Package eu.bandm.tools.ramus.ogma
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 identifiersT- the type of token typesA- the type of parsing results
- Enclosing class:
ReadingFactory
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 Summary
ConstructorsConstructorDescriptionOperatorTemplate(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.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.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. -
Method Summary
Modifier and TypeMethodDescriptionReturns the parser that specifies the syntax of the left operand.Returns the AST node factory for operator applications.Returns the set of operator token types.Returns the parser pragmas.Returns the parser that specifies the syntax of the right operand.booleanReturns the flag indicating whether operators of distinct token types are mixable.setMixable(boolean mixable) Sets the flag indicating whether operators of distinct token types are mixable.setPragmas(Parser.Pragma... pragmas) Sets the parser pragmas.withRestrictedOperatorTypes(Collection<? extends T> operatorTypes) Returns a variant of this template with fewer operator token types.withRightOperand(Reading<D, T, A> rightOperand) Returns a variant of this template with a different syntax for the right operand.
-
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 operandsoperatorFactory- the AST node factory for operator applicationsoperatorTypes- 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 operandoperatorFactory- the AST node factory for operator applicationsrightOperand- the parser that specifies the syntax for the right operandoperatorTypes- 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 operandoperatorFactory- the AST node factory for operator applicationsrightOperand- the parser that specifies the syntax for the right operandoperatorTypes- a collection of acceptable token types for the operator- Throws:
NullPointerException- if any parameter is null
-
-
Method Details
-
setMixable
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
Sets the parser pragmas.- Parameters:
pragmas- the parser pragmas- Returns:
this
-
getLeftOperand
Returns the parser that specifies the syntax of the left operand.- Returns:
- the parser that specifies the syntax of the left operand
-
getRightOperand
Returns the parser that specifies the syntax of the right operand.- Returns:
- the parser that specifies the syntax of the right operand
-
getOperatorFactory
Returns the AST node factory for operator applications.- Returns:
- the AST node factory for operator applications
-
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
Returns the parser pragmas.- Returns:
- the parser pragmas
-
withRestrictedOperatorTypes
public ReadingFactory.OperatorTemplate<D,T, withRestrictedOperatorTypesA> (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- ifoperatorTypesis nullIllegalArgumentException- if this template does not specify all ofoperatorTypes
-
withRightOperand
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- ifrightOperandis null
-