Class: Rattler::Parsers::Optional
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::Optional
- Includes:
- Combining
- Defined in:
- lib/rattler/parsers/optional.rb
Overview
Optional decorates a parser to match the same but always succeed.
Instance Method Summary collapse
-
#parse(scanner, rules, scope = {}) ⇒ Array, true
Parse using the decorated parser and always succeed.
- #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, true
Parse using the decorated parser and always succeed. If the decorated parser is capturing? return the result in an array, or an empty array if the wrapped parser fails. If the decorated parser is not capturing? always return true.
29 30 31 32 33 34 35 |
# File 'lib/rattler/parsers/optional.rb', line 29 def parse(scanner, rules, scope = {}) if result = child.parse(scanner, rules, scope) capturing? ? [result] : true else capturing? ? [] : true end end |
#variable_capture_count? ⇒ Boolean
37 38 39 |
# File 'lib/rattler/parsers/optional.rb', line 37 def variable_capture_count? true end |