nuric 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +3 -0
  3. data/Rakefile +87 -0
  4. data/bin/nuric +5 -0
  5. data/lib/nuric.rb +99 -0
  6. data/nuric.gemspec +23 -0
  7. metadata +77 -0
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,87 @@
1
+ def name
2
+ @name ||= "nuric"
3
+ end
4
+
5
+ def version
6
+ @version ||= File.read('../VERSION').strip
7
+ end
8
+
9
+ def home
10
+ @home ||= File.dirname(__FILE__)
11
+ end
12
+
13
+ def share_dir
14
+ "#{home}/share"
15
+ end
16
+
17
+ def test_dir
18
+ "#{home}/../test"
19
+ end
20
+
21
+ def bin_dir
22
+ "#{home}/bin"
23
+ end
24
+
25
+ def lib_dir
26
+ "#{home}/lib/nuric"
27
+ end
28
+
29
+ def ocaml_dir
30
+ "#{home}/../ocaml"
31
+ end
32
+
33
+ def platform
34
+ @platform ||= case RUBY_PLATFORM
35
+ when /.*linux.*/
36
+ 'linux'
37
+ when /.*darwin.*/
38
+ 'osx'
39
+ when /.*(cygwin|mswin|mingw|bccwin|wince|emx).*/
40
+ 'win'
41
+ else
42
+ ''
43
+ end
44
+ end
45
+
46
+ def testfiles
47
+ File.read("#{home}/../test/good-test-files.txt").
48
+ split("\n")
49
+ end
50
+
51
+ def gem_file
52
+ @gem_file ||= "#{name}-#{version}.gem"
53
+ end
54
+
55
+ def nuric
56
+ if platform
57
+ "#{share_dir}/#{platform}/#{name}"
58
+ else
59
+ "#{share_dir}/#{name}"
60
+ end
61
+ end
62
+
63
+ task :default => :build
64
+
65
+ task :build do
66
+ # build
67
+ Dir.chdir ocaml_dir
68
+ sh 'make NATIVE=1 STACK_TRACE=0'
69
+ FileUtils.mkdir "#{share_dir}/#{platform}" unless
70
+ Dir.exist?("#{share_dir}/#{platform}")
71
+ FileUtils.cp name, nuric
72
+
73
+ # test
74
+ Dir.chdir test_dir
75
+ testfiles.each do |file|
76
+ sh "#{nuric} #{file} 1>/dev/null"
77
+ end
78
+ Dir.chdir "#{home}/test"
79
+
80
+ Dir.chdir home
81
+ sh "gem build #{name}.gemspec"
82
+ end
83
+
84
+ task :clean do
85
+ FileUtils.rm nuric if File.exists?(nuric)
86
+ FileUtils.rm gem_file if File.exists?(gem_file)
87
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "#{File.dirname(__FILE__)}/../lib/nuric.rb"
4
+
5
+ system "#{Nuri::Compiler.new.nuric} #{ARGV.join(' ')}"
@@ -0,0 +1,99 @@
1
+ require 'json'
2
+ require 'fileutils'
3
+
4
+ module Nuri
5
+ # Ruby wrapper for Nuri language compiler.
6
+ class Compiler
7
+ def nuric
8
+ @nuric ||= "#{home}/share/#{platform}/nuric"
9
+ end
10
+
11
+ # :file => file that contains the specification
12
+ # :string => string of specification
13
+ def compile(opts)
14
+ lib = (opts[:lib] ? opts[:lib] : '.')
15
+ if opts[:file]
16
+ compile_file opts[:file], lib
17
+ elsif opts[:string]
18
+ compile_string opts[:string], lib
19
+ end
20
+ rescue
21
+ raise 'Invalid input.'
22
+ end
23
+
24
+ # :type => :file | :string
25
+ # :init => initial state specification (filename or string)
26
+ # :goal => goal state specification (filename or string)
27
+ def plan(opts)
28
+ lib = (opts[:lib] ? opts[:lib] : '.')
29
+ case opts[:type]
30
+ when :file
31
+ plan_files opts[:init], opts[:goal], lib
32
+ when :string
33
+ plan_strings opts[:init], opts[:goal], lib
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def compile_file(file, lib)
40
+ IO.popen("export NURI_LIB=\"#{lib}\" && #{nuric} #{file}",
41
+ external_encoding: 'UTF-8') do |io|
42
+ return JSON[io.gets]
43
+ end
44
+ end
45
+
46
+ def compile_string(str, lib)
47
+ IO.popen("export NURI_LIB=\"#{lib}\" && #{nuric} -i",
48
+ 'r+',
49
+ external_encoding: 'UTF-8') do |io|
50
+ io.puts str
51
+ io.close_write
52
+ return JSON[io.gets]
53
+ end
54
+ end
55
+
56
+ def plan_files(init, goal, lib)
57
+ IO.popen("export NURI_LIB=\"#{lib}\" && #{nuric} -p #{init} #{goal} 2>/dev/null",
58
+ external_encoding: 'UTF-8') do |io|
59
+ return JSON[io.gets]
60
+ end
61
+ rescue
62
+ nil
63
+ end
64
+
65
+ def temp_init
66
+ @temp_init ||= '.init.nuri'
67
+ end
68
+
69
+ def temp_goal
70
+ @temp_goal ||= '.goal.nuri'
71
+ end
72
+
73
+ def plan_strings(init, goal, lib)
74
+ File.open(temp_init, 'w') { |f| f.write(init) }
75
+ File.open(temp_goal, 'w') { |f| f.write(goal) }
76
+ plan_files temp_init, temp_goal, lib
77
+ ensure
78
+ FileUtils.rm_f temp_init
79
+ FileUtils.rm_f temp_goal
80
+ end
81
+
82
+ def home
83
+ @home ||= "#{File.dirname(__FILE__)}/.."
84
+ end
85
+
86
+ def platform
87
+ @platform ||= case RUBY_PLATFORM
88
+ when /.*linux.*/
89
+ 'linux'
90
+ when /.*darwin.*/
91
+ 'osx'
92
+ when /.*(cygwin|mswin|mingw|bccwin|wince|emx).*/
93
+ 'win'
94
+ else
95
+ ''
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'nuric'
3
+ s.version = File.read("#{File.dirname(__FILE__)}/../VERSION").strip
4
+ s.date = File.atime("#{File.dirname(__FILE__)}/../VERSION").strftime('%Y-%m-%d').to_s
5
+ s.summary = 'Nuri Language Compiler'
6
+ s.description = 'A Ruby wrapper of Nuri language compiler'
7
+ s.authors = ['Herry']
8
+ s.email = 'herry13@gmail.com'
9
+
10
+ s.executables << 'nuric'
11
+
12
+ s.files = `git ls-files`.split("\n").select { |f| !(f =~ /^test/) }
13
+
14
+ Dir['share/*/*'].each { |f| s.files << f }
15
+ s.files << 'share/nuric' if File.exist?('share/nuric')
16
+
17
+ s.require_paths = ['lib']
18
+ s.license = 'Apache-2.0'
19
+
20
+ s.homepage = 'https://github.com/nurilabs/nuri-lang'
21
+
22
+ s.add_development_dependency 'rake'
23
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nuric
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Herry
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A Ruby wrapper of Nuri language compiler
31
+ email: herry13@gmail.com
32
+ executables:
33
+ - nuric
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - Rakefile
40
+ - bin/nuric
41
+ - lib/nuric.rb
42
+ - nuric.gemspec
43
+ - share/.gitignore
44
+ - share/linux/search
45
+ - share/linux/planner
46
+ - share/linux/preprocess
47
+ - share/linux/nuric
48
+ - share/osx/search
49
+ - share/osx/planner
50
+ - share/osx/preprocess
51
+ - share/osx/nuric
52
+ homepage: https://github.com/nurilabs/nuri-lang
53
+ licenses:
54
+ - Apache-2.0
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.23
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Nuri Language Compiler
77
+ test_files: []