Class: Rattler::Parsers::Parser
- Inherits:
-
Util::Node
- Object
- Util::Node
- Rattler::Parsers::Parser
- Includes:
- Runtime::ParserHelper
- Defined in:
- lib/rattler/parsers/parser.rb
Overview
Parser
is the base class for all of Rattler’s combinator parser types.
Direct Known Subclasses
Compiler::ParserGenerator::GroupMatch, Apply, AttributedSequence, BackReference, Choice, ESymbol, Eof, Fail, Label, ListParser, Match, NodeAction, Predicate, Repeat, SemanticAction, Sequence, Skip, Super, Token
Class Method Summary collapse
Instance Method Summary collapse
-
#&(other) ⇒ Sequence
A new parser that tries both this parser and
other
and fails unless both parse in sequence. -
#>>(semantic) ⇒ AttributedSequence
A new parser that tries this parser and returns the result of the semantic action if it succeeds.
-
#capturing? ⇒ Boolean
true
if the parser returns parse results on success, orfalse
if the parser simply returnstrue
on success. -
#capturing_decidable? ⇒ Boolean
true
if it can be determined statically whether the parser returns parse results on success. -
#labeled? ⇒ Boolean
true
if the parser associates a label with parse results. -
#list(sep_parser, lower_bound, upper_bound) ⇒ Repeat
A new parser that matches lists with this parser.
-
#one_or_more ⇒ Repeat
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 ⇒ Repeat
A new parser that tries this parser but returns
true
if it fails. -
#repeat(lower_bound, upper_bound) ⇒ Repeat
A new parser that tries this parser repeatedly.
-
#semantic? ⇒ Boolean
true
if the parser is a semantic action. -
#sequence? ⇒ Boolean
true
if the parser is a sequence. -
#skip ⇒ Skip
A new parser that skips over what this parser matches.
-
#variable_capture_count? ⇒ Boolean
true
if the number of parse results returned by the parser varies based on the input. -
#with_ws(ws) ⇒ Parser
A new parser that uses
ws
to skip whitespace. -
#zero_or_more ⇒ Repeat
A new parser that tries this parser until it fails and returns all of the results.
-
#|(other) ⇒ Choice
A new parser that tries this parser first and if it fails tries
other
.
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(*args) ⇒ Object
11 12 13 |
# File 'lib/rattler/parsers/parser.rb', line 11 def self.parsed(*args) #:nodoc: self[*args] end |
Instance Method Details
#&(other) ⇒ Sequence
Returns a new parser that tries both this parser and other
and fails unless both parse in sequence.
62 63 64 |
# File 'lib/rattler/parsers/parser.rb', line 62 def &(other) Sequence[self, other] end |
#>>(semantic) ⇒ AttributedSequence
A new parser that tries this parser and returns the result of the semantic action if it succeeds
69 70 71 |
# File 'lib/rattler/parsers/parser.rb', line 69 def >>(semantic) AttributedSequence[self, semantic] end |
#capturing? ⇒ Boolean
Returns true
if the parser returns parse results on success, or false
if the parser simply returns true
on success.
17 18 19 |
# File 'lib/rattler/parsers/parser.rb', line 17 def capturing? true end |
#capturing_decidable? ⇒ Boolean
true
if it can be determined statically whether the parser returns parse results on success
29 30 31 |
# File 'lib/rattler/parsers/parser.rb', line 29 def capturing_decidable? true end |
#labeled? ⇒ Boolean
true
if the parser associates a label with parse results. Only instances of Label
should return true
.
38 39 40 |
# File 'lib/rattler/parsers/parser.rb', line 38 def labeled? false end |
#list(sep_parser, lower_bound, upper_bound) ⇒ Repeat
Returns a new parser that matches lists with this parser.
103 104 105 |
# File 'lib/rattler/parsers/parser.rb', line 103 def list(sep_parser, lower_bound, upper_bound) ListParser[self, sep_parser, lower_bound, upper_bound] end |
#one_or_more ⇒ Repeat
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.
95 96 97 |
# File 'lib/rattler/parsers/parser.rb', line 95 def one_or_more repeat(1, nil) end |
#optional ⇒ Repeat
Returns a new parser that tries this parser but returns true
if it fails.
82 83 84 |
# File 'lib/rattler/parsers/parser.rb', line 82 def optional repeat(0, 1) end |
#repeat(lower_bound, upper_bound) ⇒ Repeat
Returns a new parser that tries this parser repeatedly.
76 77 78 |
# File 'lib/rattler/parsers/parser.rb', line 76 def repeat(lower_bound, upper_bound) Repeat[self, lower_bound, upper_bound] end |
#semantic? ⇒ Boolean
Returns true
if the parser is a semantic action.
48 49 50 |
# File 'lib/rattler/parsers/parser.rb', line 48 def semantic? false end |
#sequence? ⇒ Boolean
Returns true
if the parser is a sequence.
43 44 45 |
# File 'lib/rattler/parsers/parser.rb', line 43 def sequence? false end |
#skip ⇒ Skip
Returns a new parser that skips over what this parser matches.
108 109 110 |
# File 'lib/rattler/parsers/parser.rb', line 108 def skip Skip[self] end |
#variable_capture_count? ⇒ Boolean
Returns true
if the number of parse results returned by the parser varies based on the input.
23 24 25 |
# File 'lib/rattler/parsers/parser.rb', line 23 def variable_capture_count? false end |
#with_ws(ws) ⇒ Parser
Returns a new parser that uses ws
to skip whitespace.
114 115 116 |
# File 'lib/rattler/parsers/parser.rb', line 114 def with_ws(ws) self end |
#zero_or_more ⇒ Repeat
Returns a new parser that tries this parser until it fails and returns all of the results.
88 89 90 |
# File 'lib/rattler/parsers/parser.rb', line 88 def zero_or_more repeat(0, nil) end |