Method: EBNF::PEG::Parser::ClassMethods#production

Defined in:
lib/ebnf/peg/parser.rb

#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

Parameters:

  • term (Symbol)

    Term which is a key in the branch table

  • clear_packrat (Boolean) (defaults to: false)

    (false) Clears the packrat state on completion to reduce memory requirements of parser. Use only on a top-level rule when it is determined that no further backtracking is necessary.

Yields:

  • (result, data, block)

Yield Parameters:

  • result (Object)

    The result from sucessfully parsing the production.

  • data (Hash)

    A Hash defined for the current production, during :start may be initialized with data to pass to further productions, during :finish, it contains data placed by earlier productions

  • block (Proc)

    Block passed to initialization for yielding to calling parser. Should conform to the yield specs for #initialize

  • **options (Hash)

    Other data that may be passed to the production

Yield Returns:

  • (Object)

    the result of this production.



144
145
146
# File 'lib/ebnf/peg/parser.rb', line 144

def production(term, clear_packrat: false, &block)
  production_handlers[term] = [block, clear_packrat]
end