Class: Antlr4::Runtime::SemanticContext::Predicate
- Inherits:
-
Antlr4::Runtime::SemanticContext
- Object
- Antlr4::Runtime::SemanticContext
- Antlr4::Runtime::SemanticContext::Predicate
- Defined in:
- lib/antlr4/runtime/semantic_context.rb
Constant Summary
Constants inherited from Antlr4::Runtime::SemanticContext
Instance Attribute Summary collapse
-
#is_ctx_dependent ⇒ Object
e.g., $i ref in pred.
-
#pred_index ⇒ Object
Returns the value of attribute pred_index.
-
#rule_index ⇒ Object
Returns the value of attribute rule_index.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #eval(parser, parser_call_stack) ⇒ Object
- #hash ⇒ Object
-
#initialize(rule_index = -1,, pred_index = -1,, is_ctx_dependent = false) ⇒ Predicate
constructor
A new instance of Predicate.
- #to_s ⇒ Object
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_dependent ⇒ Object
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_index ⇒ Object
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_index ⇒ Object
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
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 |
#hash ⇒ Object
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_s ⇒ Object
49 50 51 |
# File 'lib/antlr4/runtime/semantic_context.rb', line 49 def to_s '{' + @rule_index + ':' + @pred_index + '}?' end |