Exception: RecognitionException

Inherits:
Exception
  • Object
show all
Defined in:
lib/antlr4/error.rb

Overview

The root of the ANTLR exception hierarchy. In general, ANTLR tracks just

3 kinds of errors: prediction errors, failed predicate errors, and
mismatched input errors. In each case, the parser knows where it is
in the input, where it is in the ATN, the rule invocation stack,
and what kind of problem occurred.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, recognizer = nil, input = nil, ctx = nil) ⇒ RecognitionException

Returns a new instance of RecognitionException.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/antlr4/error.rb', line 22

def initialize(message=nil, recognizer=nil, input=nil, ctx=nil)
    super(message) 
    @recognizer = recognizer
    @input = input
    @ctx = ctx
    # The current {@link Token} when an error occurred. Since not all streams
    # support accessing symbols by index, we have to track the {@link Token}
    # instance itself.
    @offendingToken = nil
    # Get the ATN state number the parser was in at the time the error
    # occurred. For {@link NoViableAltException} and
    # {@link LexerNoViableAltException} exceptions, this is the
    # {@link DecisionState} number. For others, it is the state whose outgoing
    # edge we couldn't match.
    @offendingState = -1
    if recognizer then
        @offendingState = recognizer.state
    end
end

Instance Attribute Details

#ctxObject

Returns the value of attribute ctx.



19
20
21
# File 'lib/antlr4/error.rb', line 19

def ctx
  @ctx
end

#deadEndConfigsObject

used by subclassees



21
22
23
# File 'lib/antlr4/error.rb', line 21

def deadEndConfigs
  @deadEndConfigs
end

#inputObject

Returns the value of attribute input.



19
20
21
# File 'lib/antlr4/error.rb', line 19

def input
  @input
end

#offendingStateObject

Returns the value of attribute offendingState.



19
20
21
# File 'lib/antlr4/error.rb', line 19

def offendingState
  @offendingState
end

#offendingTokenObject

Returns the value of attribute offendingToken.



19
20
21
# File 'lib/antlr4/error.rb', line 19

def offendingToken
  @offendingToken
end

#recognizerObject

Returns the value of attribute recognizer.



19
20
21
# File 'lib/antlr4/error.rb', line 19

def recognizer
  @recognizer
end

#startTokenObject

used by subclassees



21
22
23
# File 'lib/antlr4/error.rb', line 21

def startToken
  @startToken
end

Instance Method Details

#getExpectedTokensObject

Gets the set of input symbols which could potentially follow the previously matched symbol at the time this exception was thrown.

<p>If the set of expected tokens is not known and could not be computed, this method returns null.</p>

state in the ATN, or null if the information is not available. /

Returns:

  • The set of token types that could potentially follow the current



54
55
56
57
58
59
60
61
# File 'lib/antlr4/error.rb', line 54

def getExpectedTokens()
    if self.recognizer then
        @offendingState = recognizer.state
        return self.recognizer.atn.getExpectedTokens(self.offendingState, self.ctx)
    else
        return nil
    end
end