Class: Rattler::Parsers::Match
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::Match
- Includes:
- Atomic
- Defined in:
- lib/rattler/parsers/match.rb
Overview
Match
parses by matching with a Regexp
. If the Regexp
matches at the parse position the entire matched string is returned, otherwise the parse fails.
Class Method Summary collapse
-
.[](re) ⇒ Match
Create a new parser that matches with
re
. - .parsed(results, *_) ⇒ Object
Instance Method Summary collapse
-
#parse(scanner, rules, scope = {}) ⇒ Object
If the
Regexp
matches at the parse position, return the matched string, otherwise return a false value.
Methods included from Atomic
Methods inherited from Parser
#&, #capturing?, #labeled?, #one_or_more, #optional, #skip, #variable_capture_count?, #with_ws, #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
Class Method Details
.[](re) ⇒ Match
Create a new parser that matches with re
.
27 28 29 |
# File 'lib/rattler/parsers/match.rb', line 27 def self.[](re) self.new(:re => re) end |
.parsed(results, *_) ⇒ Object
32 33 34 |
# File 'lib/rattler/parsers/match.rb', line 32 def self.parsed(results, *_) #:nodoc: self[eval(results.first)] end |
Instance Method Details
#parse(scanner, rules, scope = {}) ⇒ Object
If the Regexp
matches at the parse position, return the matched string, otherwise return a false value.
42 43 44 |
# File 'lib/rattler/parsers/match.rb', line 42 def parse(scanner, rules, scope={}) scanner.scan re end |