Class SemanticContext.OR

Enclosing class:
SemanticContext

public static class SemanticContext.OR extends SemanticContext.Operator
A semantic context which is true whenever at least one of the contained contexts is true.
  • Field Details

  • Constructor Details

  • Method Details

    • getOperands

      public Collection<SemanticContext> getOperands()
      Description copied from class: SemanticContext.Operator
      Gets the operands for the semantic context operator.
      Specified by:
      getOperands in class SemanticContext.Operator
      Returns:
      a collection of SemanticContext operands for the operator.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • eval

      public boolean eval(Recognizer<?,?> parser, RuleContext parserCallStack)
      For context independent predicates, we evaluate them without a local context (i.e., null context). That way, we can evaluate them without having to create proper rule-specific context during prediction (as opposed to the parser, which creates them naturally). In a practical sense, this avoids a cast exception from RuleContext to myruleContext.

      For context dependent predicates, we must pass in a local context so that references such as $arg evaluate properly as _localctx.arg. We only capture context dependent predicates in the context in which we begin prediction, so we passed in the outer context here in case of context dependent predicate evaluation.

      The evaluation of predicates by this context is short-circuiting, but unordered.

      Specified by:
      eval in class SemanticContext
    • evalPrecedence

      public SemanticContext evalPrecedence(Recognizer<?,?> parser, RuleContext parserCallStack)
      Description copied from class: SemanticContext
      Evaluate the precedence predicates for the context and reduce the result.
      Overrides:
      evalPrecedence in class SemanticContext
      Parameters:
      parser - The parser instance.
      parserCallStack -
      Returns:
      The simplified semantic context after precedence predicates are evaluated, which will be one of the following values.
      • SemanticContext.NONE: if the predicate simplifies to true after precedence predicates are evaluated.
      • null: if the predicate simplifies to false after precedence predicates are evaluated.
      • this: if the semantic context is not changed as a result of precedence predicate evaluation.
      • A non-null SemanticContext: the new simplified semantic context after precedence predicates are evaluated.
    • toString

      public String toString()
      Overrides:
      toString in class Object