Class: Rattler::Parsers::Token

Inherits:
Parser show all
Includes:
Atomic
Defined in:
lib/rattler/parsers/token.rb

Overview

Token decorates a parser to return the entire matched string

Instance Method Summary collapse

Methods included from Atomic

#with_ws

Methods inherited from Parser

#&, #>>, #capturing?, #capturing_decidable?, #labeled?, #list, #one_or_more, #optional, parsed, #repeat, #semantic?, #sequence?, #skip, #variable_capture_count?, #with_ws, #zero_or_more, #|

Methods included from Runtime::ParserHelper

#select_captures

Methods inherited from Util::Node

#==, [], #[], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #initialize, #inspect, #method_missing, #name, #pretty_print, #pretty_print_cycle, #respond_to?, #same_contents?, #to_graphviz, #with_attrs, #with_attrs!, #with_children

Constructor Details

This class inherits a constructor from Rattler::Util::Node

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rattler::Util::Node

Instance Method Details

#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object

If the decorated parser matches return the entire matched string, otherwise return a false value.

Parameters:

  • scanner (StringScanner)

    the scanner for the current parse

  • rules (RuleSet)

    the grammar rules being used for the current parse

  • scope (ParserScope) (defaults to: ParserScope.empty)

    the scope of captured results

Returns:

  • the matched string, or nil



15
16
17
18
# File 'lib/rattler/parsers/token.rb', line 15

def parse(scanner, rules, scope = ParserScope.empty)
  p = scanner.pos
  child.parse(scanner, rules, scope) && scanner.string[p...(scanner.pos)]
end