Class: Rattler::Parsers::OneOrMore
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::OneOrMore
- Includes:
- Combining
- Defined in:
- lib/rattler/parsers/one_or_more.rb
Overview
OneOrMore decorates a parser to match repeatedly and succeed if the decorated parser succeeds at least once.
Instance Method Summary collapse
-
#parse(scanner, rules, scope = {}) ⇒ Array, Boolean
Parse using the decorated parser as many times as it succeeds.
- #variable_capture_count? ⇒ Boolean
Methods included from Combining
Methods inherited from Parser
#&, #capturing?, #labeled?, #one_or_more, #optional, parsed, #skip, #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
Instance Method Details
#parse(scanner, rules, scope = {}) ⇒ Array, Boolean
Parse using the decorated parser as many times as it succeeds. If it does not succeeds at least once return false, otherwise the results in an array, or true if the decorated parser is not capturing?.
34 35 36 37 38 39 40 |
# File 'lib/rattler/parsers/one_or_more.rb', line 34 def parse(scanner, rules, scope = {}) a = [] while result = child.parse(scanner, rules, scope) a << result end (capturing? ? a : true) unless a.empty? end |
#variable_capture_count? ⇒ Boolean
42 43 44 |
# File 'lib/rattler/parsers/one_or_more.rb', line 42 def variable_capture_count? true end |