julializer 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2eafa218bf1e418f652fb5e8191cd253c03301e
4
- data.tar.gz: 716d951cc59df3a550f105db450164f84a9d30cd
3
+ metadata.gz: 70d8479457b323508c5464e36655e5114bd27d5a
4
+ data.tar.gz: cc5e118fd88d913e8d6e8ebec309d640c5cacf71
5
5
  SHA512:
6
- metadata.gz: 8f7464bbd386b33c54d66564aafb82483c20b0c6e435e69fbbbae5685900da5de710a43690518d5d0b81a3fe56811b5e851fdf5af0aa4c8cde9bb9ce4cbfd001
7
- data.tar.gz: 99bf7cba19f82330748942697393fac2477a2937791108c6646fab4cca262996bbd63cfb78eae3b97cc073f44cf4769f6698534e9157d578e622bb64008b994e
6
+ metadata.gz: a252661e9addce63fd307b232612f104936dd8a586a9d531d557eee1ea38f8cac733b1a1a87b2a51c08032bb1edc561e39c2abf7ab8f641ef44efb7a3bf3a21d
7
+ data.tar.gz: 43ca600965fc6f7847107152aceb5852fb3e5b4a2bfbc31ee684a915bce569bec90fd58a17744e2eeff1a060bb575a43e6fda9c5575e26ba3cbad758f4ee3660
data/bin/julializer CHANGED
@@ -2,20 +2,22 @@
2
2
  require 'optparse'
3
3
  require 'julializer'
4
4
 
5
+ config = {}
5
6
  Options = OptionParser.new do |opts|
6
- opts.on("-v", "--version", "Print version") { |v| puts Julializer::VERSION; exit 0}
7
+ opts.on("-v", "--version", "Print version") { |v| puts Julializer::VERSION; exit 0}
8
+ opts.on("-n", "--nullable", "Allow nil(Nullable) conversion") { |v| config[:nullable] = true}
7
9
  end
8
10
  Options.parse!(ARGV)
9
11
 
10
12
  if ARGV.empty?
11
- printf Julializer.ruby2julia($stdin.read)
13
+ printf Julializer.ruby2julia($stdin.read, config)
12
14
  else
13
- ARGV.each do |file|
14
- if File.exist? file
15
- printf Julializer.ruby2julia(File.read(file))
16
- else
17
- puts "File was not found: #{file}"
18
- exit
19
- end
20
- end
15
+ ARGV.each do |file|
16
+ if File.exist? file
17
+ printf Julializer.ruby2julia(File.read(file), config)
18
+ else
19
+ puts "File was not found: #{file}"
20
+ exit
21
+ end
22
+ end
21
23
  end
@@ -1,3 +1,3 @@
1
1
  module Julializer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/julializer.rb CHANGED
@@ -4,8 +4,11 @@ module Julializer
4
4
  class << self
5
5
  require "julializer/version"
6
6
 
7
- def ruby2julia(source)
7
+ def ruby2julia(source, config={})
8
8
  @globals = []
9
+ {:nullable=>false}.each do |k,v|
10
+ instance_variable_set("@#{k}", config[k] || v)
11
+ end
9
12
  #File.write("./__julialize_debug.log", Ripper.sexp(source).pretty_inspect)
10
13
  transpile(Ripper.sexp(source))
11
14
  end
@@ -394,17 +397,20 @@ module Julializer
394
397
  "#{transpile(s[1])}:#{transpile(s[2])}"
395
398
 
396
399
  when :aref, :aref_field
400
+ aref_string = ->(type, list, index){
401
+ # using #get function for Nullable compatible access
402
+ type==:aref && @nullable ? "get(#{list}, #{index}, Nullable)" : list + "[#{index}]"
403
+ }
397
404
  if !s[2].flatten.include?(:dot2) && !s[2].flatten.include?(:dot3) && s[2][1][0][0]!=:string_literal then
398
- transpile(s[1]) + "[" + transpile(s[2]) + "+1]"
405
+ aref_string.call(s[0], transpile(s[1]), transpile(s[2])+"+1")
399
406
  else
400
407
  if s[2].flatten.include?(:dot2)
401
- range = "#{transpile(s[2][1][0][1])}+1:#{transpile(s[2][1][0][2])}+1"
408
+ transpile(s[1]) + "[#{transpile(s[2][1][0][1])}+1:#{transpile(s[2][1][0][2])}+1]"
402
409
  elsif s[2].flatten.include?(:dot3)
403
- range = "#{transpile(s[2][1][0][1])}+1:#{transpile(s[2][1][0][2])}"
410
+ transpile(s[1]) + "[#{transpile(s[2][1][0][1])}+1:#{transpile(s[2][1][0][2])}]"
404
411
  else
405
- range = transpile(s[2])
412
+ aref_string.call(s[0], transpile(s[1]), transpile(s[2]))
406
413
  end
407
- transpile(s[1]) + "[" + range + "]"
408
414
  end
409
415
 
410
416
  when :const_path_ref
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kei Sawada(@remore)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake