Class: TRuby::ParserCombinator::Lookahead
- Defined in:
- lib/t_ruby/parser_combinator/combinators/lookahead.rb
Overview
Lookahead: check without consuming
Instance Method Summary collapse
-
#initialize(parser) ⇒ Lookahead
constructor
A new instance of Lookahead.
- #parse(input, position = 0) ⇒ Object
Methods inherited from Parser
#<<, #>>, #between, #flat_map, #label, #lookahead, #many, #many1, #map, #not_followed_by, #optional, #sep_by, #sep_by1, #|
Constructor Details
#initialize(parser) ⇒ Lookahead
Returns a new instance of Lookahead.
7 8 9 |
# File 'lib/t_ruby/parser_combinator/combinators/lookahead.rb', line 7 def initialize(parser) @parser = parser end |
Instance Method Details
#parse(input, position = 0) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/t_ruby/parser_combinator/combinators/lookahead.rb', line 11 def parse(input, position = 0) result = @parser.parse(input, position) if result.success? ParseResult.success(result.value, input, position) else result end end |