class Antlr4::Runtime::SemanticContext::OR

Attributes

opnds[RW]

Public Class Methods

new(a, b) click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 192
def initialize(a, b)
  operands = Set.new
  if a.is_a? OR
    operands.add_all(a.opnds)
  else
    operands.add(a)
  end
  if b.is_a? OR
    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 highest precedence
    reduced = precedence_predicates.max
    operands.add(reduced)
  end

  @opnds = operands.to_s
end

Public Instance Methods

eql?(other) click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 215
def eql?(other)
  return true if self == other
  return false unless other.is_a? OR

  @opnds.eql?(other.opnds)
end
eval(parser, parser_call_stack) click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 234
def eval(parser, parser_call_stack)
  i = 0
  while i < @opnds.length
    opnd = @opnds[i]
    return true if opnd.eval(parser, parser_call_stack)
    i += 1
  end
  false
end
eval_precedence(parser, parser_call_stack) click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 244
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 == NONE
      # The OR context is true if any element is true
      return NONE
    elsif evaluated != null
      # Reduce the result by skipping false elements
      operands.add(evaluated)
    end
    i += 1
  end
  return self unless differs

  if operands.empty?
    # all elements were false, so the OR context is false
    return nil
  end

  result = operands[0]
  i = 1
  while i < operands.size
    result = SemanticContext.or(result, operands.get(i))
    i += 1
  end

  result
end
hash() click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 222
def hash
  hash_code = MurmurHash.calculate(@opnds, OR.hash)
  unless @_hash3.nil?
    if hash_code == @_hash3
      puts 'Same hash_code for SemanticContext_2'
    else
      puts 'Different hash_code for SemanticContext_2'
    end
  end
  @_hash3 = hash_code
end
to_s() click to toggle source
# File lib/antlr4/runtime/semantic_context.rb, line 278
def to_s
  @opnds.join('||')
end