Class: TRuby::ParserCombinator::Lookahead

Inherits:
Parser
  • Object
show all
Defined in:
lib/t_ruby/parser_combinator.rb

Overview

Lookahead: check without consuming

Instance Method Summary collapse

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.



450
451
452
# File 'lib/t_ruby/parser_combinator.rb', line 450

def initialize(parser)
  @parser = parser
end

Instance Method Details

#parse(input, position = 0) ⇒ Object



454
455
456
457
458
459
460
461
# File 'lib/t_ruby/parser_combinator.rb', line 454

def parse(input, position = 0)
  result = @parser.parse(input, position)
  if result.success?
    ParseResult.success(result.value, input, position)
  else
    result
  end
end