Class: Predicate

Inherits:
SemanticContext show all
Defined in:
lib/antlr4/atn/SemanticContext.rb

Instance Attribute Summary collapse

Attributes inherited from SemanticContext

#opnds

Instance Method Summary collapse

Methods inherited from SemanticContext

NONE, andContext, #andContext, #evalPrecedence, filterPrecedencePredicates, #filterPrecedencePredicates, orContext, #orContext, #simplify

Constructor Details

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

Returns a new instance of Predicate.



97
98
99
100
101
# File 'lib/antlr4/atn/SemanticContext.rb', line 97

def initialize(rule_index=-1, pred_index=-1, is_ctx_dependent=false)
    self.ruleIndex = rule_index
    self.predIndex = pred_index
    self.isCtxDependent = is_ctx_dependent # e.g., $i ref in pred
end

Instance Attribute Details

#isCtxDependentObject

Returns the value of attribute isCtxDependent.



96
97
98
# File 'lib/antlr4/atn/SemanticContext.rb', line 96

def isCtxDependent
  @isCtxDependent
end

#predIndexObject

Returns the value of attribute predIndex.



96
97
98
# File 'lib/antlr4/atn/SemanticContext.rb', line 96

def predIndex
  @predIndex
end

#ruleIndexObject

Returns the value of attribute ruleIndex.



96
97
98
# File 'lib/antlr4/atn/SemanticContext.rb', line 96

def ruleIndex
  @ruleIndex
end

Instance Method Details

#==(other) ⇒ Object



125
126
127
128
129
130
# File 'lib/antlr4/atn/SemanticContext.rb', line 125

def ==(other)
    self.equal?(other)or other.kind_of?(Predicate) and \
          self.ruleIndex == other.ruleIndex and \
           self.predIndex == other.predIndex and \
           self.isCtxDependent == other.isCtxDependent
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/antlr4/atn/SemanticContext.rb', line 122

def eql?(other)
  self == other
end

#eval(parser, outerContext) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/antlr4/atn/SemanticContext.rb', line 103

def eval(parser, outerContext)
    #localctx = outerContext if self.isCtxDependent else None
    if self.isCtxDependent 
      localctx = outerContext 
    else 
      localctx = nil
    end
    return parser.sempred(localctx, self.ruleIndex, self.predIndex)
end

#hashObject



112
113
114
115
116
117
118
119
120
121
# File 'lib/antlr4/atn/SemanticContext.rb', line 112

def hash
    StringIO.open  do |buf|
        buf.write(self.ruleIndex.to_s)
        buf.write("/")
        buf.write(self.predIndex.to_s)
        buf.write("/")
        buf.write(self.isCtxDependent.to_s)
        return buf.string().hash 
    end
end

#to_sObject



131
132
133
# File 'lib/antlr4/atn/SemanticContext.rb', line 131

def to_s
  "{#{self.ruleIndex}:#{self.predIndex}}?"
end