Class: Rattler::Parsers::Token
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::Token
- Defined in:
- lib/rattler/parsers/token.rb
Overview
Token
decorates a parser to return the entire matched string
Instance Method Summary collapse
-
#parse(scanner, rules, scope = {}) ⇒ Object
If the decorated parser matches return the entire matched string, otherwise return a false value.
-
#with_ws(ws) ⇒ Parser
A new parser that uses
ws
to skip whitespace.
Methods inherited from Parser
#&, #capturing?, #labeled?, #one_or_more, #optional, parsed, #skip, #variable_capture_count?, #zero_or_more, #|
Methods inherited from Util::Node
#==, [], #[], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #initialize, #inspect, #method_missing, #name, #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 = {}) ⇒ Object
If the decorated parser matches return the entire matched string, otherwise return a false value.
24 25 26 27 |
# File 'lib/rattler/parsers/token.rb', line 24 def parse(scanner, rules, scope = {}) p = scanner.pos child.parse(scanner, rules, scope) && scanner.string[p...(scanner.pos)] end |
#with_ws(ws) ⇒ Parser
Returns a new parser that uses ws
to skip whitespace.
31 32 33 |
# File 'lib/rattler/parsers/token.rb', line 31 def with_ws(ws) ws.skip & self end |