jfun.parsec

Class Parsers

public final class Parsers extends Object

This class provides general parser combinators that work on both character level and token level.

A parser can work on character level or token level.

A token level parser is called a "parser".

For each Parser combinator, we write the signature in a haskellish sytax.

A Parser object is safely covariant about the type parameter. Jparsec tries its best to support covariance in the API since java 5 generics has no covariance support. It is always safe to use the convert() method to explicitly force covariance whenever necessary.

A parser has a user state that can be set and retrieved. Only setState, getState, transformState combinators are user state related.

We denote a user state concerned parser as Parser u a, where u is the user state type and a is the return type.

An array of element type t, is denoted as [t].

Author: Ben Yu 2004-11-11

Method Summary
static <T> Parser<T>alt(String name, Parser<T>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds.
static <T> Parser<T>alt(Parser<T>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds.
static Parser<Tok>anyToken()
Consumes a token.
static Parser<Tok>anyToken(String name)
Consumes a token.
static <R> Parser<R>atomize(String name, Parser<R> p)
Backout input consumption if p fails.
static <R> Parser<R>between(Parser<?> open, Parser<?> close, Parser<R> p)
Runs a Parser that is between a pair of parsers.
static <R> Parser<R>between(String name, Parser<?> open, Parser<?> close, Parser<R> p)
runs a Parser that is between a pair of parsers.
static <From,To> Parser<To>bind(String name, Parser<From> p, ToParser<? super From,To> f)
First run p, if it succeeds, run ToParser f with the value returned from p.
static <T> ToParser<T,T>bindAll(ToParser<T,T>... binders)
Threads an array of ToParser into a single ToParser.
static <T> ToParser<T,T>bindAll(String name, ToParser<T,T>... binders)
Threads an array of ToParser into a single ToParser.
static Parser<_>endBy(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.
static Parser<_>endBy(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static Parser<_>endBy1(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.
static Parser<_>endBy1(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy1(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy1(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy1(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static <R> Parser<R[]>endBy1(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.
static Parser<?>eof()
Asserts eof is met.
static Parser<?>eof(String msg)
Asserts eof is met.
static Parser<?>eof(String name, String msg)
Asserts eof is met.
static <x> Parser<x>expect(String name, String lbl)
Create a Parser object that reports a "something expected" error.
static <x> Parser<x>expect(String lbl)
Create a Parser object that reports a "something expected" error.
static <R> Parser<R>fail(String msg)
A parser that always fail with the given error message.
static <R> Parser<R>fail(String name, String msg)
A parser that always fail with the given error message.
static <R> Parser<R>followedBy(String name, Parser<?> sep, Parser<R> p)
First run Parser p, then run Parser sep.
static Parser<Integer>getIndex()
Retrieves the current index in the source.
static Parser<Integer>getIndex(String name)
Retrieves the current index in the source.
static <C,R> Parser<R>ifelse(String name, Parser<C> p, ToParser<? super C,R> yes, Parser<? extends R> no)
First run Parser p, if it succeeds, thread the return value to ToParser yes; if it fails and no input is consumed, run Parser no; fails if p fails and some input is consumed.
static <C,R> Parser<R>ifelse(String name, Parser<C> p, Parser<R> yes, Parser<? extends R> no)
First run Parser p, if it succeeds, run Parser yes; if it fails and no input is consumed, run Parser no; fails if p fails and some input is consumed.
static <T> Parser<T>infixl(Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Left associative infix operator.
static <T> Parser<T>infixl(String name, Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Left associative infix operator.
static <T> Parser<T>infixn(Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> operand)
Non-associative infix operator.
static <T> Parser<T>infixn(String name, Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> operand)
Non-associative infix operator.
static <T> Parser<T>infixr(Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Right associative infix operator.
static <T> Parser<T>infixr(String name, Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Right associative infix operator.
static <R> Parser<R>isConsumed(Parser<R> p)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.
static <R> Parser<R>isConsumed(Parser<R> p, String err)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.
static <R> Parser<R>isConsumed(String name, Parser<R> p)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.
static <R> Parser<R>isConsumed(String name, Parser<R> p, String err)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.
static booleanisDebugEnabled()
Is debugging enabled?
static <R> Parser<R>isReturn(String name, ObjectPredicate<R> op)
Fails if the return value of the previous parser does not satisify the given predicate.
static <R> Parser<R>isReturn(String name, Parser<R> p, ObjectPredicate<? super R> op)
The created Parser object will first run parser p, if the return value of parser p does not satisify the given predicate, it fails and the input consumption of parser p is undone.
static <R> Parser<R>isReturn(String name, Parser<R> p, ObjectPredicate<? super R> op, String expecting)
The created Parser object will first run parser p, if the return value of parser p does not satisify the given predicate, it fails and the input consumption of parser p is undone.
static <R> Parser<R>label(String name, String lbl, Parser<R> p)
if Parser p fails and does not consume input, reports an expecting error with the given label.
static <R> Parser<R>lazy(ParserEval<R> p)
Create a lazy evaluated Parser. the ParserEval object is evaluated only when the Parser is actually executed.
static <R> Parser<R>lazy(Parser<R>[] placeholder, int pos)
Create a lazy evaluated parser.
static <R> Parser<R>lazy(Parser<R>[] placeholder)
Create a lazy evaluated parser.
static <R> Parser<R>lazy(String name, ParserEval<R> p)
Create a lazy evaluated Parser. the ParserEval object is evaluated only when the Parser is actually executed.
static <R> Parser<R>longer(String name, Parser<R> p1, Parser<R> p2)
Runs two alternative parsers.
static <R> Parser<R>longer(Parser<R> p1, Parser<R> p2)
Runs two alternative parsers.
static <R> Parser<R>longest(String name, Parser<R>... ps)
Runs an array of alternative parsers.
static <R> Parser<R>longest(Parser<R>... ps)
Runs an array of alternative parsers.
static <R> Parser<R>lookahead(String name, int toknum, Parser<R> p)
By default, ifelse, plus, sum will not try to run the next branch if the previous branch failed and consumed some input. this is because the default look-ahead token is 1.
static <R> Parser<_>many(String name, int min, Parser<?> p)
Greedily runs Parser p repeatedly for at least min times and discard the results.
static Parser<_>many(String name, Parser<?> p)
Greedily runs Parser p repeatedly and discard the results.
static <R> Parser<R[]>many(String name, Class<R> etype, int min, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and collect the result in an array whose element type is etype.
static <R> Parser<R[]>many(String name, Class<R> etype, Parser<? extends R> p)
Greedily runs Parser p repeatedly and collect the result in an array whose element type is etype.
static <R> Parser<R[]>many(String name, ArrayFactory<R> af, int min, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and collect the result in an array created by ArrayFactory object.
static <R> Parser<R[]>many(String name, ArrayFactory<R> af, Parser<? extends R> p)
Greedily runs Parser p repeatedly and collect the result in an array created by ArrayFactory object.
static <From,A extends From,R,To extends R> Parser<R>manyAccum(String name, Accumulatable<From,To> accm, int min, Parser<A> p)
Greedily runs Parser p repeatedly for at least min times and collect the result with the Accumulator object created by Accumulatable.
static <From,A extends From,R,To extends R> Parser<R>manyAccum(String name, Accumulatable<From,To> accm, Parser<A> p)
Greedily runs Parser p repeatedly for 0 or more times. and collect the result with the Accumulator object created by Accumulatable.
static <R,From> Parser<R>map(String name, Parser<From> p, Map<? super From,R> m)
Transform the return value of Parser p to a different value.
static <A,B,R> Parser<R>map2(Parser<A> p1, Parser<B> p2, Map2<? super A,? super B,R> m2)
Run 2 Parsers sequentially and transform the return values to a new value.
static <A,B,R> Parser<R>map2(String name, Parser<A> p1, Parser<B> p2, Map2<? super A,? super B,R> m2)
Run 2 Parsers sequentially and transform the return values to a new value.
static <A,B,C,R> Parser<R>map3(Parser<A> p1, Parser<B> p2, Parser<C> p3, Map3<? super A,? super B,? super C,R> m3)
Run 3 Parsers sequentially and transform the return values to a new value.
static <A,B,C,R> Parser<R>map3(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Map3<? super A,? super B,? super C,R> m3)
Run 3 Parsers sequentially and transform the return values to a new value.
static <A,B,C,D,R> Parser<R>map4(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Map4<? super A,? super B,? super C,? super D,R> m4)
Run 4 Parsers sequentially and transform the return values to a new value.
static <A,B,C,D,R> Parser<R>map4(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Map4<? super A,? super B,? super C,? super D,R> m4)
Run 4 Parsers sequentially and transform the return values to a new value.
static <A,B,C,D,E,R> Parser<R>map5(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,R> m5)
Run 5 Parsers sequentially and transform the return values to a new value.
static <A,B,C,D,E,R> Parser<R>map5(String name, 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,R> m5)
Run 5 Parsers sequentially and transform the return values to a new value.
static <R> Parser<R>mapn(Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects.
static <R> Parser<R>mapn(String name, Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects.
static <E,R> Parser<R>mapn(Class<? super E> etype, Parser<E>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects.
static <E,R> Parser<R>mapn(String name, Class<? super E> etype, Parser<E>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects.
static <E,R> Parser<R>mapn(ArrayFactory<?> af, Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects.
static <R> Parser<R>mapn(String name, ArrayFactory<?> af, Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects.
static Parser<?>not(String name, Parser<?> p)
Succeeds if Parser p fails; Fails otherwise.
static Parser<?>not(String name, Parser<?> p, String errmsg)
Succeeds if Parser p fails; Fails otherwise.
static <R> Parser<R>notConsumed(Parser<R> p)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.
static <R> Parser<R>notConsumed(Parser<R> p, String err)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.
static <R> Parser<R>notConsumed(String name, Parser<R> p)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.
static <R> Parser<R>notConsumed(String name, Parser<R> p, String err)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.
static Parser<?>one()
The parser that always succeed.
static Parser<?>one(String name)
The parser that always succeed.
static <R> Parser<R>option(R v, Parser<R> p)
Runs Parser p, if it fails with no input consumed, return default value v instead.
static <R> Parser<R>option(String name, R v, Parser<R> p)
Runs Parser p, if it fails with no input consumed, return default value v instead.
static <R> Parser<R>optional(Parser<R> p)
Runs Parser p, if it fails with no input consumed, succeed anyway with null as the result.
static <R> Parser<R>optional(String name, Parser<R> p)
Runs Parser p, if it fails with no input consumed, succeed anyway with null as result.
static Parser<Object>or(String name, Parser<?>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds.
static Parser<Object>or(Parser<?>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds.
static <A,B> Parser<Pair<A,B>>pair(Parser<A> p1, Parser<B> p2)
Sequentially run 2 parser objects and collect the results in a Pair object.
static <A,B> Parser<Pair<A,B>>pair(String name, Parser<A> p1, Parser<B> p2)
Sequentially run 2 parser objects and collect the results in a Pair object.
static <R> Parser<R>parseTokens(Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
static <R> Parser<R>parseTokens(String name, Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
static <R> Parser<R>parseTokens(String eof_title, ShowToken show, Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
static <R> Parser<R>parseTokens(String name, String eof_title, ShowToken show, Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
static <R> Parser<R>peek(String name, Parser<R> p)
Look ahead with Parser p.
static <R> Parser<R>plus(Parser<R> p1, Parser<? extends R> p2)
2 alternative parser objects.
static <R> Parser<R>plus(String name, Parser<R> p1, Parser<? extends R> p2)
2 alternative parser objects.
static <R> Parser<R>plus(Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3)
3 alternative parser objects.
static <R> Parser<R>plus(String name, Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3)
3 alternative parser objects.
static <R> Parser<R>plus(Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4)
4 alternative parser objects.
static <R> Parser<R>plus(String name, Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4)
4 alternative parser objects.
static <R> Parser<R>plus(Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4, Parser<? extends R> p5)
5 alternative parser objects.
static <R> Parser<R>plus(String name, Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4, Parser<? extends R> p5)
5 alternative parser objects.
static <R> Parser<R>plus(String name, Parser<R>... ps)
combine alternative parser objects.
static <R> Parser<R>plus(Parser<R>... ps)
combine alternative parser objects.
static <T> Parser<T>postfix(Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser p and then run Parser op for 0 or more times greedily.
static <T> Parser<T>postfix(String name, Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser p and then run Parser op for 0 or more times greedily.
static <T> Parser<T>prefix(Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser op for 0 or more times greedily.
static <T> Parser<T>prefix(String name, Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser op for 0 or more times greedily.
static <R> Parser<R>raise(Object e)
throws a pseudo-exception.
static <R> Parser<R>raise(String name, Object e)
throws a pseudo-exception.
static Parser<_>repeat(String name, int n, Parser<?> p)
Runs Parser p for n times.
static <R> Parser<R[]>repeat(String name, Class<R> etype, int n, Parser<? extends R> p)
Runs Parser p for n times, collect the return values in an array whose element type is etype.
static <R> Parser<R[]>repeat(String name, ArrayFactory<R> af, int n, Parser<? extends R> p)
Runs Parser p for n times, collect the return values in an array created by the ArrayFactory object.
static <R> Parser<R>retn(R r)
The parser that returns value v.
static <R> Parser<R>retn(String name, R r)
The parser that returns value v.
static Parser<?>runnable(String name, Runnable runnable)
To create a Parser that always succeeds and causes a certain side effect using a Runnable object.
static Parser<?>runnable(Runnable runnable)
To create a Parser that always succeeds and causes a certain side effect using a Runnable object.
static <R> RrunParser(CharSequence src, Parser<R> p, PositionMap pmap, String module)
Runs a character level parser with a CharSequence input.
static <R> RrunParser(CharSequence src, Parser<R> p, String module)
Runs a character level parser with a CharSequence input.
static <R> RrunParser(Tok[] toks, int end_index, Parser<R> p, ShowToken show, String eof_title, PositionMap pmap, String module)
Runs a token level Parser object with an array of tokens.
static Parser<_>sepBy(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static Parser<_>sepBy(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static <R> Parser<R[]>sepBy(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static <R> Parser<R[]>sepBy(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static <R> Parser<R[]>sepBy(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static <R> Parser<R[]>sepBy(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static Parser<_>sepBy1(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static Parser<_>sepBy1(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static <R> Parser<R[]>sepBy1(Class<R> etype, Parser<?> sep, Parser<? extends R> p)

Class -> Parser a -> Parser [Object].

static <R> Parser<R[]>sepBy1(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)

Class -> Parser a -> Parser [Object].

static <R> Parser<R[]>sepBy1(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static <R,A extends R> Parser<R[]>sepBy1(String name, ArrayFactory<R> af, Parser<?> sep, Parser<A> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.
static Parser<_>sepEndBy(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static Parser<_>sepEndBy(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static Parser<_>sepEndBy1(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static Parser<_>sepEndBy1(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy1(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy1(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy1(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R[]>sepEndBy1(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.
static <R> Parser<R>seq(Parser<?> p1, Parser<R> p2)
Sequencing 2 parser objects.
static <R> Parser<R>seq(String name, Parser<?> p1, Parser<R> p2)
Sequencing 2 parser objects.
static <R> Parser<R>seq(Parser<?> p1, Parser<?> p2, Parser<R> p3)
Sequencing 3 parser objects.
static <R> Parser<R>seq(String name, Parser<?> p1, Parser<?> p2, Parser<R> p3)
Sequencing 3 parser objects.
static <R> Parser<R>seq(Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<R> p4)
Sequencing 4 parser objects.
static <R> Parser<R>seq(String name, Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<R> p4)
Sequencing 4 parser objects.
static <R> Parser<R>seq(Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<R> p5)
Sequencing 5 parser objects.
static <R> Parser<R>seq(String name, Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<R> p5)
Sequencing 5 parser objects.
static Parser<Object>seqAll(Parser<?>[] ps)
Sequencing of an array of Parser objects.
static Parser<Object>seqAll(String name, Parser<?>[] ps)
Sequencing of an array of Parser objects.
static Parser<?>sequence(Parser<?>... ps)
Sequencing of an array of Parser objects.
static Parser<?>sequence(String name, Parser<?>... ps)
Sequencing of an array of Parser objects.
static voidsetDebug(boolean debugged)
enable or disable debugging.
static <R> Parser<R>shorter(String name, Parser<R> p1, Parser<R> p2)
Runs two alternative parsers.
static <R> Parser<R>shorter(Parser<R> p1, Parser<R> p2)
Runs two alternative parsers.
static <R> Parser<R>shortest(String name, Parser<R>... ps)
Runs an array of alternative parsers.
static <R> Parser<R>shortest(Parser<R>... ps)
Runs an array of alternative parsers.
static <R> Parser<_>some(String name, int min, int max, Parser<?> p)
Greedily runs Parser p repeatedly for at least min times and at most max time.
static Parser<_>some(String name, int max, Parser<?> p)
Greedily runs Parser p repeatedly for at most max time.
static <R> Parser<R[]>some(String name, ArrayFactory<R> af, int min, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and at most max time.
static <R> Parser<R[]>some(String name, ArrayFactory<R> af, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at most max time.
static <R> Parser<R[]>some(String name, Class<R> etype, int min, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and at most max times.
static <R> Parser<R[]>some(String name, Class<R> etype, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at most max times.
static <From,A extends From,R,To extends R> Parser<R>someAccum(String name, Accumulatable<From,To> accm, int min, int max, Parser<A> p)
Greedily runs Parser p repeatedly for at least min times and at most max times, collect the result with the Accumulator object created by Accumulatable.
static <From,A extends From,R,To extends R> Parser<R>someAccum(String name, Accumulatable<From,To> accm, int max, Parser<A> p)
Greedily runs Parser p repeatedly for at most max times, collect the result with the Accumulator object created by Accumulatable.
static <R> Parser<R>step(String name, int n, Parser<R> p)
lookahead looks at logical steps. step(String, int, Parser) runs this parser and sets the number of logical steps.
static Parser<Object>sum(Parser<?>... ps)
An array of alternative Parser objects. zero() is returned if the array is empty. the returned Parser object will try the Parser objects in the array one by one, until one of the following conditioins are met: the Parser succeeds, (sum() succeeds)
the Parser fails with input consumed (sum() fails with input consumed)
the end of array is encountered. (sum() fails with no input consumed).
static Parser<Object>sum(String name, Parser<?>... ps)
An array of alternative Parser objects. zero() is returned if the array is empty. the returned Parser object will try the Parser objects in the array one by one, until one of the following conditioins are met: the Parser succeeds, (sum() succeeds)
the Parser fails with input consumed (sum() fails with input consumed)
the end of array is encountered. (sum() fails with no input consumed).
static <R> Parser<R>token(FromToken<R> ft)
Token level parser. checks the current token with the FromToken object.
static <R> Parser<R>token(String name, FromToken<R> ft)
Token level parser. checks the current token with the FromToken object.
static Parser<Tok>token(Object t)
Token level parser. checks to see if the current token is token t. (using ==).
static Parser<Tok>token(String name, Object t)
Token level parser. checks to see if the current token is token t. (using ==).
static <x> ToParser<x,?>toOne()
Returns a ToParser that ignores the value passed in and simply returns one().
static <x> ToParser<x,?>toOne(String name)
Returns a ToParser that ignores the value passed in and simply returns one().
static <x,R> ToParser<x,R>toParser(Parser<R> parser)
Creates a ToParser object by always returning the same Parser object.
static <T> ToParser<T,T>toReturn()
Returns a ToParser instance that simply returns the previous return value.
static <T> ToParser<T,T>toReturn(String name)
Returns a ToParser instance that simply returns the previous return value.
static <x,y> ToParser<x,y>toZero()
Returns a ToParser that ignores the value passed in and simply returns zero().
static <x,y> ToParser<x,y>toZero(String name)
Returns a ToParser that ignores the value passed in and simply returns zero().
static <R> Parser<R>tryParser(Parser<R> p, Catch<? extends R> hdl)
if Parser p throws an exception, it is handled by Catch hdl.
static <R> Parser<R>tryParser(String name, Parser<R> p, Catch<? extends R> hdl)
if Parser p throws an exception, it is handled by Catch hdl.
static <A,B,C> Parser<Tuple3<A,B,C>>tuple(Parser<A> p1, Parser<B> p2, Parser<C> p3)
Sequentially run 3 parser objects and collect the results in a Tuple3 object.
static <A,B,C,D> Parser<Tuple4<A,B,C,D>>tuple(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4)
Sequentially run 4 parser objects and collect the results in a Tuple4 object.
static <A,B,C,D,E> Parser<Tuple5<A,B,C,D,E>>tuple(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5)
Sequentially run 5 parser objects and collect the results in a Tuple5 object.
static <A,B,C> Parser<Tuple3<A,B,C>>tuple(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3)
Sequentially run 3 parser objects and collect the results in a Tuple3 object.
static <A,B,C,D> Parser<Tuple4<A,B,C,D>>tuple(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4)
Sequentially run 4 parser objects and collect the results in a Tuple4 object.
static <A,B,C,D,E> Parser<Tuple5<A,B,C,D,E>>tuple(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5)
Sequentially run 5 parser objects and collect the results in a Tuple5 object.
static <x> Parser<x>unexpected(String msg)
Reports an unexpected error.
static <x> Parser<x>unexpected(String name, String msg)
Reports an unexpected error.
static <x> Parser<x>zero()
The parser that always fails.
static <x> Parser<x>zero(String name)
The parser that always fails.

Method Detail

alt

public static <T> Parser<T> alt(String name, Parser<T>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds. Regardless of look-ahead, input consumption will not prevent the next parser from being executed.

Parameters: name the new parser name. alternatives the alternative parsers.

Returns: the new Parser object.

alt

public static <T> Parser<T> alt(Parser<T>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds. Regardless of look-ahead, input consumption will not prevent the next parser from being executed.

Parameters: alternatives the alternative parsers.

Returns: the new Parser object.

anyToken

public static Parser<Tok> anyToken()
Consumes a token. The token is used as the return value of the parser.

Parser Token

Returns: the Parser object.

anyToken

public static Parser<Tok> anyToken(String name)
Consumes a token. The Tok is used as the return value of the parser.

Parser Tok

Parameters: name the name of the Parser object.

Returns: the Parser object.

atomize

public static <R> Parser<R> atomize(String name, Parser<R> p)
Backout input consumption if p fails. The logical step is ensured to be at most 1.

Parser a -> Parser a

Parameters: name the name of the new Parser object. p the Parser object.

Returns: the new Parser object.

between

public static <R> Parser<R> between(Parser<?> open, Parser<?> close, Parser<R> p)
Runs a Parser that is between a pair of parsers. First run Parser open, then run Parser p, finally run Parser close. The return value of p is preserved as the return value.
do {open; x<-p; close; return p}

Parser ? -> Parser a -> Parser ? -> Parser a

Parameters: open the opening parser. close the closing parser. p the Parser object.

Returns: the new Parser object.

between

public static <R> Parser<R> between(String name, Parser<?> open, Parser<?> close, Parser<R> p)
runs a Parser that is between a pair of parsers. First run Parser open, then run Parser p, finally run Parser close. The return value of p is preserved as the return value.
do {open; x<-p; close; return p}

Parser ? -> Parser ? -> Parser a -> Parser a

Parameters: name the name of the new Parser object. open the opening parser. close the closing parser. p the Parser object.

Returns: the new Parser object.

bind

public static <From,To> Parser<To> bind(String name, Parser<From> p, ToParser<? super From,To> f)
First run p, if it succeeds, run ToParser f with the value returned from p.

Parser a -> (a->Parser b) -> Parser b

Parameters: name the name of the Parser. p the first Parser object. f the ToParser object to run if the first succeeds.

Returns: the Parser object.

bindAll

public static <T> ToParser<T,T> bindAll(ToParser<T,T>... binders)
Threads an array of ToParser into a single ToParser. The first return value is passed to the first ToParser, and the result Parser is executed to get the next return value. The return value keeps pass down until all ToParser are called. If any Parser fails, the threading fails.

[(a->Parser a)] -> a -> Parser a

Parameters: binders all the ToParser objects.

Returns: the new ToParser.

bindAll

public static <T> ToParser<T,T> bindAll(String name, ToParser<T,T>... binders)
Threads an array of ToParser into a single ToParser. The first return value is passed to the first ToParser, and the result Parser is executed to get the next return value. The return value keeps pass down until all ToParser are called. If any Parser fails, the threading fails.

[(a->Parser a)] -> a -> Parser a

Parameters: binders all the ToParser objects. name the name of the Parser created by the result ToParser.

Returns: the new ToParser.

endBy

public static Parser<_> endBy(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are discarded.

Class -> Parser ? -> Parser _

Parameters: sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy

public static Parser<_> endBy(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy

public static <R> Parser<R[]> endBy(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: etype array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy

public static <R> Parser<R[]> endBy(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are discarded.

ArrayFactory a -> Parser ? -> Parser a -> Parser a[]

Parameters: af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy

public static <R> Parser<R[]> endBy(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy

public static <R> Parser<R[]> endBy(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy1

public static Parser<_> endBy1(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p should succeed for at least once.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy1

public static Parser<_> endBy1(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p should succeed for at least once.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy1

public static <R> Parser<R[]> endBy1(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p should succeed for at least once.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: etype array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy1

public static <R> Parser<R[]> endBy1(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p should succeed for at least once.
For example: pattern "token; token; token; token;" is endBy1(comma, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy1

public static <R> Parser<R[]> endBy1(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p should succeed for at least once.
For example: pattern "token; token; token; token;" is endBy1(comma, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

endBy1

public static <R> Parser<R[]> endBy1(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern ended by Parser sep pattern.

Parser p should succeed for at least once.
For example: pattern "token; token; token; token;" is endBy(comma, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

eof

public static Parser<?> eof()
Asserts eof is met. Fails otherwise.

Parser ?

Returns: the Parser object.

eof

public static Parser<?> eof(String msg)
Asserts eof is met. Fails otherwise.

Parser ?

Parameters: msg the error message if eof is not met.

Returns: the Parser object.

eof

public static Parser<?> eof(String name, String msg)
Asserts eof is met. Fails otherwise.

Parser ?

Parameters: name the name of the new Parser object. msg the error message if eof is not met.

Returns: the Parser object.

expect

public static <x> Parser<x> expect(String name, String lbl)
Create a Parser object that reports a "something expected" error.

Parameters: the result Parser object is good for any result type. (it does not return anyway) name the parser name. lbl the label.

Returns: the Parser object.

Since: version 0.6

expect

public static <x> Parser<x> expect(String lbl)
Create a Parser object that reports a "something expected" error.

Parameters: the result Parser object is good for any result type. (it does not return anyway) lbl the label.

Returns: the Parser object.

Since: version 0.6

fail

public static <R> Parser<R> fail(String msg)
A parser that always fail with the given error message.

Parser *

Parameters: msg the error message.

Returns: the Parser object.

fail

public static <R> Parser<R> fail(String name, String msg)
A parser that always fail with the given error message.

Parser *

Parameters: name the Parser object name. msg the error message.

Returns: the Parser object.

followedBy

public static <R> Parser<R> followedBy(String name, Parser<?> sep, Parser<R> p)
First run Parser p, then run Parser sep. The return value of Parser p is preserved as the return value.
do{x<-p;sep;return x}.

Parser ? -> Parser a -> Parser a

Parameters: name the name of the new Parser object. sep the following parser. p the Parser object.

Returns: the new Parser object.

getIndex

public static Parser<Integer> getIndex()
Retrieves the current index in the source.

Parser Integer

Returns: the Parser object.

getIndex

public static Parser<Integer> getIndex(String name)
Retrieves the current index in the source.

Parser Integer

Parameters: name the name of the Parser object.

Returns: the Parser object.

ifelse

public static <C,R> Parser<R> ifelse(String name, Parser<C> p, ToParser<? super C,R> yes, Parser<? extends R> no)
First run Parser p, if it succeeds, thread the return value to ToParser yes; if it fails and no input is consumed, run Parser no; fails if p fails and some input is consumed.

Parser a -> (a->Parser b) -> Parser b -> Parser b

Parameters: name the name of the new Parser object. p the Parser object to test. yes the true branch. no the false branch.

Returns: the new Parser object.

ifelse

public static <C,R> Parser<R> ifelse(String name, Parser<C> p, Parser<R> yes, Parser<? extends R> no)
First run Parser p, if it succeeds, run Parser yes; if it fails and no input is consumed, run Parser no; fails if p fails and some input is consumed.

Parser x -> Parser b -> Parser b -> Parser b

Parameters: name the name of the new Parser object. p the Parser object to test. yes the true branch. no the false branch.

Returns: the new Parser object.

infixl

public static <T> Parser<T> infixl(Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Left associative infix operator. Runs Parser p and then run Parser op and Parser p for 0 or more times greedily. The Map object returned from op are applied from left to right to the return value of p.
for example: a+b+c+d is evaluated as (((a+b)+c)+d).
infixl(op, p) is equivalent to p (op p)* in EBNF.

Parser (a->a->a) -> Parser a -> Parser a

Parameters: op the operator. p the operand.

Returns: the new Parser object.

infixl

public static <T> Parser<T> infixl(String name, Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Left associative infix operator. Runs Parser p and then run Parser op and Parser p for 0 or more times greedily. The Map object returned from op are applied from left to right to the return values of p.
for example: a+b+c+d is evaluated as (((a+b)+c)+d).
infixl(op, p) is equivalent to p (op p)* in EBNF.

Parser (a->a->a) -> Parser a -> Parser a

Parameters: name the name of the new Parser object. op the operator. p the operand.

Returns: the new Parser object.

infixn

public static <T> Parser<T> infixn(Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> operand)
Non-associative infix operator. Runs Parser p and then run Parser op and Parser p optionally. The Map2 object returned from op is applied to the return values of the two p pattern, if any.
infixn(op, p) is equivalent to p (op p)? in EBNF

Parser (a->a->a) -> Parser a -> Parser a

Parameters: op the operator. operand the operand.

Returns: the new Parser object.

infixn

public static <T> Parser<T> infixn(String name, Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> operand)
Non-associative infix operator. Runs Parser p and then run Parser op and Parser p optionally. The Map2 object returned from op is applied to the return values of the two p pattern, if any.
infixn(op, p) is equivalent to p (op p)? in EBNF

Parser (a->a->a) -> Parser a -> Parser a

Parameters: name the name of the new Parser object. op the operator. operand the operand.

Returns: the new Parser object.

infixr

public static <T> Parser<T> infixr(Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Right associative infix operator. Runs Parser p and then run Parser op and Parser p for 0 or more times greedily. The Map object returned from op are applied from right to left to the return values of p.
for example: a+b+c+d is evaluated as a+(b+(c+d)).
infixr(op, p) is equivalent to p (op p)* in EBNF.

Parser (a->a->a) -> Parser a -> Parser a

Parameters: op the operator. p the operand.

Returns: the new Parser object.

infixr

public static <T> Parser<T> infixr(String name, Parser<? extends Map2<? super T,? super T,T>> op, Parser<? extends T> p)
Right associative infix operator. Runs Parser p and then run Parser op and Parser p for 0 or more times greedily. The Map object returned from op are applied from right to left to the return values of p.
for example: a+b+c+d is evaluated as a+(b+(c+d)).
infixr(op, p) is equivalent to p (op p)* in EBNF.

Parser (a->a->a) -> Parser a -> Parser a

Parameters: name the name of the new Parser object. op the operator. p the operand.

Returns: the new Parser object.

isConsumed

public static <R> Parser<R> isConsumed(Parser<R> p)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.

Parser a -> Parser a

Parameters: p the Parser object to test.

Returns: the new Parser object.

isConsumed

public static <R> Parser<R> isConsumed(Parser<R> p, String err)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.

Parser a -> Parser a

Parameters: p the Parser object to test. err the error message when p succeeds with no input consumed.

Returns: the new Parser object.

isConsumed

public static <R> Parser<R> isConsumed(String name, Parser<R> p)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.

Parser a -> Parser a

Parameters: name the name of the new Parser object. p the Parser object to test.

Returns: the new Parser object.

isConsumed

public static <R> Parser<R> isConsumed(String name, Parser<R> p, String err)
First run the Parser p, if it succeeds with input consumed, isConsumed() succeeds; if it fails or did not consume input, isConsumed() fails.

Parser a -> Parser a

Parameters: name the name of the new Parser. p the Parser object to test. err the error message when p succeeds with no input consumed.

Returns: the new Parser object.

isDebugEnabled

public static boolean isDebugEnabled()
Is debugging enabled?

Since: version 1.1

isReturn

public static <R> Parser<R> isReturn(String name, ObjectPredicate<R> op)
Fails if the return value of the previous parser does not satisify the given predicate. No-op otherwise.

Parameters: name the name of the new Parser object. op the predicate object.

Returns: the new Parser object.

isReturn

public static <R> Parser<R> isReturn(String name, Parser<R> p, ObjectPredicate<? super R> op)
The created Parser object will first run parser p, if the return value of parser p does not satisify the given predicate, it fails and the input consumption of parser p is undone. It is an atomic parser.

Parameters: name the name of the new Parser object. p the parser object to test the return value of. op the predicate object.

Returns: the new Parser object.

isReturn

public static <R> Parser<R> isReturn(String name, Parser<R> p, ObjectPredicate<? super R> op, String expecting)
The created Parser object will first run parser p, if the return value of parser p does not satisify the given predicate, it fails and the input consumption of parser p is undone. It is an atomic parser.

Parameters: name the name of the new Parser object. p the parser object to test the return value of. op the predicate object. expecting the "expected" error message.

Returns: the new Parser object.

label

public static <R> Parser<R> label(String name, String lbl, Parser<R> p)
if Parser p fails and does not consume input, reports an expecting error with the given label.

Parser a -> Parser a

Parameters: name the name of the new Parser object. lbl the label text. p the Parser object to label.

Returns: the new Parser object.

lazy

public static <R> Parser<R> lazy(ParserEval<R> p)
Create a lazy evaluated Parser. the ParserEval object is evaluated only when the Parser is actually executed.

Parser a -> Parser a

Parameters: p the ParserEval object.

Returns: the Parser object.

lazy

public static <R> Parser<R> lazy(Parser<R>[] placeholder, int pos)
Create a lazy evaluated parser. When evaluated, it reads the parser object stored in an array indexed by pos.

Parameters: placeholder the array that contains parser object. pos the position (0-based) of the parser to lazily evaluate.

Returns: the lazy parser.

lazy

public static <R> Parser<R> lazy(Parser<R>[] placeholder)
Create a lazy evaluated parser. When evaluated, it reads the first parser object stored in an array.

Parameters: placeholder the array whose first object is the lazily evaluated parser object.

Returns: the lazy parser.

lazy

public static <R> Parser<R> lazy(String name, ParserEval<R> p)
Create a lazy evaluated Parser. the ParserEval object is evaluated only when the Parser is actually executed.

Parser a -> Parser a

Parameters: name the name of the Parser object. p the ParserEval object.

Returns: the Parser object.

longer

public static <R> Parser<R> longer(String name, Parser<R> p1, Parser<R> p2)
Runs two alternative parsers. If both succeed, the one with the longer match wins. If both matches the same length, the first one is favored.

Parameters: name the name of the new Parser object. p1 the 1st alternative parser. p2 the 2nd alternative parser.

Returns: the new Parser object.

longer

public static <R> Parser<R> longer(Parser<R> p1, Parser<R> p2)
Runs two alternative parsers. If both succeed, the one with the longer match wins. If both matches the same length, the first one is favored.

Parameters: p1 the 1st alternative parser. p2 the 2nd alternative parser.

Returns: the new Parser object.

longest

public static <R> Parser<R> longest(String name, Parser<R>... ps)
Runs an array of alternative parsers. If more than one succeed, the one with the longest match wins. If two matches have the same length, the first one is favored.

Parameters: name the name of the new Parser object. ps the array of alternative parsers.

Returns: the new Parser object.

longest

public static <R> Parser<R> longest(Parser<R>... ps)
Runs an array of alternative parsers. If more than one succeed, the one with the longest match wins. If two matches have the same length, the first one is favored.

Parameters: ps the array of alternative parsers.

Returns: the new Parser object.

lookahead

public static <R> Parser<R> lookahead(String name, int toknum, Parser<R> p)
By default, ifelse, plus, sum will not try to run the next branch if the previous branch failed and consumed some input. this is because the default look-ahead token is 1.
by using lookahead, this default behavior can be altered. Parsers.plus(p1, p2).lookahead(3) will still try p2 even if p1 fails and consumes one or two inputs.

lookahead only affects one nesting level. Parsers.plus(p1,p2).ifelse(yes,no).lookahead(3) will not affect the Parsers.plus(p1,p2) nested within ifelse.

lookahead directly on top of lookahead will override the previous lookahead. Parsers.plus(p1,p2).lookahead(3).lookahead(1) is equivalent as Parsers.plus(p1, p2).lookahead(1).
lookahead looks at logical step. by default, each terminal is one logical step. atomize() combinator ensures at most 1 logical step for a parser. Use step() combinator to fine control logical steps.

Parameters: name the name of the new Parser object. toknum the number of tokens to look ahead.

Returns: the new Parser object.

many

public static <R> Parser<_> many(String name, int min, Parser<?> p)
Greedily runs Parser p repeatedly for at least min times and discard the results.

int -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. min the minimal times to run. p the Parser object.

Returns: the new Parser object.

many

public static Parser<_> many(String name, Parser<?> p)
Greedily runs Parser p repeatedly and discard the results.

Parser ? -> Parser _

Parameters: name the name of the new Parser object. p the Parser object.

Returns: the new Parser object.

many

public static <R> Parser<R[]> many(String name, Class<R> etype, int min, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and collect the result in an array whose element type is etype.

Class [a] -> int -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. etype the array element type. min the maximal times to run. p the Parser object.

Returns: the new Parser object.

many

public static <R> Parser<R[]> many(String name, Class<R> etype, Parser<? extends R> p)
Greedily runs Parser p repeatedly and collect the result in an array whose element type is etype.

Class [a] -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. etype the array element type. p the Parser object.

Returns: the new Parser object.

many

public static <R> Parser<R[]> many(String name, ArrayFactory<R> af, int min, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and collect the result in an array created by ArrayFactory object.

ArrayFactory a -> int -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. min the maximal times to run. p the Parser object.

Returns: the new Parser object.

many

public static <R> Parser<R[]> many(String name, ArrayFactory<R> af, Parser<? extends R> p)
Greedily runs Parser p repeatedly and collect the result in an array created by ArrayFactory object.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. p the Parser object.

Returns: the new Parser object.

manyAccum

public static <From,A extends From,R,To extends R> Parser<R> manyAccum(String name, Accumulatable<From,To> accm, int min, Parser<A> p)
Greedily runs Parser p repeatedly for at least min times and collect the result with the Accumulator object created by Accumulatable. Fails if p fails and consumes some input or if p throws a pseudo-exception.

Accumulatable a r -> int -> int -> Parser a -> Parser r

Parameters: name the name of the new Parser object. accm the Accumulatable object. min the minimum times to repeat. p the Parser object.

Returns: the new Parser object.

manyAccum

public static <From,A extends From,R,To extends R> Parser<R> manyAccum(String name, Accumulatable<From,To> accm, Parser<A> p)
Greedily runs Parser p repeatedly for 0 or more times. and collect the result with the Accumulator object created by Accumulatable. Fails if p fails and consumes some input or if p throws a pseudo-exception.

Accumulatable a r -> int -> int -> Parser a -> Parser r

Parameters: name the name of the new Parser object. accm the Accumulatable object. p the Parser object.

Returns: the new Parser object.

map

public static <R,From> Parser<R> map(String name, Parser<From> p, Map<? super From,R> m)
Transform the return value of Parser p to a different value.

Parser a -> (a->b) -> Parser b

Parameters: name the name of the new Parser object. p the Parser object. m the Map object.

Returns: the new Parser object.

map2

public static <A,B,R> Parser<R> map2(Parser<A> p1, Parser<B> p2, Map2<? super A,? super B,R> m2)
Run 2 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->(a->b->r)->Parser r

Parameters: p1 1st parser. p2 2nd parser. m2 the transformer.

Returns: the new Parser object.

map2

public static <A,B,R> Parser<R> map2(String name, Parser<A> p1, Parser<B> p2, Map2<? super A,? super B,R> m2)
Run 2 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->(a->b->r)->Parser r

Parameters: name the name of the new Parser object. p1 1st parser. p2 2nd parser. m2 the transformer.

Returns: the new Parser object.

map3

public static <A,B,C,R> Parser<R> map3(Parser<A> p1, Parser<B> p2, Parser<C> p3, Map3<? super A,? super B,? super C,R> m3)
Run 3 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->Parser c->(a->b->c->r)->Parser r

Parameters: p1 1st parser. p2 2nd parser. p3 3rd parser. m3 the transformer.

Returns: the new Parser object.

map3

public static <A,B,C,R> Parser<R> map3(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Map3<? super A,? super B,? super C,R> m3)
Run 3 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->Parser c->(a->b->c->r)->Parser r

Parameters: name the name of the new Parser object. p1 1st parser. p2 2nd parser. p3 3rd parser. m3 the transformer.

Returns: the new Parser object.

map4

public static <A,B,C,D,R> Parser<R> map4(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Map4<? super A,? super B,? super C,? super D,R> m4)
Run 4 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->Parser c->Parser d->(a->b->c->d->r)->Parser r

Parameters: p1 1st parser. p2 2nd parser. p3 3rd parser. p4 4th parser. m4 the transformer.

Returns: the new Parser object.

map4

public static <A,B,C,D,R> Parser<R> map4(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Map4<? super A,? super B,? super C,? super D,R> m4)
Run 4 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->Parser c->Parser d->(a->b->c->d->r)->Parser r

Parameters: name the name of the new Parser object. p1 1st parser. p2 2nd parser. p3 3rd parser. p4 4th parser. m4 the transformer.

Returns: the new Parser object.

map5

public static <A,B,C,D,E,R> Parser<R> map5(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,R> m5)
Run 5 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->Parser c->Parser d->Parser e->(a->b->c->d->e->r)->Parser r

Parameters: p1 1st parser. p2 2nd parser. p3 3rd parser. p4 4th parser. p5 5th parser. m5 the transformer.

Returns: the new Parser object.

map5

public static <A,B,C,D,E,R> Parser<R> map5(String name, 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,R> m5)
Run 5 Parsers sequentially and transform the return values to a new value.

Parser a->Parser b->Parser c->Parser d->Parser e->(a->b->c->d->e->r)->Parser r

Parameters: name the name of the new Parser object. p1 1st parser. p2 2nd parser. p3 3rd parser. p4 4th parser. p5 5th parser. m5 the transformer.

Returns: the new Parser object.

mapn

public static <R> Parser<R> mapn(Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects. The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are collected as a Object[] array and transformed by a Mapn object.

[Parser a] -> ([a]->r) -> Parser r

Parameters: ps the array of Parser objects. mn the Mapn object.

Returns: the new Parser object.

mapn

public static <R> Parser<R> mapn(String name, Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects. The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are collected and returned as an Object[] array and transformed by a Mapn object.

[Parser a] -> ([a]->r) -> Parser r

Parameters: name the name of the new Parser. ps the array of Parser objects. mn the Mapn object.

Returns: the new Parser object.

mapn

public static <E,R> Parser<R> mapn(Class<? super E> etype, Parser<E>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects. The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are collected and returned as a T[] array where T is the element type, and then transformed by a Mapn object.

[Parser a] -> ([a]->r) -> Parser r

Parameters: etype the element type of the return value array. ps the array of Parser objects. mn the Mapn object.

Returns: the new Parser object.

mapn

public static <E,R> Parser<R> mapn(String name, Class<? super E> etype, Parser<E>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects. The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are collected and returned as a T[] array where T is the element type, and then transformed by a Mapn object.

[Parser a] -> ([a]->r) -> Parser r

Parameters: name the name of the new Parser. etype the element type of the return value array. ps the array of Parser objects. mn the Mapn object.

Returns: the new Parser object.

mapn

public static <E,R> Parser<R> mapn(ArrayFactory<?> af, Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects. The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are collected and returned as an array created by the ArrayFactory parameter, and then transformed by a Mapn object.

[Parser a] -> ([a]->r) -> Parser r

Parameters: af the ArrayFactory object. ps the array of Parser objects. mn the Mapn object.

Returns: the new Parser object.

mapn

public static <R> Parser<R> mapn(String name, ArrayFactory<?> af, Parser<?>[] ps, Mapn<R> mn)
Sequencing of an array of Parser objects. The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are collected and returned as an array created by the ArrayFactory parameter and then transformed by a Mapn object.

[Parser a] -> ([a]->r) -> Parser r

Parameters: name the name of the new Parser. af the ArrayFactory object. ps the array of Parser objects. mn the Mapn object.

Returns: the new Parser object.

not

public static Parser<?> not(String name, Parser<?> p)
Succeeds if Parser p fails; Fails otherwise. Input consumption is undone.

Parser ? -> Parser ?

Parameters: name the name of the new Parser object. p the Parser to 'not'

Returns: the new Parser object.

not

public static Parser<?> not(String name, Parser<?> p, String errmsg)
Succeeds if Parser p fails; Fails otherwise. Input consumption is undone.

Parser ? -> Parser ?

Parameters: name the name of the new Parser object. p the Parser to 'not' errmsg the error message if Parser p succeeds.

Returns: the new Parser object.

notConsumed

public static <R> Parser<R> notConsumed(Parser<R> p)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.

Parser a -> Parser a

Parameters: p the Parser object to test.

Returns: the new Parser object.

notConsumed

public static <R> Parser<R> notConsumed(Parser<R> p, String err)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.

Parser a -> Parser a

Parameters: p the Parser object to test. err the error message when p succeeds and consumes some input.

Returns: the new Parser object.

notConsumed

public static <R> Parser<R> notConsumed(String name, Parser<R> p)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.

Parser a -> Parser a

Parameters: name the name of the new Parser. p the Parser object to test.

Returns: the new Parser object.

notConsumed

public static <R> Parser<R> notConsumed(String name, Parser<R> p, String err)
First run the Parser p, if it succeeds with no input consumed, notConsumed() succeeds; if it fails, notConsumed() fails; if it succeeds and consumes input, the input consumption is undone and notConsumed() fails.

Parser a -> Parser a

Parameters: name the name of the new Parser. p the Parser object to test. err the error message when p succeeds and consumes some input.

Returns: the new Parser object.

one

public static Parser<?> one()
The parser that always succeed. It does not consume any input.

Parser ?

Returns: the Parser object.

one

public static Parser<?> one(String name)
The parser that always succeed. It does not consume any input.

Parser ?

Parameters: name the name of the Parser.

Returns: the Parser object.

option

public static <R> Parser<R> option(R v, Parser<R> p)
Runs Parser p, if it fails with no input consumed, return default value v instead.
plus(p, retn(v))

a -> Parser a -> Parser a

Parameters: v the default value. p the Parser object.

Returns: the new Parser object.

option

public static <R> Parser<R> option(String name, R v, Parser<R> p)
Runs Parser p, if it fails with no input consumed, return default value v instead.
plus(name, p, retn(v))

a -> Parser a -> Parser a

Parameters: name the name of the new Parser object. v the default value. p the Parser object.

Returns: the new Parser object.

optional

public static <R> Parser<R> optional(Parser<R> p)
Runs Parser p, if it fails with no input consumed, succeed anyway with null as the result.
option(p, null)

Parser a -> Parser a

Parameters: p the Parser object.

Returns: the new Parser object.

optional

public static <R> Parser<R> optional(String name, Parser<R> p)
Runs Parser p, if it fails with no input consumed, succeed anyway with null as result.
option(name, p, null)

Parser a -> Parser a

Parameters: name the name of the new Parser object. p the Parser object.

Returns: the new Parser object.

or

public static Parser<Object> or(String name, Parser<?>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds. Regardless of look-ahead, input consumption will not prevent the next parser from being executed.

Parameters: name the new parser name. alternatives the alternative parsers.

Returns: the new Parser object.

or

public static Parser<Object> or(Parser<?>... alternatives)
To create a Parser that runs an array of Parser objects until one succeeds. Regardless of look-ahead, input consumption will not prevent the next parser from being executed.

Parameters: alternatives the alternative parsers.

Returns: the new Parser object.

pair

public static <A,B> Parser<Pair<A,B>> pair(Parser<A> p1, Parser<B> p2)
Sequentially run 2 parser objects and collect the results in a Pair object.

Parameters: p1 the first parser. p2 the second parser.

Returns: the result parser.

pair

public static <A,B> Parser<Pair<A,B>> pair(String name, Parser<A> p1, Parser<B> p2)
Sequentially run 2 parser objects and collect the results in a Pair object.

Parameters: name the result parser name. p1 the first parser. p2 the second parser.

Returns: the result parser.

parseTokens

public static <R> Parser<R> parseTokens(Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
It fails if the lexer fails or parser p fails. Parser [Tok] -> Parser a -> Parser a

Parameters: lexer the lexer object that returns an array of Tok objects. p the token level parser object. module the module name. Use any name that's meaningful. that will parse the array of Tok objects.

Returns: the new Parser object.

parseTokens

public static <R> Parser<R> parseTokens(String name, Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
It fails if the lexer fails or parser p fails. Parser [Tok] -> Parser a -> Parser a

Parameters: name the name of the new Parser object. lexer the lexer object that returns an array of Tok objects. p the token level parser object. module the module name. Use any name that's meaningful. that will parse the array of Tok objects.

Returns: the new Parser object.

parseTokens

public static <R> Parser<R> parseTokens(String eof_title, ShowToken show, Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
It fails if the lexer fails or parser p fails. String -> ShowToken -> Parser [Tok] -> Parser a -> Parser a

Parameters: eof_title the name of "end of input" show the object to transform a token to a string. lexer the lexer object that returns an array of Tok objects. p the token level parser object. module the module name. Use any name that's meaningful. that will parse the array of Tok objects.

Returns: the new Parser object.

parseTokens

public static <R> Parser<R> parseTokens(String name, String eof_title, ShowToken show, Parser<Tok[]> lexer, Parser<R> p, String module)
The created parser object will take as input the array of Tok returned from the lexer object, feed it into the Parser object p and run it, return the result from parser p.
It fails if the lexer fails or parser p fails. String -> ShowToken -> Parser [Tok] -> Parser a -> Parser a

Parameters: name the name of the new Parser object. eof_title the name of "end of input" show the object to transform a token to a string. lexer the lexer object that returns an array of Tok objects. p the token level parser object module the module name. Use any name that's meaningful. that will parse the array of Tok objects.

Returns: the new Parser object.

peek

public static <R> Parser<R> peek(String name, Parser<R> p)
Look ahead with Parser p. The input consumption is undone.

Parser a -> Parser a

Parameters: name the name of the new Parser object. p the Parser object.

Returns: the new Parser object.

plus

public static <R> Parser<R> plus(Parser<R> p1, Parser<? extends R> p2)
2 alternative parser objects. If the first Parser fails with no input consumption, the second one is executed.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a

Parameters: p1 1st Parser. p2 2nd Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(String name, Parser<R> p1, Parser<? extends R> p2)
2 alternative parser objects. If the first Parser fails with no input consumption, the second one is executed.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3)
3 alternative parser objects.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a -> Parser a

Parameters: p1 1st Parser. p2 2nd Parser. p3 3rd Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(String name, Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3)
3 alternative parser objects.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a -> Parser a

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser. p3 3rd Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4)
4 alternative parser objects.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a -> Parser a -> Parser a

Parameters: p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(String name, Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4)
4 alternative parser objects.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a -> Parser a -> Parser a

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4, Parser<? extends R> p5)
5 alternative parser objects.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a -> Parser a -> Parser a -> Parser a

Parameters: p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser. p5 5th Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(String name, Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3, Parser<? extends R> p4, Parser<? extends R> p5)
5 alternative parser objects.

For backwward compatibility with java 1.4. Use the vararg version in java 5.

Parser a -> Parser a -> Parser a -> Parser a -> Parser a -> Parser a

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser. p5 5th Parser.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(String name, Parser<R>... ps)
combine alternative parser objects. If the first Parser fails with no input consumption, the next ones are executed until one succeeds.

Parameters: name the name of the created parser. ps the Parser objects.

Returns: the new Parser.

plus

public static <R> Parser<R> plus(Parser<R>... ps)
combine alternative parser objects. If the first Parser fails with no input consumption, the next ones are executed until one succeeds.

Parameters: ps the Parser objects.

Returns: the new Parser.

postfix

public static <T> Parser<T> postfix(Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser p and then run Parser op for 0 or more times greedily. The Map object returned from op are applied from left to right to the return value of p.
postfix(op, p) is equivalent to p op* in EBNF

Parser (a->a) -> Parser a -> Parser a

Parameters: op the operator. p the operand.

Returns: the new Parser object.

postfix

public static <T> Parser<T> postfix(String name, Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser p and then run Parser op for 0 or more times greedily. The Map object returned from op are applied from left to right to the return value of p.
postfix(op, p) is equivalent to p op* in EBNF

Parser (a->a) -> Parser a -> Parser a

Parameters: name the name of the new Parser object. op the operator. p the operand.

Returns: the new Parser object.

prefix

public static <T> Parser<T> prefix(Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser op for 0 or more times greedily. Then run Parser p. The Map object returned from op are applied from right to left to the return value of p.
prefix(op, p) is equivalent to op* p in EBNF

Parser (a->a) -> Parser a -> Parser a

Parameters: op the operator. p the operand.

Returns: the new Parser object.

prefix

public static <T> Parser<T> prefix(String name, Parser<? extends Map<? super T,T>> op, Parser<? extends T> p)
Runs Parser op for 0 or more times greedily. Then run Parser p. The Map object returned from op are applied from right to left to the return value of p.
prefix(op, p) is equivalent to op* p in EBNF

Parser (a->a) -> Parser a -> Parser a

Parameters: name the name of the new Parser object. op the operator. p the operand.

Returns: the new Parser object.

raise

public static <R> Parser<R> raise(Object e)
throws a pseudo-exception.

Parser *

Parameters: e the exception object.

Returns: the Parser object.

raise

public static <R> Parser<R> raise(String name, Object e)
throws a pseudo-exception.

Parser *

Parameters: name the name of the new Parser object. e the exception object.

Returns: the Parser object.

repeat

public static Parser<_> repeat(String name, int n, Parser<?> p)
Runs Parser p for n times. Return values are discarded.

int -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. n the number of times to run. p the Parser object.

Returns: the new Parser object.

repeat

public static <R> Parser<R[]> repeat(String name, Class<R> etype, int n, Parser<? extends R> p)
Runs Parser p for n times, collect the return values in an array whose element type is etype.

Class -> int -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype the array element type. n the number of times to run. p the Parser object.

Returns: the new Parser object.

repeat

public static <R> Parser<R[]> repeat(String name, ArrayFactory<R> af, int n, Parser<? extends R> p)
Runs Parser p for n times, collect the return values in an array created by the ArrayFactory object.

ArrayFactory a -> int -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFactory object. n the number of times to run. p the Parser object.

Returns: the new Parser object.

retn

public static <R> Parser<R> retn(R r)
The parser that returns value v. It does not consume any input.

a -> Parser a

Parameters: r the value to be returned by the parser.

Returns: the Parser object.

retn

public static <R> Parser<R> retn(String name, R r)
The parser that returns value v. It does not consume any input.

a -> Parser a

Parameters: name the name of the Parser. r the value to be returned by the parser.

Returns: the Parser object.

runnable

public static Parser<?> runnable(String name, Runnable runnable)
To create a Parser that always succeeds and causes a certain side effect using a Runnable object.

Parameters: name the parser name. runnable the Runnable object.

Returns: the Parser object.

runnable

public static Parser<?> runnable(Runnable runnable)
To create a Parser that always succeeds and causes a certain side effect using a Runnable object.

Parameters: runnable the Runnable object.

Returns: the Parser object.

runParser

public static <R> R runParser(CharSequence src, Parser<R> p, PositionMap pmap, String module)
Runs a character level parser with a CharSequence input.

Parameters: src the input source. p the parser object to run. pmap the PositionMap object used to map a character index to line/column number. module the module name. Use any name that's meaningful.

Returns: the result object.

runParser

public static <R> R runParser(CharSequence src, Parser<R> p, String module)
Runs a character level parser with a CharSequence input. The Parser is equivalent to this call and is more convenient.

Parameters: src the input source. p the parser object to run. module the module name. This name apears in error message.

Returns: the result object.

runParser

public static <R> R runParser(Tok[] toks, int end_index, Parser<R> p, ShowToken show, String eof_title, PositionMap pmap, String module)
Runs a token level Parser object with an array of tokens.

[Tok] -> int -> Parser a -> ShowToken -> String -> PositionMap -> a

Parameters: toks the input tokens end_index the index after the last character in the source. p the parser object. show the object to show the tokens. eof_title the name of "end of file". module the module name. Use any name that's meaningful. This value will be shown in any EOF related messages. pmap the PositionMap object to map a character index to the line/column number.

Returns: the return value of the Parser object. (returned by retn() function)

Throws: ParserException when parsing fails.

sepBy

public static Parser<_> sepBy(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token, token, token, token" is sepBy(comma, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy

public static Parser<_> sepBy(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token, token, token, token" is sepBy(comma, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy

public static <R> Parser<R[]> sepBy(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token, token, token, token" is sepBy(comma, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: etype the array element type. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy

public static <R> Parser<R[]> sepBy(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token, token, token, token" is sepBy(comma, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: af the ArrayFacory object. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy

public static <R> Parser<R[]> sepBy(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token, token, token, token" is sepBy(comma, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy

public static <R> Parser<R[]> sepBy(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p can succeed 0 or more times.
For example: pattern "token, token, token, token" is sepBy(comma, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype the array element type. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy1

public static Parser<_> sepBy1(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p has to succeed at least once.
For example: pattern "token, token, token, token" is sepBy1(comma, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy1

public static Parser<_> sepBy1(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p has to succeed at least once.
For example: pattern "token, token, token, token" is sepBy1(comma, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy1

public static <R> Parser<R[]> sepBy1(Class<R> etype, Parser<?> sep, Parser<? extends R> p)

Class -> Parser a -> Parser [Object].
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p has to succeed at least once.
For example: pattern "token, token, token, token" is sepBy1(comma, token).
The return values are collected in an array whose element type is etype.

Parameters: etype the array element type. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy1

public static <R> Parser<R[]> sepBy1(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)

Class -> Parser a -> Parser [Object].
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p has to succeed at least once.
For example: pattern "token, token, token, token" is sepBy1(comma, token).
The return values are collected in an array whose element type is etype.

Parameters: name the name of the new Parser object. etype the array element type. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy1

public static <R> Parser<R[]> sepBy1(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p has to succeed at least once.
For example: pattern "token, token, token, token" is sepBy1(comma, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: af the ArrayFacory object. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepBy1

public static <R,A extends R> Parser<R[]> sepBy1(String name, ArrayFactory<R> af, Parser<?> sep, Parser<A> p)
run a series of Parser p pattern that is seperated by Parser sep pattern.

Parser p has to succeed at least once.
For example: pattern "token, token, token, token" is sepBy1(comma, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. sep the seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy

public static Parser<_> sepEndBy(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p may succeed 0 or more times.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy(semicolon, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy

public static <R> Parser<R[]> sepEndBy(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p may succeed 0 or more times.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy(semicolon, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: etype the array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy

public static <R> Parser<R[]> sepEndBy(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p may succeed 0 or more times.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy(semicolon, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy

public static Parser<_> sepEndBy(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p may succeed 0 or more times.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy(semicolon, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy

public static <R> Parser<R[]> sepEndBy(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p may succeed 0 or more times.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy(semicolon, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype the array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy

public static <R> Parser<R[]> sepEndBy(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p may succeed 0 or more times.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy(semicolon, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy1

public static Parser<_> sepEndBy1(Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p should succeed at least once.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy1(semicolon, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy1

public static Parser<_> sepEndBy1(String name, Parser<?> sep, Parser<?> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p should succeed at least once.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy1(semicolon, token).
The return values are discarded.

Parser ? -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy1

public static <R> Parser<R[]> sepEndBy1(Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p should succeed at least once.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy1(semicolon, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: etype the array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy1

public static <R> Parser<R[]> sepEndBy1(ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p should succeed at least once.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy1(semicolon, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser a -> Parser [a]

Parameters: af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy1

public static <R> Parser<R[]> sepEndBy1(String name, Class<R> etype, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p should succeed at least once.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy1(semicolon, token).
The return values are collected in an array whose element type is etype.

Class -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype the array element type. sep the end seperator. p the Parser object.

Returns: the new Parser object.

sepEndBy1

public static <R> Parser<R[]> sepEndBy1(String name, ArrayFactory<R> af, Parser<?> sep, Parser<? extends R> p)
run a series of Parser p pattern that is seperated and optionally ended by Parser sep pattern.

Parser p should succeed at least once.
For example: patterns "token; token; token; token" and "token;" are both sepEndBy1(semicolon, token).
The return values are collected in an array created by the ArrayFactory object af.

ArrayFactory a -> Parser ? -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. sep the end seperator. p the Parser object.

Returns: the new Parser object.

seq

public static <R> Parser<R> seq(Parser<?> p1, Parser<R> p2)
Sequencing 2 parser objects. The first Parser is executed, if it succeeds, the second Parser is executed.

Parser ? -> Parser b -> Parser b

Parameters: p1 1st Parser. p2 2nd Parser.

Returns: the new Parser.

seq

public static <R> Parser<R> seq(String name, Parser<?> p1, Parser<R> p2)
Sequencing 2 parser objects. The first Parser is executed, if it succeeds, the second Parser is executed.

Parser ? -> Parser b -> Parser b

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser.

Returns: the new Parser.

seq

public static <R> Parser<R> seq(Parser<?> p1, Parser<?> p2, Parser<R> p3)
Sequencing 3 parser objects.

Parser a -> Parser b -> Parser c -> Parser c

Parameters: p1 1st Parser. p2 2nd Parser. p3 3rd Parser.

Returns: the new Parser.

seq

public static <R> Parser<R> seq(String name, Parser<?> p1, Parser<?> p2, Parser<R> p3)
Sequencing 3 parser objects.

Parser a -> Parser b -> Parser c -> Parser c

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser. p3 3rd Parser.

Returns: the new Parser.

seq

public static <R> Parser<R> seq(Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<R> p4)
Sequencing 4 parser objects.

Parser a -> Parser b -> Parser c -> Parser c -> Parser d -> Parser d

Parameters: p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser.

Returns: the new Parser.

seq

public static <R> Parser<R> seq(String name, Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<R> p4)
Sequencing 4 parser objects.

Parser a -> Parser b -> Parser c -> Parser c -> Parser d -> Parser d

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser.

Returns: the new Parser.

seq

public static <R> Parser<R> seq(Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<R> p5)
Sequencing 5 parser objects.

Parser a -> Parser b -> Parser c -> Parser c -> Parser d -> Parser e -> Parser e

Parameters: p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser. p5 5th Parser.

Returns: the new Parser.

seq

public static <R> Parser<R> seq(String name, Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<R> p5)
Sequencing 5 parser objects.

Parser a -> Parser b -> Parser c -> Parser c -> Parser d -> Parser e -> Parser e

Parameters: name the name of the new Parser object. p1 1st Parser. p2 2nd Parser. p3 3rd Parser. p4 4th Parser. p5 5th Parser.

Returns: the new Parser.

seqAll

public static Parser<Object> seqAll(Parser<?>[] ps)
Sequencing of an array of Parser objects. If the array is empty, one() is returned.
The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are discarded.

[Parser ?] -> Parser Object

Parameters: ps the array of Parser objects.

Returns: the new Parser object.

seqAll

public static Parser<Object> seqAll(String name, Parser<?>[] ps)
Sequencing of an array of Parser objects. If the array is empty, one() is returned.
The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are discarded.

[Parser ?] -> Parser Object

Parameters: name the name of the new Parser. ps the array of Parser objects.

Returns: the new Parser object.

sequence

public static Parser<?> sequence(Parser<?>... ps)
Sequencing of an array of Parser objects. If the array is empty, one() is returned.
The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are discarded.

[Parser ?] -> Parser ?

Parameters: ps the array of Parser objects.

Returns: the new Parser object.

Since: version 1.0

sequence

public static Parser<?> sequence(String name, Parser<?>... ps)
Sequencing of an array of Parser objects. If the array is empty, one() is returned.
The array of Parser objects are executed sequentially until an error occured or all the Parsers are executed. Return values are discarded.

[Parser ?] -> Parser ?

Parameters: name the name of the new Parser. ps the array of Parser objects.

Returns: the new Parser object.

Since: version 1.0

setDebug

public static void setDebug(boolean debugged)
enable or disable debugging.

Parameters: debugged true if debugging is enabled, false otherwise.

Since: version 1.1

shorter

public static <R> Parser<R> shorter(String name, Parser<R> p1, Parser<R> p2)
Runs two alternative parsers. If both succeed, the one with the shorter match wins. If both matches the same length, the first one is favored.

Parameters: name the name of the new Parser object. p1 the 1st alternative parser. p2 the 2nd alternative parser.

Returns: the new Parser object.

shorter

public static <R> Parser<R> shorter(Parser<R> p1, Parser<R> p2)
Runs two alternative parsers. If both succeed, the one with the shorter match wins. If both matches the same length, the first one is favored.

Parameters: p1 the 1st alternative parser. p2 the 2nd alternative parser.

Returns: the new Parser object.

shortest

public static <R> Parser<R> shortest(String name, Parser<R>... ps)
Runs an array of alternative parsers. If more than one succeed, the one with the shortest match wins. If two matches have the same length, the first one is favored.

Parameters: name the name of the new Parser object. ps the array of alternative parsers.

Returns: the new Parser object.

shortest

public static <R> Parser<R> shortest(Parser<R>... ps)
Runs an array of alternative parsers. If more than one succeed, the one with the shortest match wins. If two matches have the same length, the first one is favored.

Parameters: ps the array of alternative parsers.

Returns: the new Parser object.

some

public static <R> Parser<_> some(String name, int min, int max, Parser<?> p)
Greedily runs Parser p repeatedly for at least min times and at most max time. The return values are discarded.

int -> int -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. min the minimal number of times to run. max the maximal number of times to run. p the Parser object.

Returns: the new Parser object.

some

public static Parser<_> some(String name, int max, Parser<?> p)
Greedily runs Parser p repeatedly for at most max time. The return values are discarded.

int -> Parser ? -> Parser _

Parameters: name the name of the new Parser object. max the maximal number of times to run. p the Parser object.

Returns: the new Parser object.

some

public static <R> Parser<R[]> some(String name, ArrayFactory<R> af, int min, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and at most max time. The results are collected and returned in an array created by ArrayFactory object.

ArrayFactory a -> int -> int -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. min the minimal number of times to run. max the maximal number of times to run. p the Parser object.

Returns: the new Parser object.

some

public static <R> Parser<R[]> some(String name, ArrayFactory<R> af, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at most max time. The results are collected and returned in an array created by ArrayFactory object.

ArrayFactory a -> int -> Parser a -> Parser [a]

Parameters: name the name of the new Parser object. af the ArrayFacory object. max the maximal number of times to run. p the Parser object.

Returns: the new Parser object.

some

public static <R> Parser<R[]> some(String name, Class<R> etype, int min, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at least min times and at most max times. The return values are collected and returned in an array whose element type is etype.

Class -> int -> int -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype the array element type. min the minimal number of times to run. max the maximal number of times to run. p the Parser object.

Returns: the new Parser object.

some

public static <R> Parser<R[]> some(String name, Class<R> etype, int max, Parser<? extends R> p)
Greedily runs Parser p repeatedly for at most max times. The return values are collected and returned in an array whose element type is etype.

Class -> int -> Parser a -> Parser [Object]

Parameters: name the name of the new Parser object. etype the array element type. max the maximal number of times to run. p the Parser object.

Returns: the new Parser object.

someAccum

public static <From,A extends From,R,To extends R> Parser<R> someAccum(String name, Accumulatable<From,To> accm, int min, int max, Parser<A> p)
Greedily runs Parser p repeatedly for at least min times and at most max times, collect the result with the Accumulator object created by Accumulatable. Fails if p fails and consumes some input or if p throws a pseudo-exception.

Accumulatable a r -> int -> int -> Parser a -> Parser r

Parameters: name the name of the new Parser object. accm the Accumulatable object. min the minimum times to repeat. max the maximum times to repeat. p the Parser object.

Returns: the new Parser object.

someAccum

public static <From,A extends From,R,To extends R> Parser<R> someAccum(String name, Accumulatable<From,To> accm, int max, Parser<A> p)
Greedily runs Parser p repeatedly for at most max times, collect the result with the Accumulator object created by Accumulatable. Fails if p fails and consumes some input or if p throws a pseudo-exception.

Accumulatable a r -> int -> int -> Parser a -> Parser r

Parameters: name the name of the new Parser object. accm the Accumulatable object. max the maximum times to repeat. p the Parser object.

Returns: the new Parser object.

step

public static <R> Parser<R> step(String name, int n, Parser<R> p)
lookahead looks at logical steps. step(String, int, Parser) runs this parser and sets the number of logical steps.

Parameters: name the name of the new Parser object. n the number logical steps. n>=0 has to be true. p the Parser object.

Returns: the new Parser object.

sum

public static Parser<Object> sum(Parser<?>... ps)
An array of alternative Parser objects. zero() is returned if the array is empty. the returned Parser object will try the Parser objects in the array one by one, until one of the following conditioins are met: the Parser succeeds, (sum() succeeds)
the Parser fails with input consumed (sum() fails with input consumed)
the end of array is encountered. (sum() fails with no input consumed).

[Parser a] -> Parser a

Parameters: ps the array of alternative Parser objects.

Returns: the new Parser object.

sum

public static Parser<Object> sum(String name, Parser<?>... ps)
An array of alternative Parser objects. zero() is returned if the array is empty. the returned Parser object will try the Parser objects in the array one by one, until one of the following conditioins are met: the Parser succeeds, (sum() succeeds)
the Parser fails with input consumed (sum() fails with input consumed)
the end of array is encountered. (sum() fails with no input consumed).

[Parser a] -> Parser a

Parameters: name the name of the new Parser object. ps the array of alternative Parser objects.

Returns: the new Parser object.

token

public static <R> Parser<R> token(FromToken<R> ft)
Token level parser. checks the current token with the FromToken object. If the fromToken() method returns null, a system unexpected token error occurs; if the method returns anything other than null, the token is consumed and token() succeeds.

(SourcePos->Token->a) -> Parser a

Parameters: ft the FromToken object.

Returns: the new Parser object.

token

public static <R> Parser<R> token(String name, FromToken<R> ft)
Token level parser. checks the current token with the FromToken object. If the fromToken() method returns null, a system unexpected token error occurs; if the method returns anything other than null, the token is consumed and token() succeeds.

(SourcePos->Object->a) -> Parser a

Parameters: name the name of the new Parser object. ft the FromToken object.

Returns: the new Parser object.

token

public static Parser<Tok> token(Object t)
Token level parser. checks to see if the current token is token t. (using ==). If no, a system unexpected token error occurs; if yes, the token is consumed and token() succeeds. the token is used as the parse result.

Object -> Parser SourcePos

Parameters: t the expected Token object.

Returns: the new Parser object.

token

public static Parser<Tok> token(String name, Object t)
Token level parser. checks to see if the current token is token t. (using ==). If no, a system unexpected token error occurs; if yes, the token is consumed and token() succeeds. the token is used as the parse result.

Token -> Parser SourcePos

Parameters: name the name of the new Parser object. t the expected Token object.

Returns: the new Parser object.

toOne

public static <x> ToParser<x,?> toOne()
Returns a ToParser that ignores the value passed in and simply returns one().

x -> Parser ?

Returns: the ToParser object.

toOne

public static <x> ToParser<x,?> toOne(String name)
Returns a ToParser that ignores the value passed in and simply returns one().

x -> Parser ?

Parameters: name the name of the Parser that ToParser returns.

Returns: the ToParser object.

toParser

public static <x,R> ToParser<x,R> toParser(Parser<R> parser)
Creates a ToParser object by always returning the same Parser object.

Parameters: the type of the input parameter. "x" is used to indicate that this type is irrelevant and we don't use it. the result type of the Parser object. parser the parser object.

Returns: the ToParser object.

Since: version 0.4.1

toReturn

public static <T> ToParser<T,T> toReturn()
Returns a ToParser instance that simply returns the previous return value.

a -> Parser a

Returns: The ToParser object.

toReturn

public static <T> ToParser<T,T> toReturn(String name)
Returns a ToParser instance that simply returns the previous return value.

a -> Parser a

Returns: The ToParser object.

toZero

public static <x,y> ToParser<x,y> toZero()
Returns a ToParser that ignores the value passed in and simply returns zero().

_ -> Parser *

Returns: the ToParser object.

toZero

public static <x,y> ToParser<x,y> toZero(String name)
Returns a ToParser that ignores the value passed in and simply returns zero().

_ -> Parser *

Parameters: name the name of the Parser that ToParser returns.

Returns: the ToParser object.

tryParser

public static <R> Parser<R> tryParser(Parser<R> p, Catch<? extends R> hdl)
if Parser p throws an exception, it is handled by Catch hdl.

Parser a -> Parser a

Parameters: p the Parser object. hdl the exception handler.

Returns: the new Parser object.

tryParser

public static <R> Parser<R> tryParser(String name, Parser<R> p, Catch<? extends R> hdl)
if Parser p throws an exception, it is handled by Catch hdl.

Parser a -> Parser a

Parameters: name the name of the new Parser object. p the Parser object. hdl the exception handler.

Returns: the new Parser object.

tuple

public static <A,B,C> Parser<Tuple3<A,B,C>> tuple(Parser<A> p1, Parser<B> p2, Parser<C> p3)
Sequentially run 3 parser objects and collect the results in a Tuple3 object.

Parameters: p1 the first parser. p2 the second parser. p3 the 3rd parser.

Returns: the result parser

tuple

public static <A,B,C,D> Parser<Tuple4<A,B,C,D>> tuple(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4)
Sequentially run 4 parser objects and collect the results in a Tuple4 object.

Parameters: p1 the first parser. p2 the second parser. p3 the 3rd parser. p4 the 4th parser.

Returns: the result parser

tuple

public static <A,B,C,D,E> Parser<Tuple5<A,B,C,D,E>> tuple(Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5)
Sequentially run 5 parser objects and collect the results in a Tuple5 object.

Parameters: p1 the first parser. p2 the second parser. p3 the 3rd parser. p4 the 4th parser. p5 the 5th parser.

Returns: the result parser

tuple

public static <A,B,C> Parser<Tuple3<A,B,C>> tuple(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3)
Sequentially run 3 parser objects and collect the results in a Tuple3 object.

Parameters: name the result parser name. p1 the first parser. p2 the second parser. p3 the 3rd parser.

Returns: the result parser

tuple

public static <A,B,C,D> Parser<Tuple4<A,B,C,D>> tuple(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4)
Sequentially run 4 parser objects and collect the results in a Tuple4 object.

Parameters: name the result parser name. p1 the first parser. p2 the second parser. p3 the 3rd parser. p4 the 4th parser.

Returns: the result parser

tuple

public static <A,B,C,D,E> Parser<Tuple5<A,B,C,D,E>> tuple(String name, Parser<A> p1, Parser<B> p2, Parser<C> p3, Parser<D> p4, Parser<E> p5)
Sequentially run 5 parser objects and collect the results in a Tuple5 object.

Parameters: name the result parser name. p1 the first parser. p2 the second parser. p3 the 3rd parser. p4 the 4th parser. p5 the 5th parser.

Returns: the result parser

unexpected

public static <x> Parser<x> unexpected(String msg)
Reports an unexpected error.

Parser *

Parameters: msg the error message.

Returns: the new Parser object.

unexpected

public static <x> Parser<x> unexpected(String name, String msg)
Reports an unexpected error.

Parser *

Parameters: name the name of the new Parser object. msg the error message.

Returns: the new Parser object.

zero

public static <x> Parser<x> zero()
The parser that always fails. It does not consume any input.

Parser *

Returns: the Parser object.

zero

public static <x> Parser<x> zero(String name)
The parser that always fails. It does not consume any input.

Parser *

Parameters: name the name of the Parser.

Returns: the Parser object.