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
A new match parser that matches with
re
. - .parsed(results, *_) ⇒ Object
Instance Method Summary collapse
-
#parse(scanner, rules, scope = ParserScope.empty) ⇒ 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?, #capturing_decidable?, #labeled?, #list, #one_or_more, #optional, #repeat, #semantic?, #sequence?, #skip, #variable_capture_count?, #with_ws, #zero_or_more, #|
Methods included from Runtime::ParserHelper
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
Class Method Details
.[](re) ⇒ Match
Returns a new match parser that matches with re
.
13 14 15 |
# File 'lib/rattler/parsers/match.rb', line 13 def self.[](re) self.new(:re => re) end |
.parsed(results, *_) ⇒ Object
18 19 20 |
# File 'lib/rattler/parsers/match.rb', line 18 def self.parsed(results, *_) #:nodoc: self[eval(results.first)] end |
Instance Method Details
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
If the Regexp
matches at the parse position, return the matched string, otherwise return a false value.
30 31 32 |
# File 'lib/rattler/parsers/match.rb', line 30 def parse(scanner, rules, scope = ParserScope.empty) scanner.scan re end |