class Antlr4::Runtime::SemanticContext::AND
Attributes
opnds[RW]
Public Class Methods
new(a, b)
click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 98 def initialize(a, b) operands = Set.new if a.is_a? AND operands.add_all(a.opnds) else operands.add(a) end if b.is_a? AND operands.add_all(b.opnds) else operands.add(b) end precedence_predicates = filter_precedence_predicates(operands) unless precedence_predicates.empty? # interested in the transition with the lowest precedence reduced = precedence_predicates.min operands.add(reduced) end @opnds = operands.to_a end
Public Instance Methods
eql?(other)
click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 120 def eql?(other) return true if self == other return false unless other.is_a? AND @opnds.eql?(other.opnds) end
eval(parser, parser_call_stack)
click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 139 def eval(parser, parser_call_stack) i = 0 while i < @opnds.length opnd = @opnds[i] return false unless opnd.eval(parser, parser_call_stack) i += 1 end true end
eval_precedence(parser, parser_call_stack)
click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 149 def eval_precedence(parser, parser_call_stack) differs = false operands = [] i = 0 while i < @opnds.length context = @opnds[i] evaluated = context.eval_precedence(parser, parser_call_stack) differs |= (evaluated != context) if evaluated == null # The AND context is false if any element is false return nil elsif evaluated != NONE # Reduce the result by skipping true elements operands.add(evaluated) end i += 1 end return self unless differs if operands.empty? # all elements were true, so the AND context is true return NONE end result = operands[0] i = 1 while i < operands.length result = SemanticContext.and(result, operands.get(i)) i += 1 end result end
hash()
click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 127 def hash hash_code = RumourHash.calculate(@opnds, AND.hash) unless @_hash2.nil? if hash_code == @_hash2 puts 'Same hash_code for SemanticContext_2' else puts 'Different hash_code for SemanticContext_2' end end @_hash2 = hash_code end
to_s()
click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 184 def to_s @opnds.join('&&') end