Class Reading<D,T,A>
- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA safe map of keys to initial values.static final recordA parsing result annotated with diagnostic messages.static classA key with static type information about its associated value.static classQueriable summary of the outcomes of processing input with a reading. -
Method Summary
Modifier and TypeMethodDescriptionstatic <D,T, A> Reading <D, T, A> access(Reading.Key<A> key) Deprecated.andThenCombining(Reading<D, T, B> other, BiFunction<? super A, ? super B, ? extends C> pair) Returns a reading that matches the syntax of this reading followed by that of another, combining the semantic interpretations with a function.Returns a reading that matches the syntax of this reading followed by that of another, combining the semantic interpretations.Returns a reading that matches the syntax of this reading with a suffix, with the same semantic interpretation.Returns a reading that matches the syntax of this reading with a suffix, with the same semantic interpretation.assigning(Reading.Key<? super A> key) Returns a reading that assigns the interpretation result of this reading to the given key.static <D,T, A> Reading <D, T, A> Returns a reference to the given reading that specifies a widened result type.static <D,T, A> Reading <D, T, A> Deprecated.UseReadingFactory.choice(Reading[])instead.static <D,T, A> Reading <D, T, A> Deprecated.UseReadingFactory.choice(List)instead.closeAndRepeat(Parser.Pragma... pragmas) closeAndTerminate(T endType, Parser.Pragma... pragmas) static <D,T, A> Reading <D, T, A> Deprecated.UseReadingFactory.constant(Parser, Object)instead.static <D,T, A> Reading <D, T, A> constant(T type, A value) Deprecated.UseReadingFactory.constant(Object, Object)instead.static <D,T, A> Reading <D, T, A> Deprecated.UseReadingFactory.constant(Object, String, Object)instead.static <D,T, A> Reading <D, T, A> constantEpsilon(A value) Deprecated.UseReadingFactory.constantEpsilon(Object)instead.content(Collection<? extends T> types) Deprecated.UseReadingFactory.token(Collection)instead.content(T... types) Deprecated.UseReadingFactory.token(Object[])instead.diagnose(SimpleMessage<D>... msgs) static <D,T, A> Reading <D, T, A> Deprecated.UseReadingFactory.fix(Function)instead.final ReadingFactoryReturns the factory that has created this reading.Returns a reading that extends the behavior of this reading with a mandatory check and conditional error diagnostics.static <D,T, A> Reading <D, T, A> ifThenElse(T type, Reading<D, T, ? extends A> thenBranch, Reading<D, T, ? extends A> elseBranch) Deprecated.UseReadingFactory.ifThenElse(Object, Reading, Reading)instead.static <D,T, A> Reading <D, T, A> leftAssoc(ReadingFactory.OperatorTemplate<D, T, A> template) Deprecated.UseReadingFactory.leftAssoc(OperatorTemplate)instead.static <D,T, A> Reading <D, T, A> lookahead(Map<T, Reading<D, T, ? extends A>> map, Parser.Pragma... pragmas) Deprecated.UseReadingFactory.lookahead(Map, Parser.Pragma[])instead.static <D,T, A> Reading <D, T, A> Deprecated.UseReadingFactory.lookup(Class, Map)instead.static <D,T, A> Reading <D, T, A> Deprecated.UseReadingFactory.lookup(Class, Map)instead.Returns a reading that matches the same syntax as this reading, and applies a function to the result of semantic interpretation.Returns a reading that matches the syntax of this reading followed by that of another, combining the semantic interpretations as a map entry.static <D,T, A> Reading <D, T, A> nonAssoc(ReadingFactory.OperatorTemplate<D, T, A> template) Deprecated.UseReadingFactory.nonAssoc(OperatorTemplate)instead.optional(Parser.Pragma... pragmas) Returns a reading that matches the syntax of this reading with optional interpretation, or otherwise matches no input.optionalOrElse(Parser<D, T> defaultSyntax, Parser.Pragma... pragmas) Returns a reading that matches the syntax of this reading with optional interpretation, or otherwise match some alternative syntax.optionalOrElse(T defaultType, Parser.Pragma... pragmas) Returns a reading that matches the syntax of this reading with optional interpretation, or otherwise match a single token.orElse(A defaultValue, Parser.Pragma... pragmas) Returns a reading that matches the syntax of this reading with the same interpretation, or otherwise matches no input with the given default result value.Returns a reading that matches alternatively the syntax of this or another reading, with the respective interpretation result.orElseGet(Supplier<? extends A> defaultValue, Parser.Pragma... pragmas) Returns a reading that matches the syntax of this reading with the same interpretation, or otherwise matches no input with the given default result value.plus(Parser.Pragma... pragmas) Returns a reading that matches one or more repetitions of this reading.plus(Parser<D, T> sep, Parser.Pragma... pragmas) Returns a reading that matches one or more repetitions of this reading with intervening separator syntax.plus(T sep, Parser.Pragma... pragmas) Returns a reading that matches one or more repetitions of this reading with intervening simple separator syntax.Returns a reading that matches the syntax of this reading with a prefix, with the same semantic interpretation.Returns a reading that matches the syntax of this reading with a prefix, with the same semantic interpretation.process(LookaheadTokenSource<D, T, ?> input) Parses the given input with this reading and returns a complete summary of interpretations.Parses the given input with this reading and returns a complete summary of interpretations.static <D,T, A> Reading <D, T, A> rightAssoc(ReadingFactory.OperatorTemplate<D, T, A> template) Deprecated.UseReadingFactory.rightAssoc(OperatorTemplate)instead.star(Parser.Pragma... pragmas) Returns a reading that matches zero or more repetitions of this reading.star(Parser<D, T> sep, Parser.Pragma... pragmas) Returns a reading that matches zero or more repetitions of this reading with intervening separator syntax.star(T sep, Parser.Pragma... pragmas) Returns a reading that matches zero or more repetitions of this reading with intervening simple separator syntax.text(Collection<? extends T> types) Deprecated.UseReadingFactory.text(Object[])instead.text(T... types) Deprecated.UseReadingFactory.text(Object[])instead.toString()static <D,T> Reading <D, T, T> type(Collection<? extends T> types) Deprecated.UseReadingFactory.type(Collection)instead.static <D,T> Reading <D, T, T> type(T... types) Deprecated.UseReadingFactory.type(Object[])instead.Deprecated.UseReadingFactory.unit(Parser)instead.unit(T... types) Deprecated.UseReadingFactory.unit(Object[])instead.withOtherTokenSource(LookaheadTokenMultiplexer<K, D, T, ?> multi, K newKey) Extends the behavior of this reading by switching input token sources.withScope(Reading.Initializer init) Returns a reading that matches the same syntax as this reading, but performs semantic interpretation in a local scope.Returns a reading that matches the syntax of this reading with a prefix and suffix, with the same semantic interpretation.Returns a reading that matches the syntax of this reading with a prefix and suffix, with the same semantic interpretation.Methods inherited from class eu.bandm.tools.ramus.ogma.AbstractExpression
assign, assign, getProjection, getSemantics, getSyntax
-
Method Details
-
getFactory
Returns the factory that has created this reading.- Returns:
- the factory that has created this reading
-
toString
-
cast
Returns a reference to the given reading that specifies a widened result type.- Type Parameters:
D- the type of document identifiersT- the type of token typesA- the type of parsing results- Parameters:
reading- the reading to cast- Returns:
- a reference to
readingwith result typeA - Throws:
NullPointerException- ifreading is null
-
content
@Deprecated(forRemoval=false, since="1.0") @SafeVarargs public static <D,T> Reading<D,T, contentToken<D, T>> (T... types) Deprecated.UseReadingFactory.token(Object[])instead.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
-
content
@Deprecated(forRemoval=false, since="1.0") public static <D,T> Reading<D,T, contentToken<D, T>> (Collection<? extends T> types) Deprecated.UseReadingFactory.token(Collection)instead.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- 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
@Deprecated(forRemoval=false, since="1.0") @SafeVarargs public static <D,T> Reading<D,T, typeT> (T... types) Deprecated.UseReadingFactory.type(Object[])instead.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
-
type
@Deprecated(forRemoval=false, since="1.0") public static <D,T> Reading<D,T, typeT> (Collection<? extends T> types) Deprecated.UseReadingFactory.type(Collection)instead.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
-
text
@Deprecated(forRemoval=false, since="1.0") @SafeVarargs public static <D,T> Reading<D,T, textString> (T... types) Deprecated.UseReadingFactory.text(Object[])instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T> Reading<D,T, textString> (Collection<? extends T> types) Deprecated.UseReadingFactory.text(Object[])instead.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
-
map
Returns a reading that matches the same syntax as this reading, and applies a function to the result of semantic interpretation.- Type Parameters:
B- the transformed type of parsing results- Parameters:
fun- the function to transform the results with- Returns:
- a reading that matches the same syntax as
this, and appliesfunto the result - Throws:
NullPointerException- iffunis null
-
prepend
Returns a reading that matches the syntax of this reading with a prefix, with the same semantic interpretation. The prefix must be present, but does not contribute to interpretation.- Parameters:
prefix- the parser that specifies the prefix- Returns:
- a reading that matches the syntax of
thiswithprefixprepended - Throws:
NullPointerException- ifprefixis null
-
append
Returns a reading that matches the syntax of this reading with a suffix, with the same semantic interpretation. The suffix must be present, but does not contribute to interpretation.- Parameters:
suffix- the parser that specifies the suffix- Returns:
- a reading that matches the syntax of
thiswithsuffixappended - Throws:
NullPointerException- ifsuffixis null
-
prepend
Returns a reading that matches the syntax of this reading with a prefix, with the same semantic interpretation. The prefix is specified by zero or more token types, which are to be matched sequentially. The prefix must be present, but does not contribute to interpretation.Specifying zero token types has no effect.
- Parameters:
prefix- the token types that specify the prefix- Returns:
- a reading that matches the syntax of
thiswith a sequence of tokens of typesprefixprepended - Throws:
NullPointerException- ifprefixis or contains null
-
append
Returns a reading that matches the syntax of this reading with a suffix, with the same semantic interpretation. The suffix is specified by zero or more token types, which are to be matched sequentially. The suffix must be present, but does not contribute to interpretation.Specifying zero token types has no effect.
- Parameters:
suffix- the token types that specify the suffix- Returns:
- a reading that matches the syntax of
thiswith a sequence of tokens of typessuffixappended - Throws:
NullPointerException- ifsuffixis or contains null
-
wrap
Returns a reading that matches the syntax of this reading with a prefix and suffix, with the same semantic interpretation. The prefix and suffix must be present, but do not contribute to interpretation.This operation is equivalent to, but may be more convenient than, a combination of
prepend(Parser)andappend(Parser).- Parameters:
prefix- the parser that specifies the prefixsuffix- the parser that specifies the suffix- Returns:
- a reading that matches the syntax of
thiswithprefixprepended andsuffixappended - Throws:
NullPointerException- ifprefixorsuffixis null
-
wrap
Returns a reading that matches the syntax of this reading with a prefix and suffix, with the same semantic interpretation. The prefix and suffix are specified by a single token type each. The prefix and suffix must be present, but do not contribute to interpretation.This operation is equivalent to, but may be more convenient than, a combination of
prepend(Object[])andappend(Object[]).- Parameters:
prefix- the parser that specifies the prefixsuffix- the parser that specifies the suffix- Returns:
- a reading that matches the syntax of
thiswith a token of typeprefixprepended and a token of typesuffixappended - Throws:
NullPointerException- ifprefixorsuffixis null
-
orElse
Returns a reading that matches the syntax of this reading with the same interpretation, or otherwise matches no input with the given default result value.- Parameters:
defaultValue- the default result value for the alternative that matches no inputpragmas- the pragmas to apply- Returns:
- a reading that matches the syntax of
thiswith the same result, or otherwise no input with the resultdefaultValue
-
orElseGet
Returns a reading that matches the syntax of this reading with the same interpretation, or otherwise matches no input with the given default result value.- Parameters:
defaultValue- a supplier that can provide the default result value for the alternative that matches no inputpragmas- the pragmas to apply- Returns:
- a reading that matches the syntax of
thiswith the same result, or otherwise no input with the resultdefaultValue.get() - Throws:
NullPointerException- ifdefaultValueis null
-
optionalOrElse
Returns a reading that matches the syntax of this reading with optional interpretation, or otherwise match a single token.This method supports the following pragmas:
Greedy– always perform the behavior of the parser if the next token is of an acceptable type. Note that the empty alternative is discarded in this case; use only if the grammar context is such that no possible solution is lost.Productive– throw an exception if the parser may succeed without consuming a token; thus creating an ambiguity that cannot be resolved by syntax.
- Parameters:
defaultType- the type of tokens to match alternativelypragmas- the pragmas to apply- Returns:
- a reading that wraps successful interpretations of this reading in
Optional.of(), or otherwise consumes a single token of typedefaultTypeand has the resultOptional.empty() - See Also:
-
optionalOrElse
public final Reading<D,T, optionalOrElseOptional<A>> (Parser<D, T> defaultSyntax, Parser.Pragma... pragmas) Returns a reading that matches the syntax of this reading with optional interpretation, or otherwise match some alternative syntax.This method supports the following pragmas:
Greedy– always perform the behavior of the parser if the next token is of an acceptable type. Note that the empty alternative is discarded in this case; use only if the grammar context is such that no possible solution is lost.Productive– throw an exception if the parser may succeed without consuming a token; thus creating an ambiguity that cannot be resolved by syntax.
- Parameters:
defaultSyntax- the type of tokens to match alternativelypragmas- the pragmas to apply- Returns:
- a reading that wraps successful interpretations of this reading in
Optional.of(), or otherwise consumes input as specified bydefaultSyntaxand has the resultOptional.empty() - See Also:
-
optional
Returns a reading that matches the syntax of this reading with optional interpretation, or otherwise matches no input.This method supports the following pragmas:
Greedy– always perform the behavior of the parser if the next token is of an acceptable type. Note that the empty alternative is discarded in this case; use only if the grammar context is such that no possible solution is lost.Productive– throw an exception if the parser may succeed without consuming a token; thus creating an ambiguity that cannot be resolved by syntax.
Whether input has been matched or not is reflected in the
Optionalinterpretation result.- Parameters:
pragmas- the pragmas to apply- Returns:
- a reading that wraps successful interpretations of this reading in
Optional.of(), or otherwise consumes no input and has the resultOptional.empty() - See Also:
-
star
Returns a reading that matches zero or more repetitions of this reading.The interpretation results are collected in a
List.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.
- Parameters:
pragmas- the pragmas to apply- Returns:
- a reading that behaves equivalently to zero or more repetitions of this reading, and collects the respective results
-
star
Returns a reading that matches zero or more repetitions of this reading with intervening separator syntax.The interpretation results are collected in a
List. Separators are not interpreted.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.
- Parameters:
sep- the parser that specifies the separator syntaxpragmas- the pragmas to apply- Returns:
- a reading that behaves equivalently to zero or more repetitions of
this reading separated by matches of
sep, and collects the respective results - Throws:
NullPointerException- ifsepis null
-
star
Returns a reading that matches zero or more repetitions of this reading with intervening simple separator syntax.The interpretation results are collected in a
List. Separators must be single tokens of a fixed type, and are not interpreted.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.
- Parameters:
sep- the token type of separatorspragmas- the pragmas to apply- Returns:
- a reading that behaves equivalently to zero or more repetitions of
this reading separated by matches of
sep, and collects the respective results - Throws:
NullPointerException- ifsepis null
-
plus
Returns a reading that matches one or more repetitions of this reading.The interpretation results are collected in a non-empty
List.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.
- Parameters:
pragmas- the pragmas to apply- Returns:
- a reading that behaves equivalently to one or more repetitions of this reading, and collects the respective results
-
plus
Returns a reading that matches one or more repetitions of this reading with intervening separator syntax.The interpretation results are collected in a non-empty
List. Separators are not interpreted.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.
- Parameters:
sep- the parser that specifies the separator syntaxpragmas- the pragmas to apply- Returns:
- a reading that behaves equivalently to one or more repetitions of
this reading separated by matches of
sep, and collects the respective results - Throws:
NullPointerException- ifsepis null
-
plus
Returns a reading that matches one or more repetitions of this reading with intervening simple separator syntax.The interpretation results are collected in a non-empty
List. Separators must be single tokens of a fixed type, and are not interpreted.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.
- Parameters:
sep- the token type of separatorspragmas- the pragmas to apply- Returns:
- a reading that behaves equivalently to one or more repetitions of
this reading separated by matches of
sep, and collects the respective results - Throws:
NullPointerException- ifsepis null
-
constant
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, constantA> (Parser<D, T> syntax, A value) Deprecated.UseReadingFactory.constant(Parser, Object)instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, constantA> (T type, A value) Deprecated.UseReadingFactory.constant(Object, Object)instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, constantA> (T type, String text, A value) Deprecated.UseReadingFactory.constant(Object, String, Object)instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, constantEpsilonA> (A value) Deprecated.UseReadingFactory.constantEpsilon(Object)instead.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
@Deprecated(forRemoval=false, since="1.0") @SafeVarargs public static <D,T, Reading<D,A> T, choiceA> (Reading<D, T, ? extends A>... alts) Deprecated.UseReadingFactory.choice(Reading[])instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, choiceA> (List<? extends Reading<D, T, ? extends A>> alts) Deprecated.UseReadingFactory.choice(List)instead.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
-
orElse
Returns a reading that matches alternatively the syntax of this or another reading, with the respective interpretation result.This method supports the following pragmas:
Productive– throw an exception if both alternatives may succeed without consuming a token; thus creating an ambiguity that cannot be resolved by syntax.Disjoint– return a result only if the choice between the two alternatives can be made deterministically by lookahead; throw an exception otherwise.
- Parameters:
other- the other reading to attemptpragmas- the pragmas to apply- Returns:
- a reading that behaves as the alternative choice between
thisandother - Throws:
NullPointerException- ifotheris null
-
lookup
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, lookupA> (Class<A> type, Map<T, ? extends A> model) Deprecated.UseReadingFactory.lookup(Class, Map)instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, lookupA> (Map<T, ? extends A> model) Deprecated.UseReadingFactory.lookup(Class, Map)instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, lookaheadA> (Map<T, Reading<D, T, ? extends A>> map, Parser.Pragma... pragmas) Deprecated.UseReadingFactory.lookahead(Map, Parser.Pragma[])instead.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
-
andThenCombining
public final <B,C> Reading<D,T, andThenCombiningC> (Reading<D, T, B> other, BiFunction<? super A, ? super B, ? extends C> pair) Returns a reading that matches the syntax of this reading followed by that of another, combining the semantic interpretations with a function.- Type Parameters:
B- the type of parsing results of the other readingC- the type of parsing results of the combined reading- Parameters:
other- the other reading to appendpair- the pairing function to apply to results- Returns:
- a reading that matches the syntax of
thisfollowed by that ofother, combining the semantic interpretations by applyingpair - Throws:
NullPointerException- ifotherorpairis null
-
mapsTo
Returns a reading that matches the syntax of this reading followed by that of another, combining the semantic interpretations as a map entry.- Type Parameters:
B- the type of parsing results of the other reading- Parameters:
other- the other reading to append- Returns:
- a reading that matches the syntax of
thisfollowed by that ofother, combining the semantic interpretations as a map entry - Throws:
NullPointerException- ifotheris null
-
andThenDependent
public final <B> Reading<D,T, andThenDependentB> (Reading<D, T, Function<? super A, ? extends B>> other) Returns a reading that matches the syntax of this reading followed by that of another, combining the semantic interpretations.The other reading must yield a result that is a function, to be applied to the result of this reading.
- Type Parameters:
B- the type of parsing results of the combined reading- Parameters:
other- the other reading to append- Returns:
- a reading that matches the syntax of
thisfollowed by that ofother, combining the semantic interpretations by applying the latter result to the former - Throws:
NullPointerException- ifotheris null
-
fix
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, fixA> (Function<Reading<D, T, A>, Reading<D, T, A>> loop) Deprecated.UseReadingFactory.fix(Function)instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T> Reading<D,T, unitUnit> (Parser<D, T> syntax) Deprecated.UseReadingFactory.unit(Parser)instead.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
@Deprecated(forRemoval=false, since="1.0") @SafeVarargs public static <D,T> Reading<D,T, unitUnit> (T... types) Deprecated.UseReadingFactory.unit(Object[])instead.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
-
ifThenElse
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, ifThenElseA> (T type, Reading<D, T, ? extends A> thenBranch, Reading<D, T, ? extends A> elseBranch) Deprecated.UseReadingFactory.ifThenElse(Object, Reading, Reading)instead.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, accessA> (Reading.Key<A> key) Deprecated.UseReadingFactory.access(Key)instead.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
-
assigning
Returns a reading that assigns the interpretation result of this reading to the given key.No input is consumed.
- Parameters:
key- the key- Returns:
- a reading that behaves equivalently to this reading, and then
assigns the interpretation result to
key - Throws:
NullPointerException- ifkeyis null
-
withScope
Returns a reading that matches the same syntax as this reading, but performs semantic interpretation in a local scope.All assignments to keys performed by this reading are undone afterwards.
- Parameters:
init- a map of initial local values for some keys- Returns:
- a reading that behaves equivalently to this reading, but performs semantic interpretation in a local scope that is then popped
- Throws:
NullPointerException- ifinitis null- See Also:
-
guard
public final Reading<D,T, guardA> (Predicate<? super A> condition, Function<? super A, List<SimpleMessage<D>>> error) Returns a reading that extends the behavior of this reading with a mandatory check and conditional error diagnostics.- Parameters:
condition- the condition to check on the interpretation resulterror- a function to provide diagnostics for the result if the condition fails- Returns:
- a reading that behaves equivalently to this reading, but then only
succeeds if
conditionreturnstruefor the result value; otherwise diagnostics created by applyingerrorto the value are attached, and the parsing attempt is rejected - Throws:
NullPointerException- ifconditionorerroris null
-
diagnose
-
process
Parses the given input with this reading and returns a complete summary of interpretations.- Parameters:
input- the input to parse- Returns:
- a complete summary of interpretations
- Throws:
NullPointerException- ifinputis null- See Also:
-
process
Parses the given input with this reading and returns a complete summary of interpretations.- Parameters:
input- the input to parse- Returns:
- a complete summary of interpretations
- Throws:
NullPointerException- ifinputis null
-
leftAssoc
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, leftAssocA> (ReadingFactory.OperatorTemplate<D, T, A> template) Deprecated.UseReadingFactory.leftAssoc(OperatorTemplate)instead.Tactic for left-associative operators.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 operand template to apply- Returns:
- a reading that uses
templateleft-associatively - See Also:
-
rightAssoc
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, rightAssocA> (ReadingFactory.OperatorTemplate<D, T, A> template) Deprecated.UseReadingFactory.rightAssoc(OperatorTemplate)instead.Tactic for right-associative operators.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
@Deprecated(forRemoval=false, since="1.0") public static <D,T, Reading<D,A> T, nonAssocA> (ReadingFactory.OperatorTemplate<D, T, A> template) Deprecated.UseReadingFactory.nonAssoc(OperatorTemplate)instead.Tactic for non-associative operators.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 - See Also:
-
withOtherTokenSource
public final <K> Reading<D,T, withOtherTokenSourceA> (LookaheadTokenMultiplexer<K, D, T, ?> multi, K newKey) Extends the behavior of this reading by switching input token sources.Note that token source switching is only supported in situations where no lookahead tokens have been acquired.
IllegalStateExceptionwill be thrown if lookahead tokens are present when the switch is performed.- Type Parameters:
K- the type of token multiplexer keys- Parameters:
multi- the token multiplexer to use for switchingnewKey- the key to switch the token source to during parsing with the extended parser- Returns:
- a reading that behaves equivalently to this reading, but switches
to the token source associated with
newKeybefore parsing, and switches back afterwards, on both success and failure - Throws:
NullPointerException- ifmultiornewKeyis null
-
closeAndTerminate
-
closeAndRepeat
-
ReadingFactory.access(Key)instead.