Exception: ANTLR3::Error::NoViableAlternative

Inherits:
RecognitionError show all
Defined in:
lib/antlr3/error.rb

Overview

error

NoViableAlternative

used by

all recognizers

occurs when

A recognizer must choose between multiple possible recognition paths based upon the current and future input symbols, but it has determined that the input does not suit any of the possible recognition alternatives.

In ANTLR terminology, a rule is composed of one or more alternatives, specifications seperated by | characters. An alternative is composed of a series of elements, including subrules – rule specifications enclosed within parentheses. When recognition code enters a rule method (or a subrule block) that has multiple alternatives, the recognizer must decide which one of the multiple possible paths to follow by checking a number of future input symbols. Thus, NoViableAlternative errors indicate that the current input does not fit any of the possible paths.

In lexers, this error is often raised by the main tokens! rule, which must choose between all possible token rules. If raised by tokens, it means the current input does not appear to be part of any token specification.

Constant Summary

Constants included from Constants

Constants::BUILT_IN_TOKEN_NAMES, Constants::DEFAULT, Constants::DOWN, Constants::EOF, Constants::EOF_TOKEN, Constants::EOR_TOKEN_TYPE, Constants::HIDDEN, Constants::INVALID, Constants::INVALID_TOKEN, Constants::MEMO_RULE_FAILED, Constants::MEMO_RULE_UNKNOWN, Constants::MIN_TOKEN_TYPE, Constants::SKIP_TOKEN, Constants::UP

Instance Attribute Summary collapse

Attributes inherited from RecognitionError

#column, #index, #input, #line, #source_name, #symbol, #token

Instance Method Summary collapse

Methods inherited from RecognitionError

#approximate_line_info?, #location, #unexpected_type

Constructor Details

#initialize(grammar_decision_description, decision_number, state_number, input) ⇒ NoViableAlternative

Returns a new instance of NoViableAlternative.


404
405
406
407
408
409
# File 'lib/antlr3/error.rb', line 404

def initialize( grammar_decision_description, decision_number, state_number, input )
  @grammar_decision_description = grammar_decision_description
  @decision_number = decision_number
  @state_number = state_number
  super( input )
end

Instance Attribute Details

#decision_numberObject

Returns the value of attribute decision_number


403
404
405
# File 'lib/antlr3/error.rb', line 403

def decision_number
  @decision_number
end

#grammar_decision_descriptionObject

Returns the value of attribute grammar_decision_description


403
404
405
# File 'lib/antlr3/error.rb', line 403

def grammar_decision_description
  @grammar_decision_description
end

#state_numberObject

Returns the value of attribute state_number


403
404
405
# File 'lib/antlr3/error.rb', line 403

def state_number
  @state_number
end

Instance Method Details

#messageObject


411
412
413
414
# File 'lib/antlr3/error.rb', line 411

def message
  '%s: %p != [%p]' %
    [ self.class, unexpected_type, @grammar_decision_description ]
end