D
- the type of source document identifiersT
- the type of token types; typically an enum typepublic abstract class Parser<D,T> extends Object implements Action.Continuation<Parser.Input<D,T>,Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>>
Every parser building block is essentially a transition step, a function
taking Parser.Input
to Parser.Output
, with computational
behavior specified by Action
and diagnostic messages of type SimpleMessage
.
Subclasses must implement this behavior by overriding the abstract method
Action<Output<D, T>, SimpleMessage<D>, Input<D, T>>
apply(Input<D, T>, Success<?, SimpleMessage<D>, Input<D, T>>)
.
The methods of this class are divided into a configurational and an operational phase:
Operational methods are explicitly marked in this documentation; all others are configurational.
The results of configurational methods are typically specified only in terms of equivalent behavior. Two parsers are behaviorally equivalent iff replacing one by the other in the following procedure does not change the outcome:
Modifier and Type | Class and Description |
---|---|
static class |
Parser.Compile |
static interface |
Parser.Input<D,T>
Abstract interface of immutable parser input states.
|
static class |
Parser.Output<D,T>
Immutable parser transition outputs.
|
static class |
Parser.Pragma
Enumeration of local pragmatic modifiers of parsing behavior.
|
static interface |
Parser.Token<D,T>
Abstract interface of parser tokens.
|
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
Parser<D,T> |
andThen(Parser<D,T> other)
Follows the behavior of this parser sequentially with another.
|
Parser<D,T> |
andThenCombining(Parser<D,T> other,
Action.BiContinuation<Data,Data,Data,SimpleMessage<D>,State> combiner)
Follows the behavior of this parser sequentially with another, combining
the result values.
|
abstract Action<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> |
apply(Parser.Input<D,T> in,
Success<?,SimpleMessage<D>,Parser.Input<D,T>> recyclable)
Applies this continuation, possibly using a recyclable leaf
node.
|
Parser<D,T> |
assigning(Object key)
Adds the assignment of the result value to a semantic variable to the
behavior of this parser.
|
static <D,T> Parser<D,T> |
choice(Parser<D,T>... alts)
Alternates the behavior of several parsers in nondeterministic choice.
|
Parser<D,T> |
collecting()
Adds the collecting of the result value in a sequence to the
behavior of this parser.
|
Parser<D,T> |
compile() |
protected void |
compileApply(eu.bandm.tools.ramus.runtime2.CompilationContext context,
ParserCompilationContext.Continuation continuation) |
static <D,T> Parser<D,T> |
constant(Data value)
Returns a parser that succeeds and sets the result to the given value,
consuming no tokens.
|
Parser<D,T> |
diagnose(Function<? super Parser.Input<D,T>,? extends SimpleMessage<D>>... msgs) |
Parser<D,T> |
diagnose(SimpleMessage<D>... msgs)
Add diagnostic messages to the behavior of this parser.
|
static <D,T> Action<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> |
diagnoseUnexpectedToken(Action<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> body,
Location<D> location,
@Opt String description) |
static <D,T> Parser<D,T> |
endInterval()
Returns a parser that sets the result value to the token location before
the current input state.
|
static <D,T> Parser<D,T> |
fail()
Returns a parser that fails immediately.
|
static <D,T> Parser<D,T> |
fix(UnaryOperator<Parser<D,T>> loop)
Computes the fixpoint of a recursive parser definition.
|
Optional<Set<T>> |
getFirstSet()
Returns the finite set of token types that this parser may consume first,
if available.
|
Parser<D,T> |
guard(Predicate<State> condition,
Function<State,List<SimpleMessage<D>>> error) |
static <D,T> Parser<D,T> |
id()
Returns a parser that succeeds with no effect, consuming no tokens.
|
static <D,T> Parser<D,T> |
ifThenElse(Predicate<Parser.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.
|
Parser<D,T> |
ignoringResult()
Removes the setting of the result value from the semantic effect of this
parser.
|
static <D,T> Predicate<Parser.Token<D,T>> |
keyword(String text)
Returns a predicate that matches a single token with a given text,
regardless of type.
|
static <D,T> Parser<D,T> |
lookbehind(Predicate<Parser.Token<D,T>> match) |
static <D,T> Parser<D,T> |
lookbehind(Set<T> types) |
static <D,T> Parser<D,T> |
lookbehind(T... types) |
static <D,T> Parser<D,T> |
lookup(Map<T,Parser<D,T>> alts)
Alternates the behavior of several parsers in deterministic choice, depending
on the next input token.
|
static <D,T> Parser<D,T> |
lookup(Map<T,Parser<D,T>> alts,
Parser<D,T> otherwise)
Alternates the behavior of several parsers in deterministic choice, depending
on the next input token.
|
static void |
main(String[] args) |
Parser<D,T> |
map(Function<Data,Data> transform)
Adds a final transformation of the result value to the behavior of this
parser.
|
boolean |
mayBeEpsilon()
Checks whether this parser may succeed without consuming any token.
|
Parser<D,T> |
negate()
Returns a parser that succeeds if this parser fails, and vice versa.
|
Parser<D,T> |
optional(Parser.Pragma... pragmas)
Returns a parser that behaves like this parser, or alternatively does
nothing.
|
Parser<D,T> |
optionalTagged(Parser.Pragma... pragmas)
Returns a parser that behaves like this parser, or alternatively does
nothing, setting a corresponding result value.
|
Parser<D,T> |
optionalTagged(Parser<D,T> defaultBranch,
Parser.Pragma... pragmas) |
Parser<D,T> |
orElse(Parser<D,T> other)
Alternates the behavior of this parser with another in nondeterministic
choice.
|
Parser<D,T> |
plus(Parser.Pragma... pragmas)
Returns a parser that behaves as the sequential iteration of this parser,
one or more times.
|
Parser<D,T> |
plusSequence(Parser.Pragma... pragmas)
Returns a parser that behaves as the sequential iteration of this parser,
one or more times, and collects the result values in a sequence.
|
Parser<D,T> |
plusSequence(Parser<D,T> separator,
Parser.Pragma... pragmas)
Returns a parser that behaves as the sequential iteration of this parser,
one or more times, interspersed with a separator parser, and collects the
result values in a sequence.
|
Parser<D,T> |
postprocess(Action.Continuation<State,State,SimpleMessage<D>,State> cont)
Appends an ad-hoc continuation to the semantic effect of this parser.
|
Parser<D,T> |
postprocess(Action.Continuation<State,State,SimpleMessage<D>,State> cont,
int complexity)
Appends an ad-hoc continuation to the semantic effect of this parser.
|
Parser<D,T> |
postprocess(Update<SimpleMessage<D>> effect)
Appends to the semantic effect of this parser.
|
Action<State,SimpleMessage<D>,State> |
process(Parser.Input<D,T> in,
Action.Visitor<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> errorVisitor) |
static <D,T> Parser<D,T> |
sequence(Parser<D,T>... elems)
Combines the behavior of several parsers sequentially.
|
Parser<D,T> |
star(Parser.Pragma... pragmas)
Returns a parser that behaves as the sequential iteration of this parser,
zero or more times.
|
Parser<D,T> |
starSequence(Parser.Pragma... pragmas)
Returns a parser that behaves as the sequential iteration of this parser,
zero or more times, and collects the result values in a sequence.
|
Parser<D,T> |
starSequence(Parser<D,T> separator,
Parser.Pragma... pragmas)
Returns a parser that behaves as the sequential iteration of this parser,
zero or more times, interspersed with a separator parser, and collects the
result values in a sequence.
|
static <D,T> Parser<D,T> |
startCollection()
Returns a parser that succeeds and sets the result to the empty sequence,
consuming no tokens.
|
static <D,T> Parser<D,T> |
startInterval()
Returns a parser that sets the result value to the token location at
the current input state.
|
static <D,T> Parser<D,T> |
succeed(Function<? super Parser.Input<D,T>,? extends Update<SimpleMessage<D>>> effect)
Returns a parser that succeeds with the given state-dependent effect,
consuming no tokens.
|
static <D,T> Parser<D,T> |
succeed(Update<SimpleMessage<D>> effect)
Returns a parser that succeeds with the given effect, consuming no tokens.
|
static <D,T> Parser<D,T> |
terminal(Predicate<Parser.Token<D,T>> match)
Returns a parser that consumes a single token matching a given predicate.
|
static <D,T> Parser<D,T> |
terminal(Predicate<Parser.Token<D,T>> match,
Optional<Set<T>> firstSet,
@Opt String description)
Returns a parser that consumes a single token matching a given predicate.
|
static <D,T> Parser<D,T> |
terminal(T type)
Returns a parser that consumes a single token of a given type.
|
static <D,T> Parser<D,T> |
terminal(T type,
Predicate<? super String> text)
Returns a parser that consumes a single token of a given type and text.
|
static <D,T> Parser<D,T> |
TRACE(String msg) |
Parser<D,T> |
withScope(Fragment... fragments)
Wraps the behavior of this parser in a local scope for a set of semantic
variables bound by grammar fragments.
|
Parser<D,T> |
withScope(Map<Object,? extends Data> initializers)
Wraps the behavior of this parser in a local scope for a set of semantic
variables.
|
Parser<D,T> |
withScope(Object key,
Data initializer)
Wraps the behavior of this parser in a local scope for a semantic
variable.
|
static <D,T> Parser.Input<D,T> |
wrap(Supplier<? extends Parser.Token<D,T>> gen)
Returns a parser input state lazily backed by a generator.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
apply, forget, map
public abstract Action<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> apply(Parser.Input<D,T> in, Success<?,SimpleMessage<D>,Parser.Input<D,T>> recyclable)
apply
in interface Action.Continuation<Parser.Input<D,T>,Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>>
in
- the input parsing resultrecyclable
- a recyclable leaf node, or null
if
not availablerecyclable
if available or new
.Action.succeed(Object, Success)
public Optional<Set<T>> getFirstSet()
The default implementation returns Optional.empty()
, which is
always safe. Subclasses may override this method to return an actual set,
if those parsers are known to never succeed with consuming a first token of
another type, to enable optimizations.
Optional.empty()
if such a set is either unknown or
infinite.mayBeEpsilon()
,
Parser.Token.getType()
public boolean mayBeEpsilon()
The default implementation returns true
, which is always safe.
Subclasses may override this method to return false
, if those
parsers are known to never succeed without consuming any token, to enable
optimizations.
true
iff it is possible (certain or unknown) that this
parser accepts zero tokens.getFirstSet()
protected void compileApply(eu.bandm.tools.ramus.runtime2.CompilationContext context, ParserCompilationContext.Continuation continuation)
public static <D,T> Parser<D,T> id()
D
- the type of source document identifiersT
- the type of token types; typically an enum typepublic static <D,T> Parser<D,T> succeed(Update<SimpleMessage<D>> effect)
D
- the type of source document identifiersT
- the type of token types; typically an enum typeeffect
- the desired semantic effectpublic static <D,T> Parser<D,T> succeed(Function<? super Parser.Input<D,T>,? extends Update<SimpleMessage<D>>> effect)
D
- the type of source document identifiersT
- the type of token types; typically an enum typeeffect
- a function object that computes the desired semantic effect,
given the current parser input statepublic static <D,T> Parser<D,T> constant(Data value)
This method is a shorthand for succeed(Update.setValue(value))
.
D
- the type of source document identifiersT
- the type of token types; typically an enum typevalue
- the desired semantic effectsucceed(Update)
,
Update.setValue(Data)
public static <D,T> Parser<D,T> startCollection()
This method is a shorthand for constant(Sequence.empty())
.
D
- the type of source document identifiersT
- the type of token types; typically an enum typeconstant(Data)
,
Sequence
public static <D,T> Parser<D,T> fail()
D
- the type of source document identifiersT
- the type of token types; typically an enum typepublic final Parser<D,T> negate()
The resulting parser speculatively executes the behavior of this parser. If this leads to one or more (nondeterministic) successes, the resulting parser fails; speculatively executed semantic effects are undone. Otherwise, if the speculative execution fails, the resulting parser succeeds with no effect, consuming no tokens.
id()
public static <D,T> Parser<D,T> startInterval()
D
- the type of source document identifiersT
- the type of token types; typically an enum typepublic static <D,T> Parser<D,T> endInterval()
D
- the type of source document identifiersT
- the type of token types; typically an enum type@SafeVarargs public static <D,T> Parser<D,T> lookbehind(T... types)
public static <D,T> Parser<D,T> lookbehind(Predicate<Parser.Token<D,T>> match)
public static <D,T> Parser<D,T> terminal(Predicate<Parser.Token<D,T>> match)
This method is a shorthand for terminal(match, Optional.empty(),
null)
; use that method directly if more specific information is available.
D
- the type of source document identifiersT
- the type of token types; typically an enum typematch
- a functional object that recognizes matching tokensState.withValue(eu.bandm.tools.ramus.runtime2.Data)
,
Content
,
terminal(Predicate, Optional, String)
public static <D,T> Parser<D,T> terminal(T type)
D
- the type of source document identifiersT
- the type of token types; typically an enum typetype
- the type of tokens to matchState.withValue(eu.bandm.tools.ramus.runtime2.Data)
,
Content
,
terminal(Predicate, Optional, String)
public static <D,T> Parser<D,T> terminal(T type, Predicate<? super String> text)
D
- the type of source document identifiersT
- the type of token types; typically an enum typetype
- the type of tokens to matchState.withValue(eu.bandm.tools.ramus.runtime2.Data)
,
Content
,
terminal(Predicate, Optional, String)
public static <D,T> Parser<D,T> terminal(Predicate<Parser.Token<D,T>> match, Optional<Set<T>> firstSet, @Opt @Opt String description)
The semantic effect of the returned parser stores the content of the
consumed token (as a Content
object) as the result value. If the
first token does not match, then parsing fails with an error message
indicating the expected token description.
This method is a shorthand for terminal(match, Optional.empty(),
match.toString())
; use that method directly if more specific information
is available.
D
- the type of source document identifiersT
- the type of token types; typically an enum typematch
- a functional object that recognizes matching tokensfirstSet
- an actual finite set of token types, if the type of any
matching token must be contained in the set, or Optional.empty()
if
such a set is unknown or infinitedescription
- a user-friendly description of the expected tokens, or
null
if not availablegetFirstSet()
,
State.withValue(eu.bandm.tools.ramus.runtime2.Data)
,
Content
,
terminal(Predicate, Optional, String)
public static <D,T> Action<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> diagnoseUnexpectedToken(Action<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> body, Location<D> location, @Opt @Opt String description)
public static <D,T> Predicate<Parser.Token<D,T>> keyword(String text)
D
- the type of source document identifiersT
- the type of token types; typically an enum typetext
- the text to matchterminal(Predicate)
@SafeVarargs public final Parser<D,T> diagnose(SimpleMessage<D>... msgs)
msgs
- the messages to addDiagnosis
@SafeVarargs public final Parser<D,T> diagnose(Function<? super Parser.Input<D,T>,? extends SimpleMessage<D>>... msgs)
public final Parser<D,T> map(Function<Data,Data> transform)
transform
- the transformation to apply to the result valuepublic final Parser<D,T> assigning(Object key)
key
- the key identifying the semantic variable to assign topublic Parser<D,T> collecting()
The resulting parser assumes that the result value of its pre-state is set to a sequence. It then performs the effect of this parser, and appends its result value to the preceding sequence, which becomes the overall result value. If the preceding result value is not a sequence, the result parser fails with a failure message.
Sequence
public final Parser<D,T> withScope(Object key, Data initializer)
The semantic effect of the returned parser embeds the effect of this parser in a context that inializes the specified variable before, and restores the previous value afterwards.
key
- the key identifying the semantic variable to scopeinitializer
- the initial value of the variable in its local scopepublic final Parser<D,T> withScope(Map<Object,? extends Data> initializers)
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 values afterwards.
initializers
- the map of keys to initial value of the variable in its local scopepublic Parser<D,T> withScope(Fragment... fragments)
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 values afterwards.
This method creates a local scope for the target variables of all given fragments that are not marked as imported, and initializes them with the specified values.
fragments
- the list of grammar fragmentsIllegalArgumentException
- if the list of fragments contains
duplicate target variable keys.Fragment.getKey()
,
Fragment.getInitialValue()
,
Fragment.isImported()
public final Parser<D,T> postprocess(Update<SimpleMessage<D>> effect)
This method is an equivalent shorthand for andThen(succeed(cons))
, but the result of this method may be slightly more
efficient.
effect
- the semantic effect to appendpublic final Parser<D,T> postprocess(Action.Continuation<State,State,SimpleMessage<D>,State> cont)
cont
- the semantic continuation to appendpublic final Parser<D,T> postprocess(Action.Continuation<State,State,SimpleMessage<D>,State> cont, int complexity)
Giving an estimate of the complexity of the continuation may help
self-optimization heuristics. If unknown, use the default value 1
.
cont
- the semantic continuation to appendcomplexity
- the estimated computational complexity of the
continuation, measured in state access operationspublic final Parser<D,T> ignoringResult()
public final Parser<D,T> andThen(Parser<D,T> other)
other
- the subsequent parserother
.public final Parser<D,T> andThenCombining(Parser<D,T> other, Action.BiContinuation<Data,Data,Data,SimpleMessage<D>,State> combiner)
other
- the subsequent parsercombiner
- a binary continuation to combine the result valuesother
, followed by the combination of result values.@SafeVarargs public static <D,T> Parser<D,T> sequence(Parser<D,T>... elems)
D
- the type of source document identifiersT
- the type of token types; typically an enum typeelems
- the array of parsers to combine sequentiallyid()
if the array is empty.andThen(Parser)
,
id()
public final Parser<D,T> orElse(Parser<D,T> other)
This method may exploit available syntactic information to reduce the
choice to a case for the deterministic variant ifThenElse
.
other
- the alternative parserother
if necessary.Choice
,
getFirstSet()
,
mayBeEpsilon()
public static <D,T> Parser<D,T> ifThenElse(Predicate<Parser.Token<D,T>> condition, Parser<D,T> thenBranch, Parser<D,T> elseBranch)
D
- the type of source document identifiersT
- the type of token types; typically an enum typecondition
- 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 conditionParser.Input.lookahead(int)
public final Parser<D,T> optional(Parser.Pragma... pragmas)
This method supports the following pragmas:
Greedy
– always perform the behavior
of this parser if the next token is of an acceptable type.Productive
– throw an exception if this parser
may succeed without consuming a token; thus creating an ambiguity that
cannot be resolved by syntax.pragmas
- the pragmas to applyid()
.UnsupportedOperationException
- optionally if the Productive
pragma is specified, and this.mayBeEpsilon()
returns true
.id()
,
getFirstSet()
,
mayBeEpsilon()
public final Parser<D,T> optionalTagged(Parser.Pragma... pragmas)
The semantic effect of the returned parser wraps the result value of
this parser with Option.just(eu.bandm.tools.ramus.runtime2.Data)
if the corresponding branch has been
chosen, or sets the result value to Option.none
otherwise.
This method supports the following pragmas:
Greedy
– always perform the behavior
of this parser if the next token is of an acceptable type.Productive
– throw an exception if this parser
may succeed without consuming a token; thus creating an ambiguity that
cannot be resolved by syntax.pragmas
- the pragmas to applyid()
, setting a corresponding result value.UnsupportedOperationException
- optionally if the Productive
pragma is specified, and this.mayBeEpsilon()
returns true
.id()
,
getFirstSet()
,
mayBeEpsilon()
,
Option
public final Parser<D,T> optionalTagged(Parser<D,T> defaultBranch, Parser.Pragma... pragmas)
@SafeVarargs public static <D,T> Parser<D,T> choice(Parser<D,T>... alts)
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
operation andThen(eu.bandm.tools.ramus.runtime2.Parser<D, T>)
, this method
orElse
, where more than two alternatives are concerned;D
- the type of source document identifiersT
- the type of token types; typically an enum typealts
- the alternative branchesChoice
,
getFirstSet()
,
mayBeEpsilon()
public static <D,T> Parser<D,T> lookup(Map<T,Parser<D,T>> alts)
D
- the type of source document identifiersT
- the type of token types; typically an enum typealts
- a map of token types to parsers, to be chosen if the next token
is of the respective typepublic static <D,T> Parser<D,T> lookup(Map<T,Parser<D,T>> alts, Parser<D,T> otherwise)
D
- the type of source document identifiersT
- the type of token types; typically an enum typealts
- 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 typeotherwise
if there is none.public static <D,T> Parser<D,T> fix(UnaryOperator<Parser<D,T>> loop)
D
- the type of source document identifiersT
- the type of token types; typically an enum typeloop
- a function object that returns a parser, assuming that it
receives a behaviorally equivalent parser as inputp
that is behaviorally equivalent to loop.apply(p)
.public final Parser<D,T> star(Parser.Pragma... pragmas)
This method is a shorthand for fix(p -> this.andThen(p).optional(pragmas))
.
This method supports the following pragmas:
Greedy
– always perform another
iteration of the behavior of this parser if the next token is of an
acceptable type.Productive
–
throw an exception if this parser may succeed without consuming a token;
thus creating an ambiguity that cannot be resolved by syntax.pragmas
- the pragmas to applyUnsupportedOperationException
- optionally if the Productive
pragma is specified, and this.mayBeEpsilon()
returns true
.plus(Pragma...)
,
getFirstSet()
,
mayBeEpsilon()
public final Parser<D,T> plus(Parser.Pragma... pragmas)
This method is a shorthand for fix(p -> this.andThen(p.optional(pragmas)))
.
This method supports the following pragmas:
Greedy
– always perform another
iteration of the behavior of this parser if the next token is of an
acceptable type.Productive
–
throw an exception if this parser may succeed without consuming a token;
thus creating an ambiguity that cannot be resolved by syntax.pragmas
- the pragmas to applyUnsupportedOperationException
- optionally if the Productive
pragma is specified, and this.mayBeEpsilon()
returns true
.star(Pragma...)
,
getFirstSet()
,
mayBeEpsilon()
public final Parser<D,T> starSequence(Parser.Pragma... pragmas)
This method is a shorthand for startCollection().andThen(this.collecting().star(pragmas))
.
This method supports the following pragmas:
Greedy
– always perform another
iteration of the behavior of this parser if the next token is of an
acceptable type.Productive
–
throw an exception if this parser may succeed without consuming a token;
thus creating an ambiguity that cannot be resolved by syntax.pragmas
- the pragmas to applyUnsupportedOperationException
- optionally if the Productive
pragma is specified, and this.mayBeEpsilon()
returns true
.star(Pragma...)
,
plusSequence(Pragma...)
,
collecting()
,
getFirstSet()
,
mayBeEpsilon()
public final Parser<D,T> plusSequence(Parser.Pragma... pragmas)
This method is a shorthand for startCollection().andThen(this.collecting().plus(pragmas))
.
This method supports the following pragmas:
Greedy
– always perform another
iteration of the behavior of this parser if the next token is of an
acceptable type.Productive
–
throw an exception if this parser may succeed without consuming a token;
thus creating an ambiguity that cannot be resolved by syntax.pragmas
- the pragmas to applyUnsupportedOperationException
- optionally if the Productive
pragma is specified, and this.mayBeEpsilon()
returns true
.plus(Pragma...)
,
starSequence(Pragma...)
,
collecting()
,
getFirstSet()
,
mayBeEpsilon()
public Parser<D,T> starSequence(Parser<D,T> separator, Parser.Pragma... pragmas)
This method supports the following pragmas:
Greedy
– always perform another
iteration of the behavior of this parser if the next token is of an
acceptable type.Productive
–
throw an exception if this parser and the separator may succeed without
consuming a token; thus creating an ambiguity that cannot be resolved by
syntax.separator
- the parser to invoke between consecutive iterationspragmas
- the pragmas to applyseparator
.UnsupportedOperationException
- optionally if the Productive
pragma is specified, and both this.mayBeEpsilon()
and {separator.mayBeEpsilon()} return true
.star(Pragma...)
,
plusSequence(Parser, Pragma...)
,
collecting()
,
getFirstSet()
,
mayBeEpsilon()
public Parser<D,T> plusSequence(Parser<D,T> separator, Parser.Pragma... pragmas)
This method supports the following pragmas:
Greedy
– always perform another
iteration of the behavior of this parser if the next token is of an
acceptable type.Productive
–
throw an exception if this parser and the separator may succeed without
consuming a token; thus creating an ambiguity that cannot be resolved by
syntax.separator
- the parser to invoke between consecutive iterationspragmas
- the pragmas to applyseparator
.UnsupportedOperationException
- optionally if the Productive
pragma is specified, and both this.mayBeEpsilon()
and {separator.mayBeEpsilon()} return true
.plus(Pragma...)
,
starSequence(Parser, Pragma...)
,
collecting()
,
getFirstSet()
,
mayBeEpsilon()
public Parser<D,T> guard(Predicate<State> condition, Function<State,List<SimpleMessage<D>>> error)
public static <D,T> Parser.Input<D,T> wrap(Supplier<? extends Parser.Token<D,T>> gen)
The returned input state represent the potentially infinite sequence of
tokens obtained by successive invocations of the method Supplier.get()
of the given generator.
The sequence is created lazily; new tokens are demanded only when
required by Parser.Input.lookahead(int)
or Parser.Input.consume()
. Thus
concurrent shared use of the generator may result in nondeterministic
behavior.
The implementation is thread-safe: concurrent shared uses of the
resulting Parser.Input
object observe consistent token sequences.
D
- the type of source document identifiersT
- the type of token types; typically an enum typegen
- a functional object that generates tokens on demandpublic Action<State,SimpleMessage<D>,State> process(Parser.Input<D,T> in, Action.Visitor<Parser.Output<D,T>,SimpleMessage<D>,Parser.Input<D,T>> errorVisitor)
public static void main(String[] args)
see also the complete user documentation .