Class ParserFactory
Parser factories have various configuration parameters that are fixed at construction time. A new parser factory can be derived from an existing one by changing a specific configuration parameter.
Configuration parameters control features of the parsers constructed by the factory, but only those that are not part of the main functionality. As a consequence, parsers constructed by different factories are interoperable; the observable input–output behavior is not affected by the choice of factory. Nevertheless, for uniform non-functional behavior such as the availability of metadata, it is recommended to construct all parsers that make up a grammar with the same factory.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for location tracking service.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> Parser <D, T> andThenCombining(Parser<D, T> first, Parser<D, T> second, Action.BiContinuation<Data, Data, Data, SimpleMessage<D>, State> combiner, Parser.Pragma... pragmas) Follows the behavior of one parser sequentially with another, combining the result values.final <D,T> Parser <D, T> Adds the assignment of the accumulator value to a semantic variable to the behavior of a given parser.final <D,T> Parser <D, T> Alternates the behavior of several parsers in nondeterministic choice.final <D,T> Parser <D, T> Alternates the behavior of several parsers in nondeterministic choice.final <D,T> Parser <D, T> collecting(Parser<D, T> body) Makes a given parser collect results in a sequence.final <D,T> Parser <D, T> Returns a parser that succeeds and sets the result to the given value, consuming no tokens.derive(UnaryOperator<Factory.Configuration> evolution) Creates a new variant of this factory with a modified configuration.final <D,T> Parser <D, T> diagnose(Parser<D, T> body, SimpleMessage<D>... msgs) Adds diagnostic messages to the behavior of a given parser.final <D,T> Parser <D, T> diagnose(Parser<D, T> body, Function<? super Input<D, T>, ? extends List<? extends SimpleMessage<D>>> msgs) Add diagnostic messages to the behavior of a given parser.static <D,T> Action <Output<D, T>, SimpleMessage<D>, Input<D, T>> diagnoseUnexpectedToken(Action<Output<D, T>, SimpleMessage<D>, Input<D, T>> body, @Opt Location<D> location, @Opt String description) Extends a search tree with an error message regarding an unexpected token.final <D,T> Parser <D, T> Returns a parser that sets the result value to the token location before the current input state.final <D,T> Parser <D, T> fail()Returns a parser that fails immediately.final <D,T> Parser <D, T> fix(UnaryOperator<Parser<D, T>> loop, Parser.Pragma... pragmas) Computes the fixpoint of a recursive parser definition.final <D,T> Parser <D, T> fix(UnaryOperator<Parser<D, T>> loop, UnaryOperator<Parser<D, T>> polish, Parser.Pragma... pragmas) static ParserFactoryReturns a parser factory with default configuration (factory settings).<D,T> ParserFactory.Locator <D, T> Returns a location tracking service.final <D,T> Parser <D, T> identity()Returns a parser that succeeds with no effect, consuming no tokens.final <D,T> Parser <D, T> ifThenElse(Predicate<Token<D, T>> condition, Parser<D, T> thenBranch, Parser<D, T> elseBranch) Alternates the behavior of two parsers in deterministic choice, depending on the next input token.final <D,T> Parser <D, T> ignoringResult(Parser<D, T> body) Removes the setting of the accumulator value from the semantic effect of a given parser.Returns a predicate that matches a single token with a given text, regardless of type.final <D,T> Parser <D, T> lookbehind(Predicate<? super Token<D, T>> match) Returns a parser that succeeds if and only if the preceding token matches a given predicate.final <D,T> Parser <D, T> lookbehind(Set<T> types) Returns a parser that succeeds if and only if the preceding token is of one of the given types.final <D,T> Parser <D, T> lookbehind(T... types) Returns a parser that succeeds if and only if the preceding token is of one of the given types.final <D,T> Parser <D, T> lookup(Map<T, Parser<D, T>> alts, Parser.Pragma... pragmas) Alternates the behavior of several parsers in deterministic choice, depending on the next input token.final <D,T> Parser <D, T> lookup(Map<T, Parser<D, T>> alts, Parser<D, T> otherwise, Parser.Pragma... pragmas) Alternates the behavior of several parsers in deterministic choice, depending on the next input token.final <D,T> Parser <D, T> map(Parser<D, T> body, UnaryOperator<Data> transform) Adds a final transformation of the result value to the behavior of a given parser.final <D,T> Parser <D, T> Returns a parser that succeeds if the given parser fails, and vice versa.final <D,T> Parser <D, T> postprocess(Parser<D, T> body, Update<SimpleMessage<D>> effect) Appends to the semantic effect of a given parser.final <D,T> Parser <D, T> Combines the behavior of several parsers sequentially.final <D,T> Parser <D, T> Combines the behavior of several parsers sequentially.final <D,T> Parser <D, T> sideEffect(Runnable effect) Returns a parser that always succeeds without semantic effect, and performs the given side effect directly.final <D,T> Parser <D, T> sideEffect(Consumer<Input<D, T>> effect) Returns a parser that always succeeds without semantic effect, and performs the given side effect directly.final <D,T> Parser <D, T> Returns a parser that succeeds and sets the result to the empty sequence, consuming no tokens.final <D,T> Parser <D, T> Returns a parser that sets the result value to the token location at the current input state.final <D,T> Parser <D, T> succeed(Update<SimpleMessage<D>> effect) Returns a parser that succeeds with the given effect, consuming no tokens.final <D,T> Parser <D, T> succeedGivenInput(Function<? super Input<D, T>, ? extends Update<SimpleMessage<D>>> effect) Returns a parser that succeeds with the given state-dependent effect, consuming no tokens.final <D,T> Parser <D, T> terminal()Returns a parser that consumes any single token.final <D,T> Parser <D, T> Returns a parser that consumes a single token matching a given predicate.final <D,T> Parser <D, T> terminal(T type) Returns a parser that consumes a single token of a given type.final <D,T> Parser <D, T> Returns a parser that consumes a single token of a given type and text.final <D,T> Parser <D, T> Wraps the behavior of a given parser in a local scope for a semantic variable.final <D,T> Parser <D, T> Wraps the behavior of a given in a local scope for a set of semantic variables.final <D,T> Parser <D, T> Adds side effects to a given parser to be performed directly before and after, respectively.Methods inherited from class eu.bandm.tools.ramus.ogma.Factory
construct, defaultConfiguration, getConfiguration, serviceFilterByModule, serviceFilterByPackage
-
Method Details
-
getDefault
Returns a parser factory with default configuration (factory settings).- Returns:
- a parser factory with default configuration
-
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
-
identity
Returns a parser that succeeds with no effect, consuming no tokens.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Returns:
- a parser that succeeds with no effect, consuming no tokens.
-
succeed
Returns a parser that succeeds with the given effect, consuming no tokens.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
effect- the desired semantic effect- Returns:
- a parser that succeeds with the given effect, consuming no tokens.
- Throws:
NullPointerException- ifeffectis null
-
succeedGivenInput
public final <D,T> Parser<D,T> succeedGivenInput(Function<? super Input<D, T>, ? extends Update<SimpleMessage<D>>> effect) Returns a parser that succeeds with the given state-dependent effect, consuming no tokens.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
effect- a function object that computes the desired semantic effect, given the current parser input state- Returns:
- a parser that succeeds with the computed effect, consuming no tokens.
- Throws:
NullPointerException- ifeffectis null
-
constant
Returns a parser that succeeds and sets the result to the given value, consuming no tokens.This method is a shorthand for
succeed(Update.setValue(Data.atomic(value))).- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
value- the desired semantic value- Returns:
- a parser that succeeds with the effect of setting the result to the given value, consuming no tokens.
- Throws:
NullPointerException- ifvalueis null- See Also:
-
startCollection
Returns a parser that succeeds and sets the result to the empty sequence, consuming no tokens.This operation is useful in conjunction with
collecting(eu.bandm.tools.ramus.ogma.Parser<D, T>).- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Returns:
- a parser that succeeds with the effect of setting the result to the empty sequence, consuming no tokens.
- See Also:
-
fail
Returns a parser that fails immediately.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Returns:
- a parser that fails with no effect, consuming no tokens.
-
negate
Returns a parser that succeeds if the given parser fails, and vice versa.The resulting parser speculatively executes the behavior of
body. If this leads to one or more (nondeterministic) successes, the resulting parser fails; speculatively applied semantic effects have no bearing further computations. Otherwise, if the speculative execution fails, the resulting parser succeeds with no effect, consuming no tokens.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to negate- Returns:
- a parser that succeeds with no effect if
bodyfails and vice versa - Throws:
NullPointerException- ifbodyis null- See Also:
-
startInterval
Returns a parser that sets the result value to the token location at the current input state.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Returns:
- a parser that sets the result value to the token location at the current input state.
-
endInterval
Returns a parser that sets the result value to the token location before the current input state.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Returns:
- a parser that sets the result value to the token location before the current input state.
-
lookbehind
Returns a parser that succeeds if and only if the preceding token is of one of the given types.If there is no preceding token, or its type is not among the given ones, then the parser fails.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
types- an array of token types- Returns:
- a parser that succeeds if and only if the preceding token has a
type contained in
types. - Throws:
NullPointerException- iftypesis null
-
lookbehind
Returns a parser that succeeds if and only if the preceding token is of one of the given types.If there is no preceding token, or its type is not among the given ones, then the parser fails.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
types- a set of token types- Returns:
- a parser that succeeds if and only if the preceding token has a
type contained in
types. - Throws:
NullPointerException- iftypesis null
-
lookbehind
Returns a parser that succeeds if and only if the preceding token matches a given predicate.If there is no preceding token, or its type is not among the given ones, then the parser fails.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
match- a predicate to match- Returns:
- a parser that succeeds if and only if
matchreturnstruewhen applied to the preceding token. - Throws:
NullPointerException- iftypesis null
-
terminal
Returns a parser that consumes any single token.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Returns:
- a parser that succeeds by consuming the next token and storing it in the accumulator of the semantic state
- See Also:
-
terminal
Returns a parser that consumes a single token matching a given predicate.This method is a shorthand for
terminal(match, Predictor.plus(), null); use that method directly if more specific information is available.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
match- a functional object that recognizes acceptable tokens- Returns:
- a parser that succeeds by consuming the next token and storing it
in the accumulator of the semantic state, if the token is accepted by
match; otherwise parsing fails and rejects the token - Throws:
NullPointerException- ifmatchis null- See Also:
-
terminal
Returns a parser that consumes a single token of a given type.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
type- the type of tokens to match- Returns:
- a parser that succeeds by consuming the next token and storing it
in the accumulator of the semantic state, if the token has the type
type; otherwise parsing fails and rejects the token - Throws:
NullPointerException- iftypeis null- See Also:
-
terminal
Returns a parser that consumes a single token of a given type and text.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
type- the type of tokens to matchtext- a predicate that specifies acceptable text- Returns:
- a parser that succeeds by consuming the next token and storing it
in the accumulator of the semantic state, if the token has the type
typeand text accepted bytext; otherwise parsing fails and rejects the token - Throws:
NullPointerException- iftypeortextis null- See Also:
-
diagnoseUnexpectedToken
public static <D,T> Action<Output<D,T>, diagnoseUnexpectedTokenSimpleMessage<D>, Input<D, T>> (Action<Output<D, T>, SimpleMessage<D>, Input<D, T>> body, @Opt Location<D> location, @Opt String description) Extends a search tree with an error message regarding an unexpected token.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the search tree to extendlocation- the location of the unexpected token, ornullif not availabledescription- a user-friendly description of expected tokens, ornullif not available- Returns:
- a search tree where all successes have been extended with an error message using the given information
- Throws:
NullPointerException- ifbodyis null
-
keyword
Returns a predicate that matches a single token with a given text, regardless of type.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
text- the text to match- Returns:
- a predicate that matches a token if and only if it has text equal
to
text. - Throws:
NullPointerException- iftextis null- See Also:
-
diagnose
Adds diagnostic messages to the behavior of a given parser.Adding zero messages has no effect.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extendmsgs- the messages to add- Returns:
- a parser that behaves equivalently to
body, but annotates the all successes of the search tree withmsgs - Throws:
NullPointerException- ifbody,msgsor any element is null- See Also:
-
diagnose
public final <D,T> Parser<D,T> diagnose(Parser<D, T> body, Function<? super Input<D, T>, ? extends List<? extends SimpleMessage<D>>> msgs) Add diagnostic messages to the behavior of a given parser.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extendmsgs- a function that computes the messages to add from the current input- Returns:
- a parser that behaves equivalently to
body, but annotates the all successes of the search tree with the result ofmsgsapplied to the current input - Throws:
NullPointerException- ifbodyormsgsis null
-
map
Adds a final transformation of the result value to the behavior of a given parser.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extendtransform- the transformation to apply to the result value- Returns:
- a parser that behaves equivalently to
body, but whose semantic effect transforms the result value bytransform - Throws:
NullPointerException- ifbodyortransformis null- See Also:
-
assigning
Adds the assignment of the accumulator value to a semantic variable to the behavior of a given parser.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extendkey- the key identifying the semantic variable to assign to- Returns:
- a parser that behaves equivalently to
body, but whose semantic effect also assigns the accumulator value tokey - Throws:
NullPointerException- ifbodyorkeyis null- See Also:
-
collecting
Makes a given parser collect results in a sequence.The resulting parser assumes that the accumulator value of its pre-state is set to a sequence. It then performs the effect of this parser, and appends its accumulator value to the preceding sequence, which becomes the overall accumulator value. FIXME (exception handling): If the preceding accumulator value is not a sequence, the result parser fails with a failure message.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extend- Returns:
- a parser that behaves equivalently to
body, but whose semantic effect then appends the result value to the preceding one, if that is a sequence, or otherwise fails - Throws:
NullPointerException- ifbodyis null- See Also:
-
withScope
Wraps the behavior of a given parser in a local scope for a semantic variable.The semantic effect of the returned parser embeds the effect of this parser in a context that initializes the specified variable before, and restores the previous environment afterwards.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extendkey- the key identifying the semantic variable to scopeinitializer- the initial value of the variable in its local scope- Returns:
- a parser that behaves equivalently to
body, but whose semantic effect executes in a context where the specified variable is locally scoped - Throws:
NullPointerException- ifbody,keyorinitializeris null
-
withScope
Wraps the behavior of a given in a local scope for a set of semantic variables.The semantic effect of the returned parser embeds the effect of this parser in a context that inializes the specified variables before, and restores the previous environment afterwards.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extendinitializers- the map of keys to initial value of the variable in its local scope- Returns:
- a parser that behaves equivalently to
body, but whose semantic effect executes in a context where the specified variables are locally scoped. - Throws:
NullPointerException- ifbody,initializersor any map key or value is null
-
postprocess
Appends to the semantic effect of a given parser.This method is an equivalent shorthand for
body.andThen(succeed(cons)), but the result of this method may be slightly more efficient.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to extendeffect- the semantic effect to append- Returns:
- a parser that behaves equivalently to
body, but where the semantic effect of this parser is sequentially followed byeffect. - Throws:
NullPointerException- ifbodyoreffectis null
-
ignoringResult
Removes the setting of the accumulator value from the semantic effect of a given parser. All other effects, such as diagnostics and assignments to state variables, are unaffected.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
body- the parser to modify- Returns:
- a parser that behaves equivalently to
body, but where the previous accumulator value is restored. - See Also:
-
andThenCombining
public final <D,T> Parser<D,T> andThenCombining(Parser<D, T> first, Parser<D, T> second, Action.BiContinuation<Data, Data, Data, SimpleMessage<D>, State> combiner, Parser.Pragma... pragmas) Follows the behavior of one parser sequentially with another, combining the result values.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
first- the first parsersecond- the subsequent parsercombiner- a binary continuation to combine the result values- Returns:
- a parser that behaves equivalently to
first, sequentially followed bysecond, followed by the combination of result values. - Throws:
NullPointerException- iffirst,secondorcombineris null
-
sequence
Combines the behavior of several parsers sequentially.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
elems- the array of parsers to combine sequentially- Returns:
- a parser that behaves equivalently to all of the given parsers
combined sequentially, or to
identity()if the array is empty. - Throws:
NullPointerException- ifelemsis or contains null- See Also:
-
sequence
Combines the behavior of several parsers sequentially.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
elems- the list of parsers to combine sequentially- Returns:
- a parser that behaves equivalently to all of the given parsers
combined sequentially, or to
identity()if the list is empty. - Throws:
NullPointerException- ifelemsis or contains null- See Also:
-
ifThenElse
public final <D,T> Parser<D,T> ifThenElse(Predicate<Token<D, T>> condition, Parser<D, T> thenBranch, Parser<D, T> elseBranch) Alternates the behavior of two parsers in deterministic choice, depending on the next input token.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
condition- a predicate to apply to the next input tokenthenBranch- the branch to choose if the next input token matches the conditionelseBranch- the branch to choose if the next input token does not match the condition- Returns:
- a parser that behaves equivalently to either given branch, depending on whether the next input token matches the condition.
- Throws:
NullPointerException- ifcondition,thenBranchorelseBranchis null- See Also:
-
choice
Alternates the behavior of several parsers in nondeterministic choice.This method may exploit available syntactic information to reduce the choice to a case for the deterministic variant
lookup.In contrast to the dual operation
sequence, which can be conceived as the moral equivalent of an iteration of the binary operationandThen, this method- is strongly preferrable to an iteration of the binary operation
orElse, where more than two alternatives are concerned; - but may not preserve the order in which alternative branches are tried.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
alts- the alternative branches- Returns:
- a parser that behaves equivalent to the choice of all alternative branches, tried in some arbitrary given order, nondeterministically if necessary.
- See Also:
- is strongly preferrable to an iteration of the binary operation
-
choice
Alternates the behavior of several parsers in nondeterministic choice.This method may exploit available syntactic information to reduce the choice to a case for the deterministic variant
lookup.In contrast to the dual operation
sequence, which can be conceived as the moral equivalent of an iteration of the binary operationandThen, this method- is strongly preferrable to an iteration of the binary operation
orElse, where more than two alternatives are concerned; - but may not preserve the order in which alternative branches are tried.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
alts- the alternative branches- Returns:
- a parser that behaves equivalent to the choice of all alternative branches, tried in some arbitrary given order, nondeterministically if necessary.
- See Also:
- is strongly preferrable to an iteration of the binary operation
-
lookup
Alternates the behavior of several parsers in deterministic choice, depending on the next input token.This method supports the following pragmas:
Reachable– throw an exception if any of the given parsers is known to never succeed if the next input token is of the associated type.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
alts- a map of token types to parsers, to be chosen if the next token is of the respective typepragmas- the pragmas to apply- Returns:
- a parser that behaves equivalently to the parser mapped to the type of the next input token, or to a parser that fails with a diagnostic hint if there is none.
- Throws:
UnsupportedOperationException- if a parser is found in the mapaltssuch that is predictor rules out the associated key- See Also:
-
lookup
public final <D,T> Parser<D,T> lookup(Map<T, Parser<D, T>> alts, Parser<D, T> otherwise, Parser.Pragma... pragmas) Alternates the behavior of several parsers in deterministic choice, depending on the next input token.This method supports the following pragmas:
Reachable– throw an exception if any of the given parsers is known to never succeed if the next input token is of the associated type.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
alts- a map of token types to parsers, to be chosen if the next input token is of the respective typeotherwise- the parser to be chosen if the next input token is of an unmapped typepragmas- the pragmas to apply- Returns:
- a parser that behaves equivalently to the parser mapped to the type
of the next input token, or to
otherwiseif there is none. - Throws:
UnsupportedOperationException- if a parser is found in the mapaltssuch that is predictor rules out the associated key- See Also:
-
fix
Computes the fixpoint of a recursive parser definition.This method supports the following pragmas:
Productive– throw an exception if the recursive may succeed without consuming a token; thus creating an ambiguity that cannot be resolved by syntax.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
loop- a function object that returns a parser, assuming that it receives a behaviorally equivalent parser as inputpragmas- the pragmas to apply- Returns:
- a parser
pthat is behaviorally equivalent toloop.apply(p). - Throws:
NullPointerException- ifloopis or returns nullUnsupportedOperationException- optionally if theProductivepragma is specified, andisConsuming()method of the parser returned byloopreturnsfalse.
-
fix
public final <D,T> Parser<D,T> fix(UnaryOperator<Parser<D, T>> loop, UnaryOperator<Parser<D, T>> polish, Parser.Pragma... pragmas) -
sideEffect
Returns a parser that always succeeds without semantic effect, and performs the given side effect directly.Side effects caused by the resulting parser cannot be undone via backtracking. Use this operation with care and for monitoring purposes only.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
effect- the side effect to perform- Returns:
- a parser that always succeeds without semantic effect, and invokes
effectdirectly - Throws:
NullPointerException- ifeffectis null
-
sideEffect
Returns a parser that always succeeds without semantic effect, and performs the given side effect directly.Side effects caused by the resulting parser cannot be undone via backtracking. Use this operation with care and for monitoring purposes only.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
effect- the side effect to perform with the current input- Returns:
- a parser that always succeeds without semantic effect, and invokes
effectwith the current input directly - Throws:
NullPointerException- ifeffectis null
-
withSideEffects
public final <D,T> Parser<D,T> withSideEffects(Consumer<Input<D, T>> pre, Parser<D, T> body, Consumer<Input<D, T>> post) Adds side effects to a given parser to be performed directly before and after, respectively.Side effects caused by the resulting parser cannot be undone via backtracking. Use this operation with care and for monitoring purposes only.
- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Parameters:
pre- the side effect to perform before parsing with the current inputbody- the parser to extendpost- the side effect to perform after parsing with the remaining input- Returns:
- a parser that behaves equivalently to
body, but additionally invokesprewith its current input directly before parsing, andpostwith the same input directly after parsing - Throws:
NullPointerException- ifpre,bodyorpostis null
-
getLocator
Returns a location tracking service.- Type Parameters:
D- the type of source document identifiersT- the type of token types; typically an enum type- Returns:
- a location tracking service
-