jfun.parsec
Class Parsers

java.lang.Object
  extended by jfun.parsec.Parsers

public final class Parsers
extends java.lang.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

Constructor Summary
Parsers()
           
 
Method Summary
static
<T> Parser<T>
alt(Parser<T>... alternatives)
          To create a Parser that runs an array of Parser objects until one succeeds.
static
<T> Parser<T>
alt(java.lang.String name, 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(java.lang.String name)
          Consumes a token.
static
<R> Parser<R>
atomize(java.lang.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(java.lang.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(java.lang.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(java.lang.String name, ToParser<T,T>... binders)
          Threads an array of ToParser into a single ToParser.
static
<T> ToParser<T,T>
bindAll(ToParser<T,T>... binders)
          Threads an array of ToParser into a single ToParser.
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(java.lang.Class<R> etype, Parser<?> sep, Parser<? extends R> p)
          run a series of Parser p pattern ended by Parser sep pattern.
static Parser<_> endBy(Parser<?> sep, Parser<?> p)
          run a series of Parser p pattern ended by Parser sep pattern.
static
<R> Parser<R[]>
endBy(java.lang.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[]>
endBy(java.lang.String name, java.lang.Class<R> etype, Parser<?> sep, Parser<? extends R> p)
          run a series of Parser p pattern ended by Parser sep pattern.
static Parser<_> endBy(java.lang.String name, Parser<?> sep, Parser<?> 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(java.lang.Class<R> etype, 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
<R> Parser<R[]>
endBy1(java.lang.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(java.lang.String name, java.lang.Class<R> etype, Parser<?> sep, Parser<? extends R> p)
          run a series of Parser p pattern ended by Parser sep pattern.
static Parser<_> endBy1(java.lang.String name, Parser<?> sep, Parser<?> p)
          run a series of Parser p pattern ended by Parser sep pattern.
static Parser<?> eof()
          Asserts eof is met.
static Parser<?> eof(java.lang.String msg)
          Asserts eof is met.
static Parser<?> eof(java.lang.String name, java.lang.String msg)
          Asserts eof is met.
static
<x> Parser<x>
expect(java.lang.String lbl)
          Create a Parser object that reports a "something expected" error.
static
<x> Parser<x>
expect(java.lang.String name, java.lang.String lbl)
          Create a Parser object that reports a "something expected" error.
static
<R> Parser<R>
fail(java.lang.String msg)
          A parser that always fail with the given error message.
static
<R> Parser<R>
fail(java.lang.String name, java.lang.String msg)
          A parser that always fail with the given error message.
static
<R> Parser<R>
followedBy(java.lang.String name, Parser<?> sep, Parser<R> p)
          First run Parser p, then run Parser sep.
static Parser<java.lang.Integer> getIndex()
          Retrieves the current index in the source.
static Parser<java.lang.Integer> getIndex(java.lang.String name)
          Retrieves the current index in the source.
static Parser<java.lang.Object> getState()
          Deprecated. as of version 0.6
static Parser<java.lang.Object> getState(java.lang.String name)
          Deprecated. 
static
<C,R> Parser<R>
ifelse(java.lang.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
<C,R> Parser<R>
ifelse(java.lang.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
<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(java.lang.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(java.lang.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(java.lang.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, java.lang.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(java.lang.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(java.lang.String name, Parser<R> p, java.lang.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 boolean isDebugEnabled()
          Is debugging enabled?
static
<R> Parser<R>
isReturn(java.lang.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(java.lang.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(java.lang.String name, Parser<R> p, ObjectPredicate<? super R> op, java.lang.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 Parser<?> isState(ObjectPredicate<java.lang.Object> op)
          Deprecated. as of version 0.6
static Parser<?> isState(java.lang.String name, ObjectPredicate<java.lang.Object> op)
          Deprecated. as of version 0.6
static
<R> Parser<R>
label(java.lang.String name, java.lang.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(Parser<R>[] placeholder)
          Create a lazy evaluated parser.
static
<R> Parser<R>
lazy(Parser<R>[] placeholder, int pos)
          Create a lazy evaluated parser.
static
<R> Parser<R>
lazy(ParserEval<R> p)
          Create a lazy evaluated Parser.
static
<R> Parser<R>
lazy(java.lang.String name, ParserEval<R> p)
          Create a lazy evaluated Parser.
static
<R> Parser<R>
longer(Parser<R> p1, Parser<R> p2)
          Runs two alternative parsers.
static
<R> Parser<R>
longer(java.lang.String name, Parser<R> p1, Parser<R> p2)
          Runs two alternative parsers.
static
<R> Parser<R>
longest(Parser<R>... ps)
          Runs an array of alternative parsers.
static
<R> Parser<R>
longest(java.lang.String name, Parser<R>... ps)
          Runs an array of alternative parsers.
static
<R> Parser<R>
lookahead(java.lang.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.
static
<R> Parser<R[]>
many(java.lang.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(java.lang.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
<R> Parser<R[]>
many(java.lang.String name, java.lang.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(java.lang.String name, java.lang.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<_>
many(java.lang.String name, int min, Parser<?> p)
          Greedily runs Parser p repeatedly for at least min times and discard the results.
static Parser<_> many(java.lang.String name, Parser<?> p)
          Greedily runs Parser p repeatedly and discard the results.
static
<From,A extends From,R,To extends R>
Parser<R>
manyAccum(java.lang.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(java.lang.String name, Accumulatable<From,To> accm, Parser<A> p)
          Greedily runs Parser p repeatedly for 0 or more times.
static
<R,From> Parser<R>
map(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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
<E,R> Parser<R>
mapn(ArrayFactory<?> af, Parser<?>[] ps, Mapn<R> mn)
          Sequencing of an array of Parser objects.
static
<E,R> Parser<R>
mapn(java.lang.Class<? super E> etype, Parser<E>[] ps, Mapn<R> mn)
          Sequencing of an array of Parser objects.
static
<R> Parser<R>
mapn(Parser<?>[] ps, Mapn<R> mn)
          Sequencing of an array of Parser objects.
static
<R> Parser<R>
mapn(java.lang.String name, ArrayFactory<?> af, Parser<?>[] ps, Mapn<R> mn)
          Sequencing of an array of Parser objects.
static
<E,R> Parser<R>
mapn(java.lang.String name, java.lang.Class<? super E> etype, Parser<E>[] ps, Mapn<R> mn)
          Sequencing of an array of Parser objects.
static
<R> Parser<R>
mapn(java.lang.String name, Parser<?>[] ps, Mapn<R> mn)
          Sequencing of an array of Parser objects.
static Parser<?> not(java.lang.String name, Parser<?> p)
          Succeeds if Parser p fails; Fails otherwise.
static Parser<?> not(java.lang.String name, Parser<?> p, java.lang.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, java.lang.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(java.lang.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(java.lang.String name, Parser<R> p, java.lang.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(java.lang.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(java.lang.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(java.lang.String name, Parser<R> p)
          Runs Parser p, if it fails with no input consumed, succeed anyway with null as result.
static Parser<java.lang.Object> or(Parser<?>... alternatives)
          To create a Parser that runs an array of Parser objects until one succeeds.
static Parser<java.lang.Object> or(java.lang.String name, 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(java.lang.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, java.lang.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(java.lang.String name, Parser<Tok[]> lexer, Parser<R> p, java.lang.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(java.lang.String eof_title, ShowToken show, Parser<Tok[]> lexer, Parser<R> p, java.lang.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(java.lang.String name, java.lang.String eof_title, ShowToken show, Parser<Tok[]> lexer, Parser<R> p, java.lang.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(java.lang.String name, Parser<R> p)
          Look ahead with Parser p.
static
<R> Parser<R>
plus(Parser<R>... ps)
          combine alternative parser objects.
static
<R> Parser<R>
plus(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(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(java.lang.String name, Parser<R>... ps)
          combine alternative parser objects.
static
<R> Parser<R>
plus(java.lang.String name, Parser<R> p1, Parser<? extends R> p2)
          2 alternative parser objects.
static
<R> Parser<R>
plus(java.lang.String name, Parser<R> p1, Parser<? extends R> p2, Parser<? extends R> p3)
          3 alternative parser objects.
static
<R> Parser<R>
plus(java.lang.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(java.lang.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
<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(java.lang.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(java.lang.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(java.lang.Object e)
          throws a pseudo-exception.
static
<R> Parser<R>
raise(java.lang.String name, java.lang.Object e)
          throws a pseudo-exception.
static
<R> Parser<R[]>
repeat(java.lang.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[]>
repeat(java.lang.String name, java.lang.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 Parser<_> repeat(java.lang.String name, int n, Parser<?> p)
          Runs Parser p for n times.
static
<R> Parser<R>
retn(R r)
          The parser that returns value v.
static
<R> Parser<R>
retn(java.lang.String name, R r)
          The parser that returns value v.
static Parser<?> runnable(java.lang.Runnable runnable)
          To create a Parser that always succeeds and causes a certain side effect using a Runnable object.
static Parser<?> runnable(java.lang.String name, java.lang.Runnable runnable)
          To create a Parser that always succeeds and causes a certain side effect using a Runnable object.
static
<R> R
runParser(java.lang.CharSequence src, Parser<R> p, PositionMap pmap, java.lang.String module)
          Runs a character level parser with a CharSequence input.
static
<R> R
runParser(java.lang.CharSequence src, Parser<R> p, java.lang.String module)
          Runs a character level parser with a CharSequence input.
static
<R> R
runParser(Tok[] toks, int end_index, Parser<R> p, ShowToken show, java.lang.String eof_title, PositionMap pmap, java.lang.String module)
          Runs a token level Parser object with an array of tokens.
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(java.lang.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<_> sepBy(Parser<?> sep, Parser<?> p)
          run a series of Parser p pattern that is seperated by Parser sep pattern.
static
<R> Parser<R[]>
sepBy(java.lang.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(java.lang.String name, java.lang.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<_> sepBy(java.lang.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(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[]>
sepBy1(java.lang.Class<R> etype, Parser<?> sep, Parser<? extends R> p)
           Class -> Parser a -> Parser [Object].
static Parser<_> sepBy1(Parser<?> sep, Parser<?> p)
          run a series of Parser p pattern that is seperated by Parser sep pattern.
static
<R,A extends R>
Parser<R[]>
sepBy1(java.lang.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
<R> Parser<R[]>
sepBy1(java.lang.String name, java.lang.Class<R> etype, Parser<?> sep, Parser<? extends R> p)
           Class -> Parser a -> Parser [Object].
static Parser<_> sepBy1(java.lang.String name, Parser<?> sep, Parser<?> p)
          run a series of Parser p pattern that is seperated 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
<R> Parser<R[]>
sepEndBy(java.lang.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 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(java.lang.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[]>
sepEndBy(java.lang.String name, java.lang.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 Parser<_> sepEndBy(java.lang.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(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(java.lang.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 Parser<_> sepEndBy1(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(java.lang.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[]>
sepEndBy1(java.lang.String name, java.lang.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 Parser<_> sepEndBy1(java.lang.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>
seq(Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<R> p5)
          Sequencing 5 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(Parser<?> p1, Parser<?> p2, Parser<R> p3)
          Sequencing 3 parser objects.
static
<R> Parser<R>
seq(Parser<?> p1, Parser<R> p2)
          Sequencing 2 parser objects.
static
<R> Parser<R>
seq(java.lang.String name, Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<R> p5)
          Sequencing 5 parser objects.
static
<R> Parser<R>
seq(java.lang.String name, Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<R> p4)
          Sequencing 4 parser objects.
static
<R> Parser<R>
seq(java.lang.String name, Parser<?> p1, Parser<?> p2, Parser<R> p3)
          Sequencing 3 parser objects.
static
<R> Parser<R>
seq(java.lang.String name, Parser<?> p1, Parser<R> p2)
          Sequencing 2 parser objects.
static Parser<java.lang.Object> seqAll(Parser<?>[] ps)
          Sequencing of an array of Parser objects.
static Parser<java.lang.Object> seqAll(java.lang.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(java.lang.String name, Parser<?>... ps)
          Sequencing of an array of Parser objects.
static void setDebug(boolean debugged)
          enable or disable debugging.
static Parser<java.lang.Object> setState(java.lang.Object s)
          Deprecated. as of version 0.6
static Parser<java.lang.Object> setState(java.lang.String name, java.lang.Object s)
          Deprecated. as of version 0.6
static
<R> Parser<R>
shorter(Parser<R> p1, Parser<R> p2)
          Runs two alternative parsers.
static
<R> Parser<R>
shorter(java.lang.String name, Parser<R> p1, Parser<R> p2)
          Runs two alternative parsers.
static
<R> Parser<R>
shortest(Parser<R>... ps)
          Runs an array of alternative parsers.
static
<R> Parser<R>
shortest(java.lang.String name, Parser<R>... ps)
          Runs an array of alternative parsers.
static
<R> Parser<R[]>
some(java.lang.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(java.lang.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(java.lang.String name, java.lang.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(java.lang.String name, java.lang.Class<R> etype, int max, Parser<? extends R> p)
          Greedily runs Parser p repeatedly for at most max times.
static
<R> Parser<_>
some(java.lang.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(java.lang.String name, int max, Parser<?> p)
          Greedily runs Parser p repeatedly for at most max time.
static
<From,A extends From,R,To extends R>
Parser<R>
someAccum(java.lang.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(java.lang.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(java.lang.String name, int n, Parser<R> p)
          lookahead looks at logical steps.
static Parser<java.lang.Object> sum(Parser<?>... ps)
          An array of alternative Parser objects.
static Parser<java.lang.Object> sum(java.lang.String name, Parser<?>... ps)
          An array of alternative Parser objects.
static
<R> Parser<R>
token(FromToken<R> ft)
          Token level parser.
static Parser<Tok> token(java.lang.Object t)
          Token level parser.
static
<R> Parser<R>
token(java.lang.String name, FromToken<R> ft)
          Token level parser.
static Parser<Tok> token(java.lang.String name, java.lang.Object t)
          Token level parser.
static
<x> ToParser<x,?>
toOne()
          Returns a ToParser that ignores the value passed in and simply returns one().
static
<x> ToParser<x,?>
toOne(java.lang.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(java.lang.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(java.lang.String name)
          Returns a ToParser that ignores the value passed in and simply returns zero().
static
<State> Parser<State>
transformState(Map<State,?> m)
          Deprecated. as of version 0.6
static
<State> Parser<State>
transformState(java.lang.String name, Map<State,?> m)
          Deprecated. as of version 0.6
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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String msg)
          Reports an unexpected error.
static
<x> Parser<x>
unexpected(java.lang.String name, java.lang.String msg)
          Reports an unexpected error.
static
<x> Parser<x>
zero()
          The parser that always fails.
static
<x> Parser<x>
zero(java.lang.String name)
          The parser that always fails.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parsers

public Parsers()
Method Detail

isDebugEnabled

public static boolean isDebugEnabled()
Is debugging enabled?

Since:
version 1.1

setDebug

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

Parameters:
debugged - true if debugging is enabled, false otherwise.
Since:
version 1.1

runParser

public static <R> R runParser(java.lang.CharSequence src,
                              Parser<R> p,
                              PositionMap pmap,
                              java.lang.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(java.lang.CharSequence src,
                              Parser<R> p,
                              java.lang.String module)
Runs a character level parser with a CharSequence input. The Parser.parse(CharSequence, String) 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,
                              java.lang.String eof_title,
                              PositionMap pmap,
                              java.lang.String module)
                   throws ParserException
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.

runnable

public static Parser<?> runnable(java.lang.String name,
                                 java.lang.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(java.lang.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.

parseTokens

public static <R> Parser<R> parseTokens(Parser<Tok[]> lexer,
                                        Parser<R> p,
                                        java.lang.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(java.lang.String name,
                                        Parser<Tok[]> lexer,
                                        Parser<R> p,
                                        java.lang.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(java.lang.String eof_title,
                                        ShowToken show,
                                        Parser<Tok[]> lexer,
                                        Parser<R> p,
                                        java.lang.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(java.lang.String name,
                                        java.lang.String eof_title,
                                        ShowToken show,
                                        Parser<Tok[]> lexer,
                                        Parser<R> p,
                                        java.lang.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.

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(java.lang.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.

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(java.lang.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.

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(java.lang.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.

bind

public static <From,To> Parser<To> bind(java.lang.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.

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(java.lang.String name)
Returns a ToParser instance that simply returns the previous return value.

a -> Parser a

Returns:
The ToParser 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(java.lang.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.

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(java.lang.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.

toParser

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

Type Parameters:
x - the type of the input parameter. "x" is used to indicate that this type is irrelevant and we don't use it.
R - the result type of the Parser object.
Parameters:
parser - the parser object.
Returns:
the ToParser object.
Since:
version 0.4.1

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(java.lang.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.

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(java.lang.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(java.lang.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(java.lang.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(java.lang.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.

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.

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

pair

public static <A,B> Parser<Pair<A,B>> pair(java.lang.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.

tuple

public static <A,B,C> Parser<Tuple3<A,B,C>> tuple(java.lang.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(java.lang.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(java.lang.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

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(java.lang.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

seqAll

public static Parser<java.lang.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<java.lang.Object> seqAll(java.lang.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.

isReturn

public static <R> Parser<R> isReturn(java.lang.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(java.lang.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(java.lang.String name,
                                     Parser<R> p,
                                     ObjectPredicate<? super R> op,
                                     java.lang.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.

isState

@Deprecated
public static Parser<?> isState(ObjectPredicate<java.lang.Object> op)
Deprecated. as of version 0.6

Fails if the current user state value does not satisify the given predicate. No-op otherwise.

Parameters:
op - the predicate object.
Returns:
the new Parser object.

isState

@Deprecated
public static Parser<?> isState(java.lang.String name,
                                           ObjectPredicate<java.lang.Object> op)
Deprecated. as of version 0.6

Fails if the current user state value 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.

step

public static <R> Parser<R> step(java.lang.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.

lookahead

public static <R> Parser<R> lookahead(java.lang.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.

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(java.lang.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(java.lang.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(java.lang.String name,
                                   java.lang.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(java.lang.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.

fail

public static <R> Parser<R> fail(java.lang.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(java.lang.String name,
                                 java.lang.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.

ifelse

public static <C,R> Parser<R> ifelse(java.lang.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(java.lang.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.

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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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.

sum

public static Parser<java.lang.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<java.lang.Object> sum(java.lang.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.

longer

public static <R> Parser<R> longer(java.lang.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.

longest

public static <R> Parser<R> longest(java.lang.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.

shorter

public static <R> Parser<R> shorter(java.lang.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.

shortest

public static <R> Parser<R> shortest(java.lang.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.

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(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.

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(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.

or

public static Parser<java.lang.Object> or(java.lang.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<java.lang.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.

alt

public static <T> Parser<T> alt(java.lang.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.

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,
                                       java.lang.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(java.lang.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(java.lang.String name,
                                       Parser<R> p,
                                       java.lang.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.

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,
                                        java.lang.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(java.lang.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(java.lang.String name,
                                        Parser<R> p,
                                        java.lang.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.

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(java.lang.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.

getState

@Deprecated
public static Parser<java.lang.Object> getState()
Deprecated. as of version 0.6

Retrieves the user state.

Parser u u

Returns:
the Parser object.

getState

@Deprecated
public static Parser<java.lang.Object> getState(java.lang.String name)
Deprecated. 

Retrieves the user state.

Parser u u

Parameters:
name - the name of the Parser object.
Returns:
the Parser object.

setState

@Deprecated
public static Parser<java.lang.Object> setState(java.lang.Object s)
Deprecated. as of version 0.6

Updates the user state. The old user state value is returned.

Parser u1 u

Parameters:
s - the new user state value.
Returns:
the Parser object.

setState

@Deprecated
public static Parser<java.lang.Object> setState(java.lang.String name,
                                                           java.lang.Object s)
Deprecated. as of version 0.6

Updates the user state.

Parser u1 u

Parameters:
name - the name of the Parser object.
s - the new user state value.
Returns:
the Parser object.

transformState

@Deprecated
public static <State> Parser<State> transformState(Map<State,?> m)
Deprecated. as of version 0.6

Transforms and updates the user state. The old user state value is returned.

(u1->u2) -> Parser u2 u1

Parameters:
m - the transformation.
Returns:
the Parser object.

transformState

@Deprecated
public static <State> Parser<State> transformState(java.lang.String name,
                                                              Map<State,?> m)
Deprecated. as of version 0.6

Transforms and updates the user state. The old user state value is returned.

(u1->u2) -> Parser u2 u1

Parameters:
name - the name of the Parser object.
m - the transformation.
Returns:
the Parser object.

getIndex

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

Parser Integer

Returns:
the Parser object.

getIndex

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

Parser Integer

Parameters:
name - the name of the Parser object.
Returns:
the Parser object.

peek

public static <R> Parser<R> peek(java.lang.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.

atomize

public static <R> Parser<R> atomize(java.lang.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.

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(java.lang.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.

map

public static <R,From> Parser<R> map(java.lang.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.

unexpected

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

Parser *

Parameters:
msg - the error message.
Returns:
the new Parser object.

unexpected

public static <x> Parser<x> unexpected(java.lang.String name,
                                       java.lang.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.

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(java.lang.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(java.lang.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(java.lang.String name,
                                java.lang.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.

label

public static <R> Parser<R> label(java.lang.String name,
                                  java.lang.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.

expect

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

Type Parameters:
x - the result Parser object is good for any result type. (it does not return anyway)
Parameters:
name - the parser name.
lbl - the label.
Returns:
the Parser object.
Since:
version 0.6

expect

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

Type Parameters:
x - the result Parser object is good for any result type. (it does not return anyway)
Parameters:
lbl - the label.
Returns:
the Parser object.
Since:
version 0.6

raise

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

Parser *

Parameters:
e - the exception object.
Returns:
the Parser object.

raise

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

Parser *

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

manyAccum

public static <From,A extends From,R,To extends R> Parser<R> manyAccum(java.lang.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(java.lang.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.

someAccum

public static <From,A extends From,R,To extends R> Parser<R> someAccum(java.lang.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(java.lang.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.

eof

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

Parser ?

Returns:
the Parser object.

eof

public static Parser<?> eof(java.lang.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(java.lang.String name,
                            java.lang.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.

not

public static Parser<?> not(java.lang.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(java.lang.String name,
                            Parser<?> p,
                            java.lang.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.

many

public static <R> Parser<_> many(java.lang.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(java.lang.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(java.lang.String name,
                                   java.lang.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(java.lang.String name,
                                   java.lang.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(java.lang.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(java.lang.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.

some

public static <R> Parser<_> some(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String name,
                                   java.lang.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(java.lang.String name,
                                   java.lang.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.

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(java.lang.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(java.lang.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(java.lang.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(java.lang.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.

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(java.lang.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(java.lang.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.

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(java.lang.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.

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(java.lang.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(java.lang.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(java.lang.String name,
                                     java.lang.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(java.lang.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.

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(java.lang.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(java.lang.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(java.lang.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(java.lang.String name,
                                    java.lang.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.

followedBy

public static <R> Parser<R> followedBy(java.lang.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.

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(java.lang.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(java.lang.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(java.lang.String name,
                                    java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String name,
                                     java.lang.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.

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(java.lang.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(java.lang.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(java.lang.String name,
                                       java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String name,
                                        java.lang.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(java.lang.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.

repeat

public static Parser<_> repeat(java.lang.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(java.lang.String name,
                                     java.lang.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(java.lang.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.

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(java.lang.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.

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(java.lang.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.

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(java.lang.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.

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(java.lang.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.

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(java.lang.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.

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(java.lang.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.