T
- the type of the object created by successful application of the
Parser
to a piece of textpublic interface AbstractParser<T> extends Parser<T>
Parser
with sensible default behavior
provided for a large number of methods.MATCHING_ALL
Modifier and Type | Method and Description |
---|---|
default <U,V> Parser<V> |
appendTransform(Parser<U> parser,
java.util.function.BiFunction<T,U,? extends V> incorporate)
Derive a new
Parser instance from the receiving instance. |
default <U> Parser<U> |
appendTransform(java.lang.String pattern,
java.util.function.BiFunction<T,java.lang.String,? extends U> incorporate)
Derive a new
Parser instance from the receiving instance. |
default Parser<T> |
orElse(Parser<? extends T> onFailure)
Derive a new
Parser instance from the receiving instance. |
default Parser<T> |
orElse(java.util.function.Supplier<? extends T> onFailure)
Derive a new
Parser instance from the receiving instance. |
default T |
parse(java.lang.String literal)
Parse the given literal according to this parser.
|
default ParseResult<T> |
parseSubstring(ParseState currentState)
Parse the substring at the given parse state according to this parser.
|
ParseResult<T> |
parseSubstringImpl(ParseState currentState) |
default <U,V> Parser<V> |
prependTransform(Parser<U> parser,
java.util.function.BiFunction<T,U,? extends V> incorporate)
Derive a new
Parser instance from the receiving instance. |
default <U> Parser<U> |
prependTransform(java.lang.String pattern,
java.util.function.BiFunction<T,java.lang.String,? extends U> incorporate)
Derive a new
Parser instance from the receiving instance. |
default <W> Parser<W> |
transform(java.util.function.Function<? super T,? extends W> transform)
Derive a new
Parser instance from the receiving instance. |
default <U> Parser<T> |
tryAppendTransform(Parser<U> parser,
java.util.function.BiFunction<T,U,? extends T> incorporate)
Derive a new
Parser instance from the receiving instance. |
default <U> Parser<T> |
tryPrependTransform(Parser<U> parser,
java.util.function.BiFunction<T,U,? extends T> incorporate)
Derive a new
Parser instance from the receiving instance. |
default <W> Parser<W> transform(java.util.function.Function<? super T,? extends W> transform)
Parser
Parser
instance from the receiving instance.
The new parser will match the same text as the given parser, but the object
parsed will be transformed by the given Function
.
transform
in interface Parser<T>
W
- the type of the object of the new parser, post-transformationtransform
- the transformation to apply to the object given by application of
this parserParser
instance which applies the given
transformationdefault Parser<T> orElse(java.util.function.Supplier<? extends T> onFailure)
Parser
Parser
instance from the receiving instance.
The new parser will attempt to match a piece of text in the same manner as the receiving parser. If the attempt fails, the text matched, or partially matched, by the original attempt will remain unconsumed, and the parser will instead return a value from the given supplier.
default Parser<T> orElse(Parser<? extends T> onFailure)
Parser
Parser
instance from the receiving instance.
The new parser will attempt to match a piece of text in the same manner as the receiving parser. If the attempt fails, the text matched, or partially matched, by the original attempt will remain unconsumed, then an attempt will be made to instead apply the given parser.
default <U> Parser<U> appendTransform(java.lang.String pattern, java.util.function.BiFunction<T,java.lang.String,? extends U> incorporate)
Parser
Parser
instance from the receiving instance.
The new parser will first match the start of the text according to the receiving parser, then match the start of any subsequent text according to the given pattern.
Upon success, the text matched by the appended pattern will be transformed, along with the result of applying the receiving parser, into a new result according to the given function.
appendTransform
in interface Parser<T>
U
- The type of the new parse resultpattern
- A pattern matching the text which should immediately follow from
the text matched by this parserincorporate
- A function taking the result of parsing the receiving parser and
the appended text, and transforming them into a new parse resultParser
instance which also matches against the
appended text patterndefault <U> Parser<U> prependTransform(java.lang.String pattern, java.util.function.BiFunction<T,java.lang.String,? extends U> incorporate)
Parser
Parser
instance from the receiving instance.
The new parser will first match the start of the text according to the given pattern, then match the start of any subsequent text according to the receiving parser.
Upon success, the text matched by the appended pattern will be transformed, along with the result of applying the receiving parser, into a new result according to the given function.
prependTransform
in interface Parser<T>
U
- The type of the new parse resultpattern
- A pattern matching the text which should immediately precede the
text matched by this parserincorporate
- A function taking the result of parsing the receiving parser and
the prepending text, and transforming them into a new parse resultParser
instance which also matches against the
prepended text patterndefault <U,V> Parser<V> appendTransform(Parser<U> parser, java.util.function.BiFunction<T,U,? extends V> incorporate)
Parser
Parser
instance from the receiving instance.
The new parser will first match the start of the text according to the receiving parser, then match the start of any subsequent text according to the given parser.
Upon success, the result of applying the appended parser will be transformed, along with the result of applying the receiving parser, into a new result according to the given function.
appendTransform
in interface Parser<T>
U
- The type of the parse result of the appended parserV
- The type of the new parse resultparser
- A parser matching the text immediately following from the text
matched by this parserincorporate
- A function taking the result of parsing the receiving parser and
the result of parsing the appended parser, and transforming them
into a new parse resultParser
instance which also matches against the
appended parserdefault <U,V> Parser<V> prependTransform(Parser<U> parser, java.util.function.BiFunction<T,U,? extends V> incorporate)
Parser
Parser
instance from the receiving instance.
The new parser will first match the start of the text according to the given parser, then match the start of any subsequent text according to the receiving parser.
Upon success, the result of applying the prepended parser will be transformed, along with the result of applying the receiving parser, into a new result according to the given function.
prependTransform
in interface Parser<T>
U
- The type of the parse result of the appended parserV
- The type of the new parse resultparser
- A parser matching the text immediately preceding the text matched
by this parserincorporate
- A function taking the result of parsing the receiving parser and
the result of parsing the appended parser, and transforming them
into a new parse resultParser
instance which also matches against the
appended parserdefault <U> Parser<T> tryAppendTransform(Parser<U> parser, java.util.function.BiFunction<T,U,? extends T> incorporate)
Parser
Parser
instance from the receiving instance.
The new parser will first match the start of the text according to the receiving parser, then attempt to match the start of any subsequent text according to the given parser. If the second step - of matching the remaining text with the given parser - fails, then the result of applying the receiving parser alone will be returned.
If application of the appended parser also succeeds, the result of applying the appended parser will be transformed, along with the result of applying the receiving parser, into a new result according to the given function.
tryAppendTransform
in interface Parser<T>
U
- The type of the parse result of the appended parserparser
- A parser matching the text immediately following from the text
matched by this parserincorporate
- A function taking the result of parsing the receiving parser and
the result of parsing the appended parser, and transforming them
into a new parse resultParser
instance which also matches against the
appended parserdefault <U> Parser<T> tryPrependTransform(Parser<U> parser, java.util.function.BiFunction<T,U,? extends T> incorporate)
Parser
Parser
instance from the receiving instance.
The new parser will first match the start of the text according to the given parser, then attempt to match the start of any subsequent text according to the receiving parser. If the first step - of matching the remaining text with the given parser - fails, then the result of applying the receiving parser alone will be returned.
If application of the prepended parser also succeeds, the result of applying the prepended parser will be transformed, along with the result of applying the receiving parser, into a new result according to the given function.
tryPrependTransform
in interface Parser<T>
U
- The type of the parse result of the appended parserparser
- A parser matching the text immediately following from the text
matched by this parserincorporate
- A function taking the result of parsing the receiving parser and
the result of parsing the appended parser, and transforming them
into a new parse resultParser
instance which also matches against the
appended parserdefault T parse(java.lang.String literal)
Parser
default ParseResult<T> parseSubstring(ParseState currentState)
Parser
parseSubstring
in interface Parser<T>
currentState
- the current parse state over a string literalParseResult<T> parseSubstringImpl(ParseState currentState)