|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.jparsec.Parsers
public final class Parsers
Provides common Parser
implementations.
Field Summary | |
---|---|
static Parser<Object> |
ANY_TOKEN
A Parser that consumes a token. |
static Parser<?> |
EOF
Parser that succeeds only if EOF is met. |
static Parser<Integer> |
INDEX
A Parser that retrieves the current index in the source. |
Method Summary | ||
---|---|---|
static
|
always()
Parser that always succeeds. |
|
static Parser<Object[]> |
array(Parser<?>... parsers)
A Parser that sequentially runs parsers one by one and collects the return
values in an array. |
|
static
|
between(Parser<?> before,
Parser<T> parser,
Parser<?> after)
Equivalent to Parser.between(Parser, Parser) . |
|
static
|
constant(T v)
A Parser that always returns v regardless of input. |
|
static
|
expect(String name)
A Parser that fails and reports that name is logically expected. |
|
static
|
fail(String message)
A Parser that always fails with message . |
|
static
|
list(Iterable<? extends Parser<? extends T>> parsers)
A Parser that sequentially runs parsers one by one and collects the return
values in a List . |
|
static
|
longer(Parser<? extends T> p1,
Parser<? extends T> p2)
A Parser that runs both p1 and p2 and selects the longer match. |
|
static
|
longest(Iterable<? extends Parser<? extends T>> parsers)
A Parser that runs every element of parsers and selects the longest match. |
|
static
|
longest(Parser<? extends T>... parsers)
A Parser that runs every element of parsers and selects the longest match. |
|
static
|
never()
Parser that always fails. |
|
static
|
or(Iterable<? extends Parser<? extends T>> alternatives)
A Parser that tries each alternative parser in alternatives . |
|
static
|
or(Parser<? extends T>... alternatives)
A Parser that tries each alternative parser in alternatives . |
|
static
|
or(Parser<? extends T> p1,
Parser<? extends T> p2)
A Parser that tries 2 alternative parser objects. |
|
static
|
or(Parser<? extends T> p1,
Parser<? extends T> p2,
Parser<? extends T> p3)
A Parser that tries 3 alternative parser objects. |
|
static
|
or(Parser<? extends T> p1,
Parser<? extends T> p2,
Parser<? extends T> p3,
Parser<? extends T> p4)
A Parser that tries 4 alternative parser objects. |
|
static
|
or(Parser<? extends T> p1,
Parser<? extends T> p2,
Parser<? extends T> p3,
Parser<? extends T> p4,
Parser<? extends T> p5)
A Parser that tries 5 alternative parser objects. |
|
static
|
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)
A Parser that tries 6 alternative parser objects. |
|
static
|
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)
A Parser that tries 7 alternative parser objects. |
|
static
|
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)
A Parser that tries 8 alternative parser objects. |
|
static
|
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)
A Parser that tries 9 alternative parser objects. |
|
static
|
pair(Parser<? extends A> p1,
Parser<? extends B> p2)
A Parser that sequentially runs p1 and p2 and collects the results in a
Pair object. |
|
static Parser<?> |
runnable(Runnable runnable)
Deprecated. |
|
static Parser<Object> |
sequence(Iterable<? extends Parser<?>> parsers)
A Parser that runs parsers sequentially and discards the return values. |
|
static Parser<Object> |
sequence(Parser<?>... parsers)
A Parser that runs parsers sequentially and discards the return values. |
|
static
|
sequence(Parser<?> p1,
Parser<?> p2,
Parser<?> p3,
Parser<?> p4,
Parser<T> p5)
A Parser that runs 5 parser objects sequentially. |
|
static
|
sequence(Parser<?> p1,
Parser<?> p2,
Parser<?> p3,
Parser<T> p4)
A Parser that runs 4 parser objects sequentially. |
|
static
|
sequence(Parser<?> p1,
Parser<?> p2,
Parser<T> p3)
A Parser that runs 3 parser objects sequentially. |
|
static
|
sequence(Parser<?> p1,
Parser<T> p2)
A Parser that runs 2 parser objects sequentially. |
|
static
|
sequence(Parser<A> p1,
Parser<B> p2,
Map2<? super A,? super B,? extends T> map)
A Parser that runs p1 and p2 sequentially
and transforms the return values using map . |
|
static
|
sequence(Parser<A> p1,
Parser<B> p2,
Parser<C> p3,
Map3<? super A,? super B,? super C,? extends T> map)
A Parser that runs 3 parser objects sequentially and transforms the return values
using map . |
|
static
|
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)
A Parser that runs 4 parser objects sequentially and transforms the return values
using map . |
|
static
|
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)
A Parser that runs 5 parser objects sequentially and transforms the return values
using map . |
|
static
|
shorter(Parser<? extends T> p1,
Parser<? extends T> p2)
A Parser that runs both p1 and p2 and selects the shorter match. |
|
static
|
shortest(Iterable<? extends Parser<? extends T>> parsers)
A Parser that runs every element of parsers and selects the shortest match. |
|
static
|
shortest(Parser<? extends T>... parsers)
A Parser that runs every element of parsers and selects the shortest match. |
|
static
|
token(TokenMap<? extends T> fromToken)
Checks the current token with the fromToken object. |
|
static
|
tokenType(Class<? extends T> type,
String name)
Checks whether the current token value is of type , in which case, the token value is
returned and parse succeeds. |
|
static
|
tuple(Parser<? extends A> p1,
Parser<? extends B> p2)
A Parser that sequentially runs p1 and p2 and collects the results in a
Pair object. |
|
static
|
tuple(Parser<? extends A> p1,
Parser<? extends B> p2,
Parser<? extends C> p3)
A Parser that sequentially runs 3 parser objects and collects the results in a
Tuple3 object. |
|
static
|
tuple(Parser<? extends A> p1,
Parser<? extends B> p2,
Parser<? extends C> p3,
Parser<? extends D> p4)
A Parser that sequentially runs 4 parser objects and collects the results in a
Tuple4 object. |
|
static
|
tuple(Parser<? extends A> p1,
Parser<? extends B> p2,
Parser<? extends C> p3,
Parser<? extends D> p4,
Parser<? extends E> p5)
A Parser that sequentially runs 5 parser objects and collects the results in a
Tuple5 object. |
|
static
|
unexpected(String name)
A Parser that fails and reports that name is logically unexpected. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Parser<?> EOF
Parser
that succeeds only if EOF is met. Fails otherwise.
public static final Parser<Object> ANY_TOKEN
Parser
that consumes a token. The token value is returned from the parser.
public static final Parser<Integer> INDEX
Parser
that retrieves the current index in the source.
Method Detail |
---|
public static <T> Parser<T> always()
Parser
that always succeeds.
public static <T> Parser<T> never()
Parser
that always fails.
public static <T> Parser<T> fail(String message)
Parser
that always fails with message
.
@Deprecated public static Parser<?> runnable(Runnable runnable)
Parser
that always succeeds and invokes runnable
.
public static <T> Parser<T> constant(T v)
Parser
that always returns v
regardless of input.
public static <T> Parser<T> sequence(Parser<?> p1, Parser<T> p2)
Parser
that runs 2 parser objects sequentially. p1
is executed,
if it succeeds, p2
is executed.
public static <T> Parser<T> sequence(Parser<?> p1, Parser<?> p2, Parser<T> p3)
Parser
that runs 3 parser objects sequentially.
public static <T> Parser<T> sequence(Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<T> p4)
Parser
that runs 4 parser objects sequentially.
public static <T> Parser<T> sequence(Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<T> p5)
Parser
that runs 5 parser objects sequentially.
public static <A,B> Parser<Pair<A,B>> pair(Parser<? extends A> p1, Parser<? extends B> p2)
Parser
that sequentially runs p1
and p2
and collects the results in a
Pair
object. Is equivalent to tuple(Parser, Parser)
.
public static <A,B> Parser<Pair<A,B>> tuple(Parser<? extends A> p1, Parser<? extends B> p2)
Parser
that sequentially runs p1
and p2
and collects the results in a
Pair
object. Is equivalent to pair(Parser, Parser)
.
public static <A,B,C> Parser<Tuple3<A,B,C>> tuple(Parser<? extends A> p1, Parser<? extends B> p2, Parser<? extends C> p3)
Parser
that sequentially runs 3 parser objects and collects the results in a
Tuple3
object.
public static <A,B,C,D> Parser<Tuple4<A,B,C,D>> tuple(Parser<? extends A> p1, Parser<? extends B> p2, Parser<? extends C> p3, Parser<? extends D> p4)
Parser
that sequentially runs 4 parser objects and collects the results in a
Tuple4
object.
public static <A,B,C,D,E> Parser<Tuple5<A,B,C,D,E>> tuple(Parser<? extends A> p1, Parser<? extends B> p2, Parser<? extends C> p3, Parser<? extends D> p4, Parser<? extends E> p5)
Parser
that sequentially runs 5 parser objects and collects the results in a
Tuple5
object.
public static Parser<Object[]> array(Parser<?>... parsers)
Parser
that sequentially runs parsers
one by one and collects the return
values in an array.
public static <T> Parser<List<T>> list(Iterable<? extends Parser<? extends T>> parsers)
Parser
that sequentially runs parsers
one by one and collects the return
values in a List
.
public static <T> Parser<T> between(Parser<?> before, Parser<T> parser, Parser<?> after)
Parser.between(Parser, Parser)
. Use this to list the parsers in the
natural order.
public static <A,B,T> Parser<T> sequence(Parser<A> p1, Parser<B> p2, Map2<? super A,? super B,? extends T> map)
Parser
that runs p1
and p2
sequentially
and transforms the return values using map
.
public 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)
Parser
that runs 3 parser objects sequentially and transforms the return values
using map
.
public 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)
Parser
that runs 4 parser objects sequentially and transforms the return values
using map
.
public 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)
Parser
that runs 5 parser objects sequentially and transforms the return values
using map
.
public static Parser<Object> sequence(Parser<?>... parsers)
Parser
that runs parsers
sequentially and discards the return values.
public static Parser<Object> sequence(Iterable<? extends Parser<?>> parsers)
Parser
that runs parsers
sequentially and discards the return values.
public static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2)
Parser
that tries 2 alternative parser objects.
Fallback happens regardless of partial match.
public static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3)
Parser
that tries 3 alternative parser objects.
Fallback happens regardless of partial match.
public static <T> Parser<T> or(Parser<? extends T> p1, Parser<? extends T> p2, Parser<? extends T> p3, Parser<? extends T> p4)
Parser
that tries 4 alternative parser objects.
Fallback happens regardless of partial match.
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
that tries 5 alternative parser objects.
Fallback happens regardless of partial match.
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
that tries 6 alternative parser objects.
Fallback happens regardless of partial match.
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
that tries 7 alternative parser objects.
Fallback happens regardless of partial match.
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
that tries 8 alternative parser objects.
Fallback happens regardless of partial match.
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)
Parser
that tries 9 alternative parser objects.
Fallback happens regardless of partial match.
public static <T> Parser<T> or(Parser<? extends T>... alternatives)
Parser
that tries each alternative parser in alternatives
.
Different than alt(Parser[])
, it requires all alternative parsers to have
type T
.
public static <T> Parser<T> or(Iterable<? extends Parser<? extends T>> alternatives)
Parser
that tries each alternative parser in alternatives
.
public static <T> Parser<T> longer(Parser<? extends T> p1, Parser<? extends T> p2)
Parser
that runs both p1
and p2
and selects the longer match.
If both matches the same length, the first one is favored.
public static <T> Parser<T> longest(Parser<? extends T>... parsers)
Parser
that runs every element of parsers
and selects the longest match.
If two matches have the same length, the first one is favored.
public static <T> Parser<T> longest(Iterable<? extends Parser<? extends T>> parsers)
Parser
that runs every element of parsers
and selects the longest match.
If two matches have the same length, the first one is favored.
public static <T> Parser<T> shorter(Parser<? extends T> p1, Parser<? extends T> p2)
Parser
that runs both p1
and p2
and selects the shorter match.
If both matches the same length, the first one is favored.
public static <T> Parser<T> shortest(Parser<? extends T>... parsers)
Parser
that runs every element of parsers
and selects the shortest match.
If two matches have the same length, the first one is favored.
public static <T> Parser<T> shortest(Iterable<? extends Parser<? extends T>> parsers)
Parser
that runs every element of parsers
and selects the shortest match.
If two matches have the same length, the first one is favored.
public static <T> Parser<T> expect(String name)
Parser
that fails and reports that name
is logically expected.
public static <T> Parser<T> unexpected(String name)
Parser
that fails and reports that name
is logically unexpected.
public static <T> Parser<T> token(TokenMap<? extends T> fromToken)
fromToken
object. If the
TokenMap.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.
fromToken
- the FromToken
object.
public static <T> Parser<T> tokenType(Class<? extends T> type, String name)
type
, in which case, the token value is
returned and parse succeeds.
type
- the expected token value type.name
- the name of what's logically expected.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |