Skip to content

Commit 60c7ab5

Browse files
author
webdev778
committed
Merge branch 'python-compiler'
2 parents fa8fbb5 + 672fc73 commit 60c7ab5

File tree

6 files changed

+355
-5
lines changed

6 files changed

+355
-5
lines changed

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ unless ENV["SKIP_JS"]
2626
end
2727
end
2828

29+
unless ENV["SKIP_PYTHON"]
30+
group :pyexec do
31+
gem 'pycall'
32+
end
33+
end
34+
2935
group :rababa do
3036
gem 'rababa', "~> 0.1.1"
3137
end

Rakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ task :compile, [:compiler, :target] do |t, args|
1414
when "javascript"
1515
require "interscript/compiler/javascript"
1616
[Interscript::Compiler::Javascript, "js"]
17+
when "python"
18+
require "interscript/compiler/python"
19+
[Interscript::Compiler::Python, "py"]
1720
end
1821

1922
FileUtils.mkdir_p(args[:target])
@@ -34,7 +37,7 @@ task :compile, [:compiler, :target] do |t, args|
3437
File.write(args[:target] + "/" + map + "." + ext, code)
3538
end
3639

37-
File.write(args[:target] + "/index.json", maplist.to_json)
40+
File.write(args[:target] + "/index.json", maplist.to_json) if args[:compiler] == "javascript"
3841
end
3942

4043
task :generate_visualization_html do

lib/interscript.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def transliterate_each(system_code, string, maps={}, &block)
4848
load(system_code, maps).(string, each: true, &block)
4949
end
5050

51-
def transliterate_file(system_code, input_file, output_file, maps={})
51+
def transliterate_file(system_code, input_file, output_file, maps={}, compiler: Interscript::Interpreter)
5252
input = File.read(input_file)
53-
output = transliterate(system_code, input, maps)
53+
output = transliterate(system_code, input, maps, compiler: compiler)
5454

5555
File.open(output_file, 'w') do |f|
5656
f.puts(output)

lib/interscript/command.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ class Command < Thor
88
desc '<file>', 'Transliterate text'
99
option :system, aliases: '-s', required: true, desc: 'Transliteration system'
1010
option :output, aliases: '-o', required: false, desc: 'Output file'
11+
option :compiler, aliases: '-c', required: false, desc: 'Compiler (eg. Interscript::Compiler::Python)'
1112
# Was this option really well thought out? The last parameter is a cache, isn't it?
1213
#option :map, aliases: '-m', required: false, default: "{}", desc: 'Transliteration mapping json'
1314

1415
def translit(input)
16+
compiler = if options[:compiler]
17+
compiler = options[:compiler].split("::").last.downcase
18+
require "interscript/compiler/#{compiler}"
19+
Object.const_get(options[:compiler])
20+
else
21+
Interscript::Interpreter
22+
end
23+
1524
if options[:output]
16-
Interscript.transliterate_file(options[:system], input, options[:output]) #, JSON.parse(options[:map]))
25+
Interscript.transliterate_file(options[:system], input, options[:output], compiler: compiler)
1726
else
18-
puts Interscript.transliterate(options[:system], IO.read(input))
27+
puts Interscript.transliterate(options[:system], IO.read(input), compiler: compiler)
1928
end
2029
end
2130

0 commit comments

Comments
 (0)