Class ReadingFactory
The construction of parsers is delegated to an encapsulated object of
class ParserFactory, with which the configuration is shared.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for constructing binary AST nodes for operators.static classConfigurable template for binary operator syntax.Nested classes/interfaces inherited from class eu.bandm.tools.ramus.ogma.Factory
Factory.Configuration -
Field Summary
Fields inherited from class eu.bandm.tools.ramus.ogma.Factory
configuration, MODULE_NAME, PACKAGE_PREFIX -
Method Summary
Modifier and TypeMethodDescriptionfinal <D,T, A> Reading <D, T, A> access(Reading.Key<A> key) Returns a reading that retrieves the value assigned to a given key as the semantic interpretation.assign(Reading.Key<A> key, A value) Returns a reading that assigns the given value to the given key.final <D,T, A> Reading <D, T, A> Returns a reading that matches any of the given readings, with the respective semantic interpretation.final <D,T, A> Reading <D, T, A> Returns a reading that matches any of the given readings, with the respective semantic interpretation.final <D,T, A> Reading <D, T, A> Returns a reading with the given syntax and a constant semantic interpretation.final <D,T, A> Reading <D, T, A> constant(T type, A value) Returns a reading that matches a single token of the given type with a constant semantic interpretation.final <D,T, A> Reading <D, T, A> Returns a reading that matches a single token of the given type and text with a constant semantic interpretation.final <D,T, A> Reading <D, T, A> constantEpsilon(A value) Returns a reading that matches an empty fragment of input with a constant semantic interpretation.derive(UnaryOperator<Factory.Configuration> evolution) Creates a new variant of this factory with a modified configuration.final <D,T, A> Reading <D, T, A> Returns a recursive reading.static ReadingFactoryReturns a factory with default configuration (factory settings).final ParserFactoryReturns the parser factory used by this factory.final <D,T, A> Reading <D, T, A> ifThenElse(T type, Reading<D, T, ? extends A> thenBranch, Reading<D, T, ? extends A> elseBranch) Returns a reading that chooses deterministically between two alternatives depending on the type of the next token.final <D,T, A> Reading <D, T, A> leftAssoc(ReadingFactory.OperatorTemplate<D, T, A> template) Returns a reading that uses the given operator template left-associatively.final <D,T, A> Reading <D, T, A> lookahead(Map<T, Reading<D, T, ? extends A>> map, Parser.Pragma... pragmas) Returns a reading that chooses from the given readings according to the type of the next token.final <D,T, A> Reading <D, T, A> Returns a reading that maps the given token types to constant semantic interpretations.final <D,T, A> Reading <D, T, A> Returns a reading that maps the given token types to constant semantic interpretations.final <D,T, A> Reading <D, T, A> nonAssoc(ReadingFactory.OperatorTemplate<D, T, A> template) Returns a reading that uses the given operator template non-associatively.final <D,T, A> Reading <D, T, A> rightAssoc(ReadingFactory.OperatorTemplate<D, T, A> template) Returns a reading that uses the given operator template right-associatively.text(Collection<? extends T> types) Returns a reading that matches a single token of any of the given token types and interprets it as a text string.text(T... types) Returns a reading that matches a single token of any of the given token types and interprets it as a text string.token(Collection<? extends T> types) Returns a reading that matches a single token of any of the given token types and interprets it as content.token(T... types) Returns a reading that matches a single token of any of the given token types and interprets it as a token.final <D,T> Reading <D, T, T> type(Collection<? extends T> types) Returns a reading that matches a single token of any of the given token types and interprets it as a token type.final <D,T> Reading <D, T, T> type(T... types) Returns a reading that matches a single token of any of the given token types and interprets it as a token type.Returns a reading that matches the given syntax with zero-information semantic interpretation.unit(T... types) Returns a reading that matches the given sequence of token types with zero-information semantic interpretation.Methods inherited from class eu.bandm.tools.ramus.ogma.Factory
construct, defaultConfiguration, getConfiguration, serviceFilterByModule, serviceFilterByPackage
-
Method Details
-
derive
Creates a new variant of this factory with a modified configuration.- Parameters:
evolution- the modification to apply to the configuration- Returns:
- a new factory with a modified configuration
- Throws:
NullPointerException- ifevolutionis null
-
getParserFactory
Returns the parser factory used by this factory.- Returns:
- the parser factory used by this factory
-
getDefault
Returns a factory with default configuration (factory settings).- Returns:
- a factory with default configuration
- See Also:
-
token
Returns a reading that matches a single token of any of the given token types and interprets it as a token.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
types- an array of acceptable token types- Returns:
- a reading that matches a single token whose type is contained in
types, with the semantic result being the matched token - Throws:
NullPointerException- iftypesis null
-
token
Returns a reading that matches a single token of any of the given token types and interprets it as content.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
types- a collection of acceptable token types- Returns:
- a reading that matches a single token whose type is contained in
types, with the semantic result being the matched token - Throws:
NullPointerException- iftypesis null
-
type
Returns a reading that matches a single token of any of the given token types and interprets it as a token type.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
types- an array of acceptable token types- Returns:
- a reading that matches a single token whose type is contained in
types, with the semantic result being the type of the matched token - Throws:
NullPointerException- iftypesis null
-
type
Returns a reading that matches a single token of any of the given token types and interprets it as a token type.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
types- a collection of acceptable token types- Returns:
- a reading that matches a single token whose type is contained in
types, with the semantic result being the type of the matched token - Throws:
NullPointerException- iftypesis null
-
text
Returns a reading that matches a single token of any of the given token types and interprets it as a text string.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
types- an array of acceptable token types- Returns:
- a reading that matches a single token whose type is contained in
types, with the semantic result being the text of the matched token - Throws:
NullPointerException- iftypesis null
-
text
Returns a reading that matches a single token of any of the given token types and interprets it as a text string.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
types- a collection of acceptable token types- Returns:
- a reading that matches a single token whose type is contained in
types, with the semantic result being the text of the matched token - Throws:
NullPointerException- iftypesis null
-
constant
Returns a reading with the given syntax and a constant semantic interpretation.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
syntax- the parser that specifies the syntaxvalue- the constant value of the semantic interpretation- Returns:
- a reading that matches
syntax, with the semantic result being alwaysvalue - Throws:
NullPointerException- ifsyntaxorvalueis null
-
constant
Returns a reading that matches a single token of the given type with a constant semantic interpretation.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
type- the acceptable token typevalue- the constant value of the semantic interpretation- Returns:
- a reading that matches a single token of type equal to
type, with the semantic result being alwaysvalue - Throws:
NullPointerException- iftypeorvalueis null
-
constant
Returns a reading that matches a single token of the given type and text with a constant semantic interpretation.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
type- the acceptable token typetext- the acceptable token textvalue- the constant value of the semantic interpretation- Returns:
- a reading that matches a single token of type
typeand text equal totext, with the semantic result being alwaysvalue - Throws:
NullPointerException- iftype,textorvalueis null
-
constantEpsilon
Returns a reading that matches an empty fragment of input with a constant semantic interpretation.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
value- the constant value of the semantic interpretation- Returns:
- a reading that matches without consuming any input, with the
semantic result being always
value - Throws:
NullPointerException- ifvalueis null
-
choice
Returns a reading that matches any of the given readings, with the respective semantic interpretation. The alternatives are tried in order.Note that the information which of the alternatives has matched is not recorded.
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
alts- the alternative readings to combine- Returns:
- a reading that matches any of
altswith the respective semantic interpretation - Throws:
NullPointerException- ifaltsis or contains null
-
choice
Returns a reading that matches any of the given readings, with the respective semantic interpretation. The alternatives are tried in order.Note that the information which of the alternatives has matched is not recorded.
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
alts- the alternative readings to combine- Returns:
- a reading that matches any of
altswith the respective semantic interpretation - Throws:
NullPointerException- ifaltsis or contains null
-
lookup
Returns a reading that maps the given token types to constant semantic interpretations.FIXME: type checking
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
type- the checked type of semantic valuesmodel- a map of token types to semantic values- Returns:
- a reading that matches any token whose type is a key in
model, with the semantic result being the corresponding value - Throws:
NullPointerException- iftypeormodelis null
-
lookup
Returns a reading that maps the given token types to constant semantic interpretations.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
model- a map of token types to semantic values- Returns:
- a reading that matches any token whose type is a key in
model, with the semantic result being the corresponding value - Throws:
NullPointerException- ifmodelis null
-
lookahead
public final <D,T, Reading<D,A> T, lookaheadA> (Map<T, Reading<D, T, ? extends A>> map, Parser.Pragma... pragmas) Returns a reading that chooses from the given readings according to the type of the next token.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
map- a map of token types to readings to choose frompragmas- the pragmas to apply- Returns:
- a reading that delegates to a reading chosen from
mapaccording to the type of the next token, or fails if there is no matching entry - Throws:
NullPointerException- ifmapis null or contains a null value
-
fix
Returns a recursive reading.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
loop- a reading construction function to apply recursively- Returns:
- a reading
rthat behaves equivalently toloop.apply(r) - Throws:
NullPointerException- ifloopis null
-
unit
Returns a reading that matches the given syntax with zero-information semantic interpretation.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
syntax- the parser that specifies the syntax- Returns:
- a reading that matches
syntax, with the semantic result being alwaysUnit.unit - Throws:
NullPointerException- ifsyntaxis null
-
unit
Returns a reading that matches the given sequence of token types with zero-information semantic interpretation.The sequence
typesmay be empty; then no input is consumed.- Type Parameters:
D- the type of document identifiersT- the type of token types- Parameters:
types- an array of token types to match sequentially- Returns:
- a reading that matches a sequence of tokens whose types are
elementwise equal to
types, with the semantic result being alwaysUnit.unit - Throws:
NullPointerException- iftypesis null- See Also:
-
ifThenElse
public final <D,T, Reading<D,A> T, ifThenElseA> (T type, Reading<D, T, ? extends A> thenBranch, Reading<D, T, ? extends A> elseBranch) Returns a reading that chooses deterministically between two alternatives depending on the type of the next token.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
type- the expected token typethenBranch- the alternative to choose if the next token is of the expected typeelseBranch- the alternative to choose if the next token is of an unexpected type- Returns:
- a reading that delegates to
thenBranchif the type of the next token is equal totype, or toelseBranchotherwise - Throws:
NullPointerException- ifthenBranchorelseBranchis null
-
access
Returns a reading that retrieves the value assigned to a given key as the semantic interpretation.No input is consumed.
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
key- the key- Returns:
- a reading that consumes no input, with the semantic result being
the value assigned to
key, or FIXME if unassigned - Throws:
NullPointerException- ifkeyis null- See Also:
-
assign
Returns a reading that assigns the given value to the given key.No input is consumed.
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
key- the keyvalue- the value- Returns:
- a reading that consumes no input and assigns
valuetokeyas a side effect, with the semantic result begin alwaysUnit.unit - See Also:
-
leftAssoc
Returns a reading that uses the given operator template left-associatively.FIXME:
The resulting expression will match inputs of the form "e1 op1 ... opn-1 en", and interpret them as an AST of the form opn-1(... op1(e1, e2) ..., en).
It is assumed that all operands ei conform to the same syntax and interpretation, and that operators are distinguished by token type.
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
template- the operator template to apply- Returns:
- a reading that uses
templateleft-associatively - Throws:
NullPointerException- iftemplateis null- See Also:
-
rightAssoc
Returns a reading that uses the given operator template right-associatively.FIXME:
The resulting expression will match inputs of the form "e1 op1 ... opn-1 en", and interpret them as an AST of the form op1(e1, ... opn-1(en-1, en)...).
It is assumed that all operands ei conform to the same syntax and interpretation, and that operators are distinguished by token type.
Unmixable right-associative operators are currently not supported.
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
template- the operator template to apply- Returns:
- a reading that uses
templateright-associatively - Throws:
NullPointerException- iftemplateis nullUnsupportedOperationException- iftemplate.isMixable()is false- See Also:
-
nonAssoc
Returns a reading that uses the given operator template non-associatively.FIXME:
The resulting expression will match inputs of the form "e1 op e2", and interpret them as an AST of the form op(e1, e2).
It is assumed that all operands ei conform to the same syntax and interpretation, and that operators are distinguished by token type.
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
template- the operator template to apply- Returns:
- a reading that uses
templatenon-associatively - Throws:
NullPointerException- iftemplateis null- See Also:
-