Class ReadingFactory.OperatorTemplate<D,T,A>

java.lang.Object
eu.bandm.tools.ramus.ogma.ReadingFactory.OperatorTemplate<D,T,A>
Type Parameters:
D - the type of document identifiers
T - the type of token types
A - the type of parsing results
Enclosing class:
ReadingFactory

public static class ReadingFactory.OperatorTemplate<D,T,A> extends Object
Configurable template for binary operator syntax. A template may specify the following details:
  • A syntax for the left and right operand, which may be the same or distinct.
  • A factory for AST nodes that represent operator applications.
  • One or more token types that function as operators in the input.
  • An optional flag indicating whether operators of different token types may be mixed without parentheses (default: true).
  • Zero or more parser pragmas (default: none).
  • Constructor Details

    • OperatorTemplate

      @SafeVarargs public OperatorTemplate(Reading<D,T,A> operand, ReadingFactory.OperatorFactory<D,T,A> operatorFactory, T... operatorTypes)
      Creates a new template with the same syntax for both operands.

      The order of given operator token types is irrelevant. Duplicates are ignored. Note that the template is unusable (results in syntax that cannot be matched) if no operator token types are given.

      Parameters:
      operand - the parser that specifies the syntax for both operands
      operatorFactory - the AST node factory for operator applications
      operatorTypes - an array of acceptable token types for the operator
      Throws:
      NullPointerException - if any parameter is null
    • OperatorTemplate

      @SafeVarargs public OperatorTemplate(Reading<D,T,A> leftOperand, ReadingFactory.OperatorFactory<D,T,A> operatorFactory, Reading<D,T,A> rightOperand, T... operatorTypes)
      Creates a new template with distinct syntax for left and right operands.

      The order of given operator token types is irrelevant. Duplicates are ignored. Note that the template is unusable (results in syntax that cannot be matched) if no operator token types are given.

      Parameters:
      leftOperand - the parser that specifies the syntax for the left operand
      operatorFactory - the AST node factory for operator applications
      rightOperand - the parser that specifies the syntax for the right operand
      operatorTypes - an array of acceptable token types for the operator
      Throws:
      NullPointerException - if any parameter is null
    • OperatorTemplate

      public OperatorTemplate(Reading<D,T,A> leftOperand, ReadingFactory.OperatorFactory<D,T,A> operatorFactory, Reading<D,T,A> rightOperand, Collection<? extends T> operatorTypes)
      Creates a new template with distinct syntax for left and right operands.

      The order of given operator token types is irrelevant. Duplicates are ignored. Note that the template is unusable (results in syntax that cannot be matched) if no operator token types are given.

      Parameters:
      leftOperand - the parser that specifies the syntax for the left operand
      operatorFactory - the AST node factory for operator applications
      rightOperand - the parser that specifies the syntax for the right operand
      operatorTypes - a collection of acceptable token types for the operator
      Throws:
      NullPointerException - if any parameter is null
  • Method Details

    • setMixable

      public ReadingFactory.OperatorTemplate<D,T,A> setMixable(boolean mixable)
      Sets the flag indicating whether operators of distinct token types are mixable.
      Parameters:
      mixable - the flag indicating whether operators of distinct token types are mixable
      Returns:
      this
    • setPragmas

      public ReadingFactory.OperatorTemplate<D,T,A> setPragmas(Parser.Pragma... pragmas)
      Sets the parser pragmas.
      Parameters:
      pragmas - the parser pragmas
      Returns:
      this
    • getLeftOperand

      public Reading<D,T,A> getLeftOperand()
      Returns the parser that specifies the syntax of the left operand.
      Returns:
      the parser that specifies the syntax of the left operand
    • getRightOperand

      public Reading<D,T,A> getRightOperand()
      Returns the parser that specifies the syntax of the right operand.
      Returns:
      the parser that specifies the syntax of the right operand
    • getOperatorFactory

      public ReadingFactory.OperatorFactory<D,T,A> getOperatorFactory()
      Returns the AST node factory for operator applications.
      Returns:
      the AST node factory for operator applications
    • getOperatorTypes

      public Set<T> getOperatorTypes()
      Returns the set of operator token types.
      Returns:
      the set of operator token types
    • isMixable

      public boolean isMixable()
      Returns the flag indicating whether operators of distinct token types are mixable.
      Returns:
      the flag indicating whether operators of distinct token types are mixable
    • getPragmas

      public Parser.Pragma[] getPragmas()
      Returns the parser pragmas.
      Returns:
      the parser pragmas
    • withRestrictedOperatorTypes

      public ReadingFactory.OperatorTemplate<D,T,A> withRestrictedOperatorTypes(Collection<? extends T> operatorTypes)
      Returns a variant of this template with fewer operator token types.

      This method checks whether the given operator token types are indeed a restriction.

      Parameters:
      operatorTypes - the new collection of acceptable operator token types
      Returns:
      a variant of this template with only the given operator token types
      Throws:
      NullPointerException - if operatorTypes is null
      IllegalArgumentException - if this template does not specify all of operatorTypes
    • withRightOperand

      public ReadingFactory.OperatorTemplate<D,T,A> withRightOperand(Reading<D,T,A> rightOperand)
      Returns a variant of this template with a different syntax for the right operand.
      Parameters:
      rightOperand - the new parser that
      Returns:
      a variant of this template with rightOperand
      Throws:
      NullPointerException - if rightOperand is null