Class: Ruby2Basic::ZXSpectrum::Transpiler
- Inherits:
-
Object
- Object
- Ruby2Basic::ZXSpectrum::Transpiler
- Defined in:
- lib/ruby2basic/zxspectrum/transpiler.rb
Instance Attribute Summary collapse
-
#oneline ⇒ Object
Returns the value of attribute oneline.
Instance Method Summary collapse
- #call(code) ⇒ Object
-
#initialize ⇒ Transpiler
constructor
A new instance of Transpiler.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Transpiler
Returns a new instance of Transpiler.
9 10 11 |
# File 'lib/ruby2basic/zxspectrum/transpiler.rb', line 9 def initialize @oneline = false end |
Instance Attribute Details
#oneline ⇒ Object
Returns the value of attribute oneline.
7 8 9 |
# File 'lib/ruby2basic/zxspectrum/transpiler.rb', line 7 def oneline @oneline end |
Instance Method Details
#call(code) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby2basic/zxspectrum/transpiler.rb', line 22 def call(code) reset @result = Prism.parse(code) @comments = @result.comments.map do |c| { line: c.location.start_line, text: c.location.slice.gsub(/^#\s*/, "") } end return "Error de sintaxis" unless @result.success? process_nodes(@result.value.statements.body) output = [] @arrays.each { |dim| output << "#{@line_num} #{dim}"; @line_num += 10 } output += @lines unless @oneline output << "#{@line_num} STOP" @line_num += 10 output += @subs end output.join("\n") end |
#reset ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ruby2basic/zxspectrum/transpiler.rb', line 13 def reset @lines = [] @line_num = 10 @subs = [] @labels = {} @arrays = [] @string_vars = [] end |