Class: TRuby::ParserCombinator::TokenLabel

Inherits:
TokenParser
  • Object
show all
Defined in:
lib/t_ruby/parser_combinator/token/token_label.rb

Overview

Label for error messages

Instance Method Summary collapse

Methods inherited from TokenParser

#<<, #>>, #label, #many, #many1, #map, #optional, #sep_by, #sep_by1, #|

Constructor Details

#initialize(parser, name) ⇒ TokenLabel

Returns a new instance of TokenLabel.



7
8
9
10
# File 'lib/t_ruby/parser_combinator/token/token_label.rb', line 7

def initialize(parser, name)
  @parser = parser
  @name = name
end

Instance Method Details

#parse(tokens, position = 0) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/t_ruby/parser_combinator/token/token_label.rb', line 12

def parse(tokens, position = 0)
  result = @parser.parse(tokens, position)
  if result.failure?
    TokenParseResult.failure("Expected #{@name}", tokens, position)
  else
    result
  end
end