Class: TRuby::ParserCombinator::TokenParser
- Inherits:
-
Object
- Object
- TRuby::ParserCombinator::TokenParser
- Defined in:
- lib/t_ruby/parser_combinator/token/token_parser.rb
Overview
Base class for token parsers
Direct Known Subclasses
TokenAlternative, TokenLabel, TokenMany, TokenMany1, TokenMap, TokenMatcher, TokenOptional, TokenSepBy, TokenSepBy1, TokenSequence, TokenSkipRight
Instance Method Summary collapse
-
#<<(other) ⇒ Object
Skip right: parse both, keep left result.
-
#>>(other) ⇒ Object
Sequence: run this parser, then the other.
-
#label(name) ⇒ Object
Label: add a descriptive label for error messages.
-
#many ⇒ Object
Many: zero or more repetitions.
-
#many1 ⇒ Object
Many1: one or more repetitions.
-
#map(&block) ⇒ Object
Map: transform the result.
-
#optional ⇒ Object
Optional: zero or one.
- #parse(tokens, position = 0) ⇒ Object
-
#sep_by(delimiter) ⇒ Object
Separated by: parse items separated by delimiter.
-
#sep_by1(delimiter) ⇒ Object
Separated by 1: at least one item.
-
#|(other) ⇒ Object
Alternative: try this parser, if it fails try the other.
Instance Method Details
#<<(other) ⇒ Object
Skip right: parse both, keep left result
52 53 54 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 52 def <<(other) TokenSkipRight.new(self, other) end |
#>>(other) ⇒ Object
Sequence: run this parser, then the other
12 13 14 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 12 def >>(other) TokenSequence.new(self, other) end |
#label(name) ⇒ Object
Label: add a descriptive label for error messages
57 58 59 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 57 def label(name) TokenLabel.new(self, name) end |
#many ⇒ Object
Many: zero or more repetitions
27 28 29 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 27 def many TokenMany.new(self) end |
#many1 ⇒ Object
Many1: one or more repetitions
32 33 34 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 32 def many1 TokenMany1.new(self) end |
#map(&block) ⇒ Object
Map: transform the result
22 23 24 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 22 def map(&block) TokenMap.new(self, block) end |
#optional ⇒ Object
Optional: zero or one
37 38 39 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 37 def optional TokenOptional.new(self) end |
#parse(tokens, position = 0) ⇒ Object
7 8 9 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 7 def parse(tokens, position = 0) raise NotImplementedError end |
#sep_by(delimiter) ⇒ Object
Separated by: parse items separated by delimiter
42 43 44 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 42 def sep_by(delimiter) TokenSepBy.new(self, delimiter) end |
#sep_by1(delimiter) ⇒ Object
Separated by 1: at least one item
47 48 49 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 47 def sep_by1(delimiter) TokenSepBy1.new(self, delimiter) end |
#|(other) ⇒ Object
Alternative: try this parser, if it fails try the other
17 18 19 |
# File 'lib/t_ruby/parser_combinator/token/token_parser.rb', line 17 def |(other) TokenAlternative.new(self, other) end |