Exception: Antlr4::Runtime::FailedPredicateException

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

Instance Attribute Summary collapse

Attributes inherited from RecognitionException

#context, #input, #offending_state, #offending_token, #recognizer

Instance Method Summary collapse

Methods inherited from RecognitionException

#expected_tokens

Constructor Details

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


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/antlr4/runtime/failed_predicate_exception.rb', line 8

def initialize(recognizer, predicate = nil, message = nil)
  super(format_message(predicate, message))
  @recognizer = recognizer
  @input = recognizer.input_stream
  @context = recognizer._ctx

  s = recognizer._interp.atn.states.get(recognizer.getState)

  trans = s.transition(0)
  if trans.is_a? PredicateTransition
    @rule_index = trans.rule_index
    @predicate_index = trans.pred_index
  else
    @rule_index = 0
    @predicate_index = 0
  end

  @predicate = predicate
  @offending_token = recognizer.current_token
end

Instance Attribute Details

#predicateObject (readonly)

Returns the value of attribute predicate


4
5
6
# File 'lib/antlr4/runtime/failed_predicate_exception.rb', line 4

def predicate
  @predicate
end

#predicate_indexObject (readonly)

Returns the value of attribute predicate_index


5
6
7
# File 'lib/antlr4/runtime/failed_predicate_exception.rb', line 5

def predicate_index
  @predicate_index
end

#rule_indexObject (readonly)

Returns the value of attribute rule_index


6
7
8
# File 'lib/antlr4/runtime/failed_predicate_exception.rb', line 6

def rule_index
  @rule_index
end

Instance Method Details

#format_message(predicate, message) ⇒ Object


29
30
31
# File 'lib/antlr4/runtime/failed_predicate_exception.rb', line 29

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