Class: OR
Overview
Instance Attribute Summary
#opnds
Instance Method Summary
collapse
NONE, #andContext, andContext, filterPrecedencePredicates, #filterPrecedencePredicates, #orContext, orContext, #simplify
Constructor Details
#initialize(a, b) ⇒ OR
Returns a new instance of OR.
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/antlr4/atn/SemanticContext.rb', line 270
def initialize(a, b)
operands = Set.new()
if a.kind_of? OR then
a.opnds.each {|o| operands.add(o) }
else
operands.add(a)
end
if b.kind_of? OR then
b.opnds.each {|o| operands.add(o) }
else
operands.add(b)
end
precedencePredicates = filterPrecedencePredicates(operands)
if precedencePredicates.length() > 0 then
s = precedencePredicates.sort()
reduced = s[-1]
operands.add(reduced)
end
self.opnds = operands.to_a
end
|
Instance Method Details
#==(other) ⇒ Object
295
296
297
|
# File 'lib/antlr4/atn/SemanticContext.rb', line 295
def ==(other)
self.equal?(other) or other.kind_of?(OR) and self.opnds == other.opnds
end
|
#eql?(other) ⇒ Boolean
292
293
294
|
# File 'lib/antlr4/atn/SemanticContext.rb', line 292
def eql?(other)
self == other
end
|
#eval(parser, outerContext) ⇒ Object
<p> The evaluation of predicates by this context is short-circuiting, but unordered.</p>
306
307
308
309
310
311
312
313
314
|
# File 'lib/antlr4/atn/SemanticContext.rb', line 306
def eval(parser, outerContext)
self.opnds.each {|opnd|
if opnd.eval(parser, outerContext)
return true
end
}
return false
end
|
#evalPrecedence(parser, outerContext) ⇒ Object
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
# File 'lib/antlr4/atn/SemanticContext.rb', line 316
def evalPrecedence(parser, outerContext)
differs = false
operands = Array.new
operands = self.opnds.map {|context|
evaluated = context.evalPrecedence(parser, outerContext)
if evaluated.equal? context then
differs = false
else
differs = true
end
return SemanticContext.NONE if evaluate.equal? SemanticContext.NONE
if not evaluated.nil? then
evaluated
end
}.compact
return self unless differs
if operands.empty?
return nil
end
result = nil
operands.each {|o|
if result.nil?
result = o
else
result = result.orContext(o)
end
}
return result
end
|
298
299
300
|
# File 'lib/antlr4/atn/SemanticContext.rb', line 298
def hash
"#{self.opnds}/OR".hash
end
|
351
352
353
|
# File 'lib/antlr4/atn/SemanticContext.rb', line 351
def to_s
self.opnds.map(&:to_s).join("||")
end
|