Module: EBNF::LL1::Parser::ClassMethods
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/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)
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 163 def method_missing(method, *args, &block) if @delegate ||= nil # special handling when last arg is **options params = @delegate.method(method).parameters if params.any? {|t, _| t == :keyrest} && args.last.is_a?(Hash) opts = args.pop @delegate.send(method, *args, **opts, &block) else @delegate.send(method, *args, &block) end 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.
156 157 158 159 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 156 def eval_with_binding(object) @delegate = object object.instance_eval {yield} end |
#patterns ⇒ Object
65 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 65 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
146 147 148 149 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 146 def production(term, &block) @production_handlers ||= {} @production_handlers[term] = block end |
#production_handlers ⇒ Object
63 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 63 def production_handlers; @production_handlers || {}; end |
#start_handlers ⇒ Object
62 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 62 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
121 122 123 124 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 121 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.
94 95 96 97 98 99 100 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 94 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
64 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/ll1/parser.rb', line 64 def terminal_handlers; @terminal_handlers || {}; end |