Class: Antlr4::Runtime::SemanticContext::Predicate

Inherits:
Antlr4::Runtime::SemanticContext show all
Defined in:
lib/antlr4/runtime/semantic_context.rb

Constant Summary

Constants inherited from Antlr4::Runtime::SemanticContext

NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Antlr4::Runtime::SemanticContext

and, #eval_precedence, filter_precedence_predicates, or

Constructor Details

#initialize(rule_index = -1,, pred_index = -1,, is_ctx_dependent = false) ⇒ Predicate

Returns a new instance of Predicate.



15
16
17
18
19
20
# File 'lib/antlr4/runtime/semantic_context.rb', line 15

def initialize(rule_index = -1, pred_index = -1, is_ctx_dependent = false)
  @rule_index = rule_index
  @pred_index = pred_index
  @is_ctx_dependent = is_ctx_dependent
  @_hash = nil
end

Instance Attribute Details

#is_ctx_dependentObject

e.g., $i ref in pred



13
14
15
# File 'lib/antlr4/runtime/semantic_context.rb', line 13

def is_ctx_dependent
  @is_ctx_dependent
end

#pred_indexObject

Returns the value of attribute pred_index.



12
13
14
# File 'lib/antlr4/runtime/semantic_context.rb', line 12

def pred_index
  @pred_index
end

#rule_indexObject

Returns the value of attribute rule_index.



11
12
13
# File 'lib/antlr4/runtime/semantic_context.rb', line 11

def rule_index
  @rule_index
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/antlr4/runtime/semantic_context.rb', line 42

def eql?(other)
  return false unless other.is_a? Predicate
  return true if self == other

  @rule_index == other.rule_index && @pred_index == other.pred_index && @is_ctx_dependent == other.is_ctx_dependent
end

#eval(parser, parser_call_stack) ⇒ Object



22
23
24
25
# File 'lib/antlr4/runtime/semantic_context.rb', line 22

def eval(parser, parser_call_stack)
  localctx = @is_ctx_dependent ? parser_call_stack : nil
  parser.sempred(localctx, @rule_index, @pred_index)
end

#hashObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/antlr4/runtime/semantic_context.rb', line 27

def hash
  return @_hash unless @_hash.nil?

  hash_code = RumourHash.calculate([@rule_index, @pred_index, @is_ctx_dependent ? 1 : 0])

  unless @_hash.nil?
    if hash_code == @_hash
      puts 'Same hash_code for SemanticContext'
    else
      puts 'Different hash_code for SemanticContext'
    end
  end
  @_hash = hash_code
end

#to_sObject



49
50
51
# File 'lib/antlr4/runtime/semantic_context.rb', line 49

def to_s
  '{' + @rule_index + ':' + @pred_index + '}?'
end