Class: MVinl::Parser
- Inherits:
-
Program
- Object
- Program
- MVinl::Parser
- Defined in:
- lib/mvinl/parser.rb
Overview
Generated parser class
Instance Method Summary collapse
- #enqueue_token(token) ⇒ Object
- #feed(input) ⇒ Object
- #finalize! ⇒ Object
-
#initialize(lexer, context, debug: false) ⇒ Parser
constructor
A new instance of Parser.
- #next_token ⇒ Object
- #parse ⇒ Object
- #parsing_done? ⇒ Boolean
Constructor Details
#initialize(lexer, context, debug: false) ⇒ Parser
Returns a new instance of Parser.
13 14 15 16 17 18 19 20 |
# File 'lib/mvinl/parser.rb', line 13 def initialize(lexer, context, debug: false) @lexer = lexer @context = context @yydebug = debug @tokens = [] @done = false super() end |
Instance Method Details
#enqueue_token(token) ⇒ Object
41 42 43 |
# File 'lib/mvinl/parser.rb', line 41 def enqueue_token(token) @tokens << token end |
#feed(input) ⇒ Object
29 30 31 |
# File 'lib/mvinl/parser.rb', line 29 def feed(input) @lexer.feed input end |
#finalize! ⇒ Object
45 46 47 |
# File 'lib/mvinl/parser.rb', line 45 def finalize! @done = true end |
#next_token ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/mvinl/parser.rb', line 33 def next_token if @tokens.empty? @lexer.next_token else @tokens.shift end end |
#parse ⇒ Object
22 23 24 25 26 27 |
# File 'lib/mvinl/parser.rb', line 22 def parse do_parse rescue Racc::ParseError => e puts "Parsing error at #{@context.state[:lines]}: #{e.}" nil end |
#parsing_done? ⇒ Boolean
49 50 51 |
# File 'lib/mvinl/parser.rb', line 49 def parsing_done? @done && @tokens.empty? end |