Class: Ascode::Parser::Main
- Inherits:
-
Object
- Object
- Ascode::Parser::Main
- Defined in:
- lib/ascode/parser/main.rb
Instance Method Summary collapse
- #block(index) ⇒ Object
- #character(char, index) ⇒ Object
- #function(char) ⇒ Object
-
#initialize(code, impl_o = true) ⇒ Main
constructor
A new instance of Main.
- #literal(index) ⇒ Object
- #parse ⇒ Object
Constructor Details
Instance Method Details
#block(index) ⇒ Object
50 51 52 53 54 |
# File 'lib/ascode/parser/main.rb', line 50 def block(index) block = ConditionBlock.new @code, index @ast.push block.parse @skip_chars = block.block.length end |
#character(char, index) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/ascode/parser/main.rb', line 34 def character(char, index) if char == "\"" || char =~ /[0-9.]/ literal index elsif char == "[" block index else function char end end |
#function(char) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/ascode/parser/main.rb', line 56 def function(char) function = @function.parse char return unless function @implicit_output = false if function[:action] == "output" @ast.push function end |
#literal(index) ⇒ Object
44 45 46 47 48 |
# File 'lib/ascode/parser/main.rb', line 44 def literal(index) literal = Literal.new @code, index @ast.push literal.parse @skip_chars = literal.length end |
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ascode/parser/main.rb', line 15 def parse @ast = [] @skip_chars = 0 @implicit_output = @do_implicit_output @code.split("").to_enum.each_with_index do |char, index| if @skip_chars > 0 @skip_chars -= 1 next end character char, index end @ast.push(type: :io, action: "output") if @implicit_output @ast end |