Class Parsers
java.lang.Object
org.jparsec.Parsers
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAllows the overloads of "or()" to call the varargs version of "or" with no ambiguity.static <T> Parser<T> always()Parserthat always succeeds.AParserthat sequentially runsparsersone by one and collects the return values in an array.static <T> Parser<T> Equivalent toParser.between(Parser, Parser).static <T> Parser<T> constant(T v) AParserthat always returnsvregardless of input.(package private) static Parser<?> AParserthat succeeds only if EOF is met.static <T> Parser<T> AParserthat fails and reports thatnameis logically expected.static <T> Parser<T> AParserthat always fails withmessage.static <T> Parser<T> static <T> Parser<T> AParserthat runs every element ofparsersand selects the longest match.static <T> Parser<T> AParserthat runs every element ofparsersand selects the longest match.(package private) static <T> Parser<T> static <T> Parser<T> never()Parserthat always fails.static <T> Parser<T> AParserthat tries each alternative parser inalternatives.static <T> Parser<T> AParserthat tries each alternative parser inalternatives.static <T> Parser<T> AParserthat tries 2 alternative parser objects.static <T> Parser<T> AParserthat tries 3 alternative parser objects.static <T> Parser<T> AParserthat tries 4 alternative parser objects.static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4, Parser<? extends T> p5) AParserthat tries 5 alternative parser objects.static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4, Parser<? extends T> p5, Parser<? extends T> p6) AParserthat tries 6 alternative parser objects.static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4, Parser<? extends T> p5, Parser<? extends T> p6, Parser<? extends T> p7) AParserthat tries 7 alternative parser objects.static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4, Parser<? extends T> p5, Parser<? extends T> p6, Parser<? extends T> p7, Parser<? extends T> p8) AParserthat tries 8 alternative parser objects.static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4, Parser<? extends T> p5, Parser<? extends T> p6, Parser<? extends T> p7, Parser<? extends T> p8, Parser<? extends T> p9) AParserthat tries 9 alternative parser objects.Deprecated.Prefer to converting to your own object with a lambda.static Parser<?> Deprecated.AParserthat runsparserssequentially and discards the return values.AParserthat runsparserssequentially and discards the return values.static <T> Parser<T> AParserthat runs 5 parser objects sequentially.static <T> Parser<T> AParserthat runs 4 parser objects sequentially.static <T> Parser<T> AParserthat runs 3 parser objects sequentially.static <T> Parser<T> AParserthat runs 2 parser objects sequentially.static <A,B, T> Parser <T> sequence(Parser<A> p1, Parser<B> p2, BiFunction<? super A, ? super B, ? extends T> map) static <A,B, C, T> Parser <T> sequence(Parser<A> p1, Parser<B> p2, Parser<C> p3, Map3<? super A, ? super B, ? super C, ? extends T> map) AParserthat runs 3 parser objects sequentially and transforms the return values usingmap.static <A,B, C, D, T>
Parser<T> sequence(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Map4<? super A, ? super B, ? super C, ? super D, ? extends T> map) AParserthat runs 4 parser objects sequentially and transforms the return values usingmap.static <A,B, C, D, E, T>
Parser<T> sequence(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5, Map5<? super A, ? super B, ? super C, ? super D, ? super E, ? extends T> map) AParserthat runs 5 parser objects sequentially and transforms the return values usingmap.static <A,B, C, D, E, F, T>
Parser<T> sequence(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5, Parser<F> p6, Map6<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? extends T> map) AParserthat runs 6 parser objects sequentially and transforms the return values usingmap.static <A,B, C, D, E, F, G, T>
Parser<T> sequence(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5, Parser<F> p6, Parser<G> p7, Map7<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? extends T> map) AParserthat runs 7 parser objects sequentially and transforms the return values usingmap.static <A,B, C, D, E, F, G, H, T>
Parser<T> sequence(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5, Parser<F> p6, Parser<G> p7, Parser<H> p8, Map8<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H, ? extends T> map) AParserthat runs 7 parser objects sequentially and transforms the return values usingmap.static <T> Parser<T> static <T> Parser<T> AParserthat runs every element ofparsersand selects the shortest match.static <T> Parser<T> AParserthat runs every element ofparsersand selects the shortest match.(package private) static <T> Parser<T>[]We always convertIterableto an array to avoid the cost of creating a new object each time the parser runs.private static <T> Parser<T>[]toArray(Collection<? extends Parser<? extends T>> parsers) (package private) static <T> Parser<T>[]toArrayWithIteration(Iterable<? extends Parser<? extends T>> parsers) static <T> Parser<T> Checks the current token with thefromTokenobject.tokens(Parser<? extends Collection<Token>> parser) Converts a parser of a collection ofTokento a parser of an array ofToken.static <T> Parser<T> Checks whether the current token value is oftype, in which case, the token value is returned and parse succeeds.Deprecated.Prefer to converting to your own object with a lambda.Deprecated.Prefer to converting to your own object with a lambda.tuple(Parser<? extends A> p1, Parser<? extends B> p2, Parser<? extends C> p3, Parser<? extends D> p4) Deprecated.Prefer to converting to your own object with a lambda.tuple(Parser<? extends A> p1, Parser<? extends B> p2, Parser<? extends C> p3, Parser<? extends D> p4, Parser<? extends E> p5) Deprecated.Prefer to converting to your own object with a lambda.static <T> Parser<T> unexpected(String name) AParserthat fails and reports thatnameis logically unexpected.
-
Field Details
-
EOF
-
ANY_TOKEN
-
INDEX
Deprecated.UseSOURCE_LOCATIONinstead.AParserthat retrieves the current index in the source. -
SOURCE_LOCATION
AParserthat returns the current location in the source.Because
SourceLocation.getLine()andSourceLocation.getColumn()take amortizedlog(n)time, it's more efficient to avoid calling them until the entire source has been parsed successfully. In other words, avoidSOURCE_LOCATION.map(SourceLocation::getLine)or anything similar.SourceLocation#getIndexcan be called any time.- Since:
- 3.1
-
ALWAYS
-
NEVER
-
TRUE
-
FALSE
-
-
Constructor Details
-
Parsers
private Parsers()
-
-
Method Details
-
always
-
never
-
eof
-
fail
-
runnable
Deprecated.AParserthat always succeeds and invokesrunnable. -
tokens
-
nested
AParserthat takes as input the array ofTokenreturned fromlexer, and feeds the tokens as input intoparser.It fails if either
lexerorparserfails.- Parameters:
lexer- the lexer object that returns an array of Tok objects.parser- the token level parser object.- Returns:
- the new Parser object.
-
constant
-
sequence
-
sequence
-
sequence
-
sequence
-
pair
@Deprecated public static <A,B> Parser<Pair<A,B>> pair(Parser<? extends A> p1, Parser<? extends B> p2) Deprecated.Prefer to converting to your own object with a lambda.AParserthat sequentially runsp1andp2and collects the results in aPairobject. Is equivalent totuple(Parser, Parser). -
tuple
@Deprecated public static <A,B> Parser<Pair<A,B>> tuple(Parser<? extends A> p1, Parser<? extends B> p2) Deprecated.Prefer to converting to your own object with a lambda.AParserthat sequentially runsp1andp2and collects the results in aPairobject. Is equivalent topair(Parser, Parser). -
tuple
-
tuple
-
tuple
-
array
-
list
-
between
Equivalent toParser.between(Parser, Parser). Use this to list the parsers in the natural order. -
sequence
public static <A,B, Parser<T> sequenceT> (Parser<A> p1, Parser<B> p2, BiFunction<? super A, ? super B, ? extends T> map) -
sequence
-
sequence
-
sequence
-
sequence
public static <A,B, Parser<T> sequenceC, D, E, F, T> (Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5, Parser<F> p6, Map6<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? extends T> map) AParserthat runs 6 parser objects sequentially and transforms the return values usingmap.- Since:
- 3.0
-
sequence
public static <A,B, Parser<T> sequenceC, D, E, F, G, T> (Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5, Parser<F> p6, Parser<G> p7, Map7<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? extends T> map) AParserthat runs 7 parser objects sequentially and transforms the return values usingmap.- Since:
- 3.0
-
sequence
public static <A,B, Parser<T> sequenceC, D, E, F, G, H, T> (Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5, Parser<F> p6, Parser<G> p7, Parser<H> p8, Map8<? super A, ? super B, ? super C, ? super D, ? super E, ? super F, ? super G, ? super H, ? extends T> map) AParserthat runs 7 parser objects sequentially and transforms the return values usingmap.- Since:
- 3.0
-
sequence
-
sequence
-
or
-
or
-
or
-
or
-
or
-
or
-
or
public static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4, Parser<? extends T> p5, Parser<? extends T> p6, Parser<? extends T> p7, Parser<? extends T> p8) AParserthat tries 8 alternative parser objects. Fallback happens regardless of partial match. -
or
public static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4, Parser<? extends T> p5, Parser<? extends T> p6, Parser<? extends T> p7, Parser<? extends T> p8, Parser<? extends T> p9) AParserthat tries 9 alternative parser objects. Fallback happens regardless of partial match. -
or
AParserthat tries each alternative parser inalternatives.Different than
alt(Parser[]), it requires all alternative parsers to have typeT. -
or
-
alt
-
longer
-
longest
-
longest
-
shorter
-
shortest
-
shortest
-
expect
-
unexpected
-
token
Checks the current token with thefromTokenobject. If theTokenMap.map(Token)method returns null, an unexpected token error occurs; if the method returns a non-null value, the value is returned and the parser succeeds.- Parameters:
fromToken- theFromTokenobject.- Returns:
- the new Parser object.
-
tokenType
Checks whether the current token value is oftype, in which case, the token value is returned and parse succeeds.- Parameters:
type- the expected token value type.name- the name of what's logically expected.- Returns:
- the new Parser object.
-
toArrayWithIteration
-
toArray
-
toArray
-
SOURCE_LOCATIONinstead.