Class: Rattler::Parsers::Label
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::Label
- Includes:
- Combining
- Defined in:
- lib/rattler/parsers/label.rb
Overview
Label
decorates a parser and associates a label with the decorated parser’s parse result if successful. The label only applies if nested in a Choice
or Sequence
decorated by an Action
.
Class Method Summary collapse
-
.[](label, parser) ⇒ Object
Create a new parser that decorates
parser
and associateslabel
withparser
‘s parse result on success. - .parsed(results, *_) ⇒ Object
Instance Method Summary collapse
-
#capturing_decidable? ⇒ Object
true
if it can be determined statically whether the parser returns parse results on success. -
#labeled? ⇒ Boolean
true
. -
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Delegate to the decorated parser and associate #label with the parse result if successful.
Methods included from Combining
#capturing?, #semantic?, #with_ws
Methods inherited from Parser
#&, #>>, #capturing?, #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
.[](label, parser) ⇒ Object
Create a new parser that decorates parser
and associates label
with parser
‘s parse result on success.
18 19 20 |
# File 'lib/rattler/parsers/label.rb', line 18 def self.[](label, parser) self.new(parser, :label => label.to_sym) end |
.parsed(results, *_) ⇒ Object
12 13 14 |
# File 'lib/rattler/parsers/label.rb', line 12 def self.parsed(results, *_) #:nodoc: self[*results] end |
Instance Method Details
#capturing_decidable? ⇒ Object
true
if it can be determined statically whether the parser returns parse results on success
23 24 25 |
# File 'lib/rattler/parsers/label.rb', line 23 def capturing_decidable? child.capturing_decidable? end |
#labeled? ⇒ Boolean
Returns true
.
28 29 30 |
# File 'lib/rattler/parsers/label.rb', line 28 def labeled? true end |
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Delegate to the decorated parser and associate #label with the parse result if successful.
38 39 40 41 42 43 |
# File 'lib/rattler/parsers/label.rb', line 38 def parse(scanner, rules, scope = ParserScope.empty) if result = child.parse(scanner, rules, scope) {|_| scope = _ } yield scope.bind(label => result) if block_given? result end end |