class Rley::Parser::ExpectationNotMet
Abstract class and subclass of ErrorReason
. This specialization represents errors in which the input didn’t match one of the expected token.
Attributes
The terminal symbols expected when error was occurred
The last input token read when error was detected
Public Class Methods
Source
# File lib/rley/parser/error_reason.rb, line 53 def initialize(aRank, lastToken, expectedTerminals) super(aRank) raise StandardError, 'Internal error: nil token' if lastToken.nil? @last_token = lastToken.dup @expected_terminals = expectedTerminals.dup end
Calls superclass method
Rley::Parser::ErrorReason::new
Protected Instance Methods
Source
# File lib/rley/parser/error_reason.rb, line 70 def expectations term_names = expected_terminals.map(&:name) explain = +'Expected one ' explain << if expected_terminals.size > 1 "of: ['#{term_names.join("', '")}']" else "'#{term_names[0]}'" end explain end
Emit a text explaining the expected terminal symbols
Source
# File lib/rley/parser/error_reason.rb, line 63 def position return last_token.position if last_token.respond_to?(:position) rank + 1 end