Class: Rattler::Parsers::Parser
- Inherits:
-
Util::Node
- Object
- Util::Node
- Rattler::Parsers::Parser
- Defined in:
- lib/rattler/parsers/parser.rb
Overview
Parser
is the base class for all of Rattler’s combinator parser types.
Direct Known Subclasses
BackEnd::ParserGenerator::GroupMatch, Apply, BackReference, Choice, DirectAction, DispatchAction, ESymbol, Fail, Label, ListParser, Match, Predicate, Repeat, Sequence, Skip, Token
Class Method Summary collapse
Instance Method Summary collapse
-
#&(other) ⇒ Object
A new parser that tries both this parser and
other
and fails unless both parse in sequence. -
#capturing? ⇒ Boolean
Return
true
if the parser returns parse results on success, orfalse
if the parser simply returnstrue
on success. -
#labeled? ⇒ Boolean
Return
true
if the parser associates a label with parse results. -
#one_or_more ⇒ Object
A new parser that tries this parser until it fails and returns all of the results if it succeeded at least once and fails otherwise.
-
#optional ⇒ Object
A new parser that tries this parser but returns
true
if it fails. -
#skip ⇒ Object
A new parser that skips over what this parser matches.
- #variable_capture_count? ⇒ Boolean
-
#with_ws(ws) ⇒ Parser
A new parser that uses
ws
to skip whitespace. -
#zero_or_more ⇒ Object
A new parser that tries this parser until it fails and returns all of the results.
-
#|(other) ⇒ Object
A new parser that tries this parser first and if it fails tries
other
.
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
Class Method Details
.parsed(*args) ⇒ Object
19 20 21 |
# File 'lib/rattler/parsers/parser.rb', line 19 def self.parsed(*args) #:nodoc: self[*args] end |
Instance Method Details
#&(other) ⇒ Object
Returns a new parser that tries both this parser and other
and fails unless both parse in sequence.
54 55 56 |
# File 'lib/rattler/parsers/parser.rb', line 54 def &(other) Sequence[self, other] end |
#capturing? ⇒ Boolean
Return true
if the parser returns parse results on success, or false
if the parser simply returns true
on success.
28 29 30 |
# File 'lib/rattler/parsers/parser.rb', line 28 def capturing? true end |
#labeled? ⇒ Boolean
Return true
if the parser associates a label with parse results. Only instances of Label
should return true
.
40 41 42 |
# File 'lib/rattler/parsers/parser.rb', line 40 def labeled? false end |
#one_or_more ⇒ Object
Returns a new parser that tries this parser until it fails and returns all of the results if it succeeded at least once and fails otherwise.
72 73 74 |
# File 'lib/rattler/parsers/parser.rb', line 72 def one_or_more OneOrMore[self] end |
#optional ⇒ Object
Returns a new parser that tries this parser but returns true
if it fails.
60 61 62 |
# File 'lib/rattler/parsers/parser.rb', line 60 def optional Optional[self] end |
#skip ⇒ Object
Returns a new parser that skips over what this parser matches.
77 78 79 |
# File 'lib/rattler/parsers/parser.rb', line 77 def skip Skip[self] end |
#variable_capture_count? ⇒ Boolean
32 33 34 |
# File 'lib/rattler/parsers/parser.rb', line 32 def variable_capture_count? false end |
#with_ws(ws) ⇒ Parser
Returns a new parser that uses ws
to skip whitespace.
83 84 85 |
# File 'lib/rattler/parsers/parser.rb', line 83 def with_ws(ws) self end |
#zero_or_more ⇒ Object
Returns a new parser that tries this parser until it fails and returns all of the results.
66 67 68 |
# File 'lib/rattler/parsers/parser.rb', line 66 def zero_or_more ZeroOrMore[self] end |
#|(other) ⇒ Object
Returns a new parser that tries this parser first and if it fails tries other
.
47 48 49 |
# File 'lib/rattler/parsers/parser.rb', line 47 def |(other) Choice[self, other] end |