Method: EBNF::PEG::Parser::ClassMethods#terminal

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

#terminal(term, regexp, **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.

Options Hash (**options):

  • :unescape (Boolean)

    Cause strings and codepoints to be unescaped.

Yields:

  • (value, prod)

Yield Parameters:

  • value (String)

    The scanned terminal value.

  • prod (Symbol)

    A symbol indicating the production which referenced this terminal

  • block (Proc)

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



85
86
87
88
89
# File 'lib/ebnf/peg/parser.rb', line 85

def terminal(term, regexp, **options, &block)
  terminal_regexps[term] = regexp
  terminal_handlers[term] = block if block_given?
  terminal_options[term] = options.freeze
end