Module: EBNF::LL1::Parser::ClassMethods
- Defined in:
- lib/ebnf/ll1/parser.rb
Overview
DSL for creating terminals and productions
Instance Method Summary collapse
-
#eval_with_binding(object) ⇒ Object
Evaluate a handler, delegating to the specified object.
- #patterns ⇒ Object
-
#production(term) {|input, current, block| ... } ⇒ Object
Defines a production called when production of associated terminals and non-terminals has completed with data from previous production along with data defined for the current production.
- #production_handlers ⇒ Object
- #start_handlers ⇒ Object
-
#start_production(term) {|input, current, block| ... } ⇒ Object
Defines a production called at the beggining of a particular production with data from previous production along with data defined for the current production.
-
#terminal(term, regexp, options = {}) {|term, token, input, block| ... } ⇒ Object
Defines the pattern for a terminal node and a block to be invoked when ther terminal is encountered.
- #terminal_handlers ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
124 125 126 127 128 129 130 |
# File 'lib/ebnf/ll1/parser.rb', line 124 def method_missing(method, *args, &block) if @@delegate ||= nil @@delegate.send method, *args, &block else super end end |
Instance Method Details
#eval_with_binding(object) ⇒ Object
Evaluate a handler, delegating to the specified object. This is necessary so that handlers can operate within the binding context of the parser in which they’re invoked.
117 118 119 120 |
# File 'lib/ebnf/ll1/parser.rb', line 117 def eval_with_binding(object) @@delegate = object object.instance_eval {yield} end |
#patterns ⇒ Object
26 |
# File 'lib/ebnf/ll1/parser.rb', line 26 def patterns; @@patterns || []; end |
#production(term) {|input, current, block| ... } ⇒ Object
Defines a production called when production of associated terminals and non-terminals has completed with data from previous production along with data defined for the current production. Block is called in an evaluation block from the enclosing parser.
Yield to generate a triple
107 108 109 110 |
# File 'lib/ebnf/ll1/parser.rb', line 107 def production(term, &block) @@production_handlers ||= {} @@production_handlers[term] = block end |
#production_handlers ⇒ Object
24 |
# File 'lib/ebnf/ll1/parser.rb', line 24 def production_handlers; @@production_handlers || {}; end |
#start_handlers ⇒ Object
23 |
# File 'lib/ebnf/ll1/parser.rb', line 23 def start_handlers; @@start_handlers || {}; end |
#start_production(term) {|input, current, block| ... } ⇒ Object
Defines a production called at the beggining of a particular production with data from previous production along with data defined for the current production. Block is called in an evaluation block from the enclosing parser.
Yield to generate a triple
82 83 84 85 |
# File 'lib/ebnf/ll1/parser.rb', line 82 def start_production(term, &block) @@start_handlers ||= {} @@start_handlers[term] = block end |
#terminal(term, regexp, options = {}) {|term, token, input, block| ... } ⇒ Object
Defines the pattern for a terminal node and a block to be invoked when ther terminal is encountered. If the block is missing, the value of the terminal will be placed on the input hash to be returned to a previous production. Block is called in an evaluation block from the enclosing parser.
55 56 57 58 59 60 61 |
# File 'lib/ebnf/ll1/parser.rb', line 55 def terminal(term, regexp, = {}, &block) @@patterns ||= [] # Passed in order to define evaulation sequence @@patterns << EBNF::LL1::Lexer::Terminal.new(term, regexp, ) @@terminal_handlers ||= {} @@terminal_handlers[term] = block if block_given? end |
#terminal_handlers ⇒ Object
25 |
# File 'lib/ebnf/ll1/parser.rb', line 25 def terminal_handlers; @@terminal_handlers || {}; end |