Exception: FailedPredicateException

Inherits:
RecognitionException show all
Defined in:
lib/antlr4/error.rb

Overview

A semantic predicate failed during validation. Validation of predicates

occurs when normally parsing the alternative just like matching a token.
Disambiguating predicate evaluation occurs when we test a predicate during
prediction.

Instance Attribute Summary collapse

Attributes inherited from RecognitionException

#ctx, #deadEndConfigs, #input, #offendingState, #offendingToken, #recognizer, #startToken

Instance Method Summary collapse

Methods inherited from RecognitionException

#getExpectedTokens

Constructor Details

#initialize(recognizer, predicate = nil, message = nil) ⇒ FailedPredicateException

Returns a new instance of FailedPredicateException.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/antlr4/error.rb', line 125

def initialize(recognizer, predicate=nil, message=nil)
    super(self.formatMessage(predicate,message), recognizer,
                     recognizer.getInputStream(), recognizer.ctx)
    s = recognizer.interp.atn.states[recognizer.state]
    trans = s.transitions[0]
    if trans.kind_of? PredicateTransition then
        @ruleIndex = trans.ruleIndex
        @predicateIndex = trans.predIndex
    else
        @ruleIndex = 0
        @predicateIndex = 0
    end
    @predicate = predicate
    @offendingToken = recognizer.getCurrentToken()
end

Instance Attribute Details

#predicateObject

Returns the value of attribute predicate.



124
125
126
# File 'lib/antlr4/error.rb', line 124

def predicate
  @predicate
end

#predicateIndexObject

Returns the value of attribute predicateIndex.



124
125
126
# File 'lib/antlr4/error.rb', line 124

def predicateIndex
  @predicateIndex
end

#ruleIndexObject

Returns the value of attribute ruleIndex.



124
125
126
# File 'lib/antlr4/error.rb', line 124

def ruleIndex
  @ruleIndex
end

Instance Method Details

#formatMessage(predicate, message) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/antlr4/error.rb', line 141

def formatMessage(predicate, message)
    if message.nil?
        "failed predicate: {" + predicate + "}?"
    else
        message
    end
end