Module: EBNF::PEG::Parser::ClassMethods
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/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.
-
#production(term, clear_packrat: false) {|result, data, block| ... } ⇒ Object
Defines a production called when production of associated non-terminals has completed with data from previous production along with data defined for the current production.
- #production_handlers ⇒ Object
- #start_handlers ⇒ Object
- #start_options ⇒ Object
-
#start_production(term, **options) {|data, 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 = nil, **options) {|value, prod| ... } ⇒ Object
Defines the pattern for a terminal node and a block to be invoked when ther terminal is encountered.
- #terminal_handlers ⇒ Object
- #terminal_options ⇒ Object
- #terminal_regexps ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 161 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.
154 155 156 157 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 154 def eval_with_binding(object) @delegate = object object.instance_eval {yield} end |
#production(term, clear_packrat: false) {|result, data, block| ... } ⇒ Object
Defines a production called when production of associated 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
145 146 147 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 145 def production(term, clear_packrat: false, &block) production_handlers[term] = [block, clear_packrat] end |
#production_handlers ⇒ Object
55 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 55 def production_handlers; (@production_handlers ||= {}); end |
#start_handlers ⇒ Object
53 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 53 def start_handlers; (@start_handlers ||= {}); end |
#start_options ⇒ Object
54 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 54 def ; (@start_hoptions ||= {}); end |
#start_production(term, **options) {|data, 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
115 116 117 118 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 115 def start_production(term, **, &block) start_handlers[term] = block [term] = .freeze end |
#terminal(term, regexp = nil, **options) {|value, prod| ... } ⇒ 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.
If no block is provided, then the value which would have been passed to the block is used as the result directly.
86 87 88 89 90 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 86 def terminal(term, regexp = nil, **, &block) terminal_regexps[term] = regexp if regexp terminal_handlers[term] = block if block_given? [term] = .freeze end |
#terminal_handlers ⇒ Object
56 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 56 def terminal_handlers; (@terminal_handlers ||= {}); end |
#terminal_options ⇒ Object
58 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 58 def ; (@terminal_options ||= {}); end |
#terminal_regexps ⇒ Object
57 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ebnf-c8f40958c6c3/lib/ebnf/peg/parser.rb', line 57 def terminal_regexps; (@terminal_regexps ||= {}); end |