Class: Tuga::Transpiler
- Inherits:
-
Object
- Object
- Tuga::Transpiler
- Defined in:
- lib/tuga/transpiler.rb
Overview
Transpiles Tuga code to Ruby
Constant Summary collapse
- ENCODING =
The encoding used to allow Portuguese characters
"# encoding: utf-8\n"
- CORE_EXTENSIONS =
Aliases common methods from the standard library
"require \"tuga/core_ext\"\n"
- INITIAL_CODE =
Every transpilled program will be encoded
"#{ENCODING}#{CORE_EXTENSIONS}".freeze
Instance Method Summary collapse
-
#initialize ⇒ Transpiler
constructor
A new instance of Transpiler.
-
#to_ruby(tuga_code, require_core_ext: true) ⇒ String
Converts Tuga code to Ruby.
Constructor Details
#initialize ⇒ Transpiler
Returns a new instance of Transpiler.
19 20 21 22 |
# File 'lib/tuga/transpiler.rb', line 19 def initialize @ruby_2_ruby = Ruby2Ruby.new @ruby_parser = RubyParser.new end |
Instance Method Details
#to_ruby(tuga_code, require_core_ext: true) ⇒ String
Converts Tuga code to Ruby
31 32 33 34 35 36 |
# File 'lib/tuga/transpiler.rb', line 31 def to_ruby(tuga_code, require_core_ext: true) sexp = ruby_parser.process("# encoding: utf-8\n#{tuga_code}") ruby_code = ruby_2_ruby.process(sexp) require_core_ext ? "#{INITIAL_CODE}#{ruby_code}" : "#{ENCODING}#{ruby_code}" end |