Class: Rattler::Parsers::AttributedSequence
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::AttributedSequence
- Includes:
- Sequencing
- Defined in:
- lib/rattler/parsers/attributed_sequence.rb
Overview
AttributedSequence combines one or more parsers with a semantic action and matches the parser in sequence and applies the action to the captured results.
Class Method Summary collapse
Instance Method Summary collapse
-
#capture_count ⇒ Fixnum
The number of child parsers that are capturing.
-
#capturing? ⇒ Boolean
trueif the parser returns parse results on success, orfalseif the parser simply returnstrueon success. -
#capturing_decidable? ⇒ Boolean
trueif it can be determined statically whether the parser returns parse results on success. -
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Parse each parser in sequence, and if they all succeed return the result of applying the semantic action to the captured results.
Methods included from Sequencing
Methods included from Combining
Methods inherited from Parser
#&, #>>, #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
.parsed(results, *_) ⇒ Object
12 13 14 15 |
# File 'lib/rattler/parsers/attributed_sequence.rb', line 12 def self.parsed(results, *_) #:nodoc: op, action = results (op + [action]).reduce(:>>) end |
Instance Method Details
#capture_count ⇒ Fixnum
Returns the number of child parsers that are capturing.
45 46 47 |
# File 'lib/rattler/parsers/attributed_sequence.rb', line 45 def capture_count @capture_count ||= children[0...-1].count {|_| _.capturing? } end |
#capturing? ⇒ Boolean
Returns true if the parser returns parse results on success, or false if the parser simply returns true on success.
35 36 37 |
# File 'lib/rattler/parsers/attributed_sequence.rb', line 35 def capturing? children.last.capturing? end |
#capturing_decidable? ⇒ Boolean
true if it can be determined statically whether the parser returns parse results on success
40 41 42 |
# File 'lib/rattler/parsers/attributed_sequence.rb', line 40 def capturing_decidable? false end |
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Parse each parser in sequence, and if they all succeed return the result of applying the semantic action to the captured results.
24 25 26 27 28 29 30 31 32 |
# File 'lib/rattler/parsers/attributed_sequence.rb', line 24 def parse(scanner, rules, scope = ParserScope.empty) result = false backtracking(scanner) do if scope = parse_children(scanner, rules, scope.nest) {|r| result = r } yield scope if block_given? result end end end |