Class: TRuby::ParserCombinator::Parser
- Inherits:
-
Object
- Object
- TRuby::ParserCombinator::Parser
- Defined in:
- lib/t_ruby/parser_combinator.rb
Overview
Base parser class
Direct Known Subclasses
Alternative, ChainLeft, Choice, EndOfInput, Fail, FlatMap, Label, Lazy, Literal, Lookahead, Many, Many1, Map, NotFollowedBy, Optional, Pure, Regex, Satisfy, SepBy, SepBy1, Sequence, SkipRight
Instance Method Summary collapse
-
#<<(other) ⇒ Object
Skip right: parse both, keep left result.
-
#>>(other) ⇒ Object
Sequence: run this parser, then the other.
-
#between(left, right) ⇒ Object
Between: parse between left and right delimiters.
-
#flat_map(&block) ⇒ Object
FlatMap: transform with another parser.
-
#label(name) ⇒ Object
Label: add a descriptive label for error messages.
-
#lookahead ⇒ Object
Lookahead: check without consuming.
-
#many ⇒ Object
Many: zero or more repetitions.
-
#many1 ⇒ Object
Many1: one or more repetitions.
-
#map(&block) ⇒ Object
Map: transform the result.
-
#not_followed_by ⇒ Object
Not: succeed only if parser fails.
-
#optional ⇒ Object
Optional: zero or one.
- #parse(input, 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
103 104 105 |
# File 'lib/t_ruby/parser_combinator.rb', line 103 def <<(other) SkipRight.new(self, other) end |
#>>(other) ⇒ Object
Sequence: run this parser, then the other
53 54 55 |
# File 'lib/t_ruby/parser_combinator.rb', line 53 def >>(other) Sequence.new(self, other) end |
#between(left, right) ⇒ Object
Between: parse between left and right delimiters
98 99 100 |
# File 'lib/t_ruby/parser_combinator.rb', line 98 def between(left, right) (left >> self << right).map { |(_, val)| val } end |
#flat_map(&block) ⇒ Object
FlatMap: transform with another parser
68 69 70 |
# File 'lib/t_ruby/parser_combinator.rb', line 68 def flat_map(&block) FlatMap.new(self, block) end |
#label(name) ⇒ Object
Label: add a descriptive label for error messages
108 109 110 |
# File 'lib/t_ruby/parser_combinator.rb', line 108 def label(name) Label.new(self, name) end |
#lookahead ⇒ Object
Lookahead: check without consuming
113 114 115 |
# File 'lib/t_ruby/parser_combinator.rb', line 113 def lookahead Lookahead.new(self) end |
#many ⇒ Object
Many: zero or more repetitions
73 74 75 |
# File 'lib/t_ruby/parser_combinator.rb', line 73 def many Many.new(self) end |
#many1 ⇒ Object
Many1: one or more repetitions
78 79 80 |
# File 'lib/t_ruby/parser_combinator.rb', line 78 def many1 Many1.new(self) end |
#map(&block) ⇒ Object
Map: transform the result
63 64 65 |
# File 'lib/t_ruby/parser_combinator.rb', line 63 def map(&block) Map.new(self, block) end |
#not_followed_by ⇒ Object
Not: succeed only if parser fails
118 119 120 |
# File 'lib/t_ruby/parser_combinator.rb', line 118 def not_followed_by NotFollowedBy.new(self) end |
#optional ⇒ Object
Optional: zero or one
83 84 85 |
# File 'lib/t_ruby/parser_combinator.rb', line 83 def optional Optional.new(self) end |
#parse(input, position = 0) ⇒ Object
46 47 48 |
# File 'lib/t_ruby/parser_combinator.rb', line 46 def parse(input, position = 0) raise NotImplementedError end |
#sep_by(delimiter) ⇒ Object
Separated by: parse items separated by delimiter
88 89 90 |
# File 'lib/t_ruby/parser_combinator.rb', line 88 def sep_by(delimiter) SepBy.new(self, delimiter) end |
#sep_by1(delimiter) ⇒ Object
Separated by 1: at least one item
93 94 95 |
# File 'lib/t_ruby/parser_combinator.rb', line 93 def sep_by1(delimiter) SepBy1.new(self, delimiter) end |
#|(other) ⇒ Object
Alternative: try this parser, if it fails try the other
58 59 60 |
# File 'lib/t_ruby/parser_combinator.rb', line 58 def |(other) Alternative.new(self, other) end |