Class: AND
- Inherits:
- SemanticContext show all
- Defined in:
- lib/antlr4/atn/SemanticContext.rb
Overview
is false.
Instance Attribute Summary
Attributes inherited from SemanticContext
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#eval(parser, outerContext) ⇒ Object
@inheritDoc.
- #evalPrecedence(parser, outerContext) ⇒ Object
- #hash ⇒ Object
-
#initialize(a, b) ⇒ AND
constructor
A new instance of AND.
- #to_s ⇒ Object
Methods inherited from SemanticContext
NONE, #andContext, andContext, filterPrecedencePredicates, #filterPrecedencePredicates, #orContext, orContext, #simplify
Constructor Details
#initialize(a, b) ⇒ AND
Returns a new instance of AND.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/antlr4/atn/SemanticContext.rb', line 174 def initialize(a, b) operands = Set.new() if a.kind_of? AND then a.opnds.each {|o| operands.add(o) } else operands.add(a) end if b.kind_of? AND then b.opnds.each {|o| operands.add(o) } else operands.add(b) end precedencePredicates = filterPrecedencePredicates(operands) if precedencePredicates.length>0 then # interested in the transition with the lowest precedence reduced = precedencePredicates.min operands.add(reduced) end @opnds = operands.to_a end |
Instance Method Details
#==(other) ⇒ Object
198 199 200 201 |
# File 'lib/antlr4/atn/SemanticContext.rb', line 198 def ==(other) self.equal?(other) or \ ( other.kind_of?(AND) and self.opnds == other.opnds ) end |
#eql?(other) ⇒ Boolean
195 196 197 |
# File 'lib/antlr4/atn/SemanticContext.rb', line 195 def eql?(other) self == other end |
#eval(parser, outerContext) ⇒ Object
@inheritDoc
<p> The evaluation of predicates by this context is short-circuiting, but unordered.</p>
214 215 216 217 218 219 220 221 |
# File 'lib/antlr4/atn/SemanticContext.rb', line 214 def eval(parser, outerContext) self.opnds.each {|opnd| if not opnd.eval(parser, outerContext) return false end } return true end |
#evalPrecedence(parser, outerContext) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/antlr4/atn/SemanticContext.rb', line 223 def evalPrecedence(parser, outerContext) differs = false operands = Array.new self.opnds.each {|context| evaluated = context.evalPrecedence(parser, outerContext) if evaluated.equal? context then differs = false else differs = true end # differs = differs || (! (evaluated.equal? context)) # The AND context is false if any element is false return nil if evaluated.nil? if evaluated.equal? SemanticContext.NONE # Reduce the result by skipping true elements operands.push(evaluated) end } if not differs return self end if operands.length()==0 # all elements were true, so the AND context is true return SemanticContext.NONE end result = nil operands.each {|o| if result.nil? result = o else result = result.andContext(o) end } return result end |
#hash ⇒ Object
203 204 205 |
# File 'lib/antlr4/atn/SemanticContext.rb', line 203 def hash "#{self.opnds}/AND".hash end |
#to_s ⇒ Object
260 261 262 |
# File 'lib/antlr4/atn/SemanticContext.rb', line 260 def to_s self.opnds.map(&:to_s).join("&&") end |