I
- the input stream symbol typeA
- the parser result typepublic interface Parser<I,A>
Result
.
The Parser
type along with the pure
and ap
functions constitute an applicative functor.Modifier and Type | Method and Description |
---|---|
Lazy<Boolean> |
acceptsEmpty()
Indicate whether this parser accepts the empty symbol.
|
default <B> ApplyBuilder._2<I,A,B> |
and(Parser<I,B> pb)
Combine this parser with another to form a builder which accumulates the parse results.
|
default <B> Parser<I,A> |
andL(Parser<I,B> pb)
Combine this parser with another to form a parser which applies two parsers,
and if they are both successful
throws away the result of the right-hand parser,
and returns the result of the left-hand parser
|
default <B> Parser<I,B> |
andR(Parser<I,B> pb)
Combine this parser with another to form a parser which applies two parsers,
and if they are both successful
throws away the result of the left-hand parser
and returns the result of the right-hand parser
|
static <I,A,B> Parser<I,B> |
ap(Functions.F<A,B> f,
Parser<I,A> pa)
Construct a parser that, if
pa succeeds, yielding a function a ,
then it returns the result of applying function f to value a . |
static <I,A,B> Parser<I,B> |
ap(Parser<I,Functions.F<A,B>> pf,
Parser<I,A> pa)
Construct a parser that, if
pf succeeds, yielding a function f ,
and if pa succeeds, yielding a value a ,
then it returns the result of applying function f to value a . |
default Result<I,A> |
apply(Input<I> in)
Apply this parser to the input stream.
|
Result<I,A> |
apply(Input<I> in,
SymSet<I> follow)
Apply this parser to the input stream.
|
default <OPEN,CLOSE> |
between(Parser<I,OPEN> open,
Parser<I,CLOSE> close)
A parser for expressions with enclosing symbols.
|
default <B> Parser<I,B> |
cast() |
default Parser<I,A> |
chainl(Parser<I,Functions.Op2<A>> op,
A a)
A parser for an operand, followed by zero or more operands that are separated by operators.
|
default Parser<I,A> |
chainl1(Parser<I,Functions.Op2<A>> op)
A parser for an operand, followed by one or more operands that are separated by operators.
|
default Parser<I,A> |
chainr(Parser<I,Functions.Op2<A>> op,
A a)
A parser for an operand, followed by zero or more operands that are separated by operators.
|
default Parser<I,A> |
chainr1(Parser<I,Functions.Op2<A>> op)
A parser for an operand, followed by one or more operands that are separated by operators.
|
static <I,A> Parser<I,A> |
choice(IList.NonEmpty<Parser<I,A>> ps)
A parser that attempts one or more parsers in turn and returns the result
of the first that succeeds, or else fails.
|
static <I,A> Parser<I,A> |
choice(Parser<I,A>... ps)
A parser that attempts one or more parsers in turn and returns the result
of the first that succeeds, or else fails.
|
Lazy<SymSet<I>> |
firstSet()
The First Set for this parser.
|
default Parser<I,IList<A>> |
many()
A parser which repeatedly applies this parser until it fails,
and then returns an
IList of the results. |
default Parser<I,IList.NonEmpty<A>> |
many1()
A parser which applies this parser one or more times until it fails,
and then returns an
IList of the results. |
default <B> Parser<I,IList<A>> |
manyTill(Parser<I,B> end)
A parser which repeatedly applies this parser until the end parser succeeds,
and then returns an
IList of the results. |
default <B> Parser<I,B> |
map(Functions.F<A,B> f)
Construct a parser that, if this parser succeeds then returns the result
of applying the function
f to the result,
otherwise return the failure. |
default Parser<I,Optional<A>> |
optional()
A parser that applies this parser, and, if it succeeds,
returns the result wrapped in an
Optional ,
otherwise returns an empty Optional . |
default <B extends A> |
or(Parser<I,B> rhs)
Construct a parser which returns the result of either this parser or,
if it fails, then the result of the
rhs parser. |
default Result<I,A> |
parse(Input<I> in)
Apply this parser to the input stream.
|
static <I,A> Parser<I,A> |
pure(A a)
Applicative unit/pure function.
|
static <I,A> Ref<I,A> |
ref()
Construct an uninitialised parser reference object.
|
static <I,A> Ref<I,A> |
ref(Parser<I,A> p)
Construct a parser reference object from a parser.
|
default <SEP> Parser<I,IList<A>> |
sepBy(Parser<I,SEP> sep)
A parser which applies this parser zero or more times until it fails,
alternating with calls to the
sep parser. |
default <SEP> Parser<I,IList<A>> |
sepBy1(Parser<I,SEP> sep)
A parser which applies this parser one or more times until it fails,
alternating with calls to the
sep parser. |
static <I,T> Parser<I,IList<T>> |
sequence(IList<Parser<I,T>> lpt)
Standard applicative sequencing.
|
static <E,T> Parser<E,Stream<T>> |
sequence(Stream<Parser<E,T>> spt)
Variation of
sequence(IList) for Stream . |
default Parser<I,Unit> |
skipMany()
A parser which applies this parser zero or more times until it fails,
and throws away the results.
|
static <I,T,U> Parser<I,IList<U>> |
traverse(IList<T> lt,
Functions.F<T,Parser<I,U>> f)
Standard applicative traversal.
|
static <I,A> Ref<I,A> ref()
I
- the input stream symbol typeA
- the parser result typestatic <I,A> Ref<I,A> ref(Parser<I,A> p)
I
- the input stream symbol typeA
- the parser result typep
- the parserstatic <I,A> Parser<I,A> pure(A a)
I
- the input stream symbol typeA
- the parser result typea
- the valuestatic <I,A,B> Parser<I,B> ap(Parser<I,Functions.F<A,B>> pf, Parser<I,A> pa)
pf
succeeds, yielding a function f
,
and if pa
succeeds, yielding a value a
,
then it returns the result of applying function f
to value a
.
Otherwise, if pf
fails then the parser returns the failure,
else if pa
fails then it returns that failure.I
- the input stream symbol typeA
- the input type of the functionB
- the return type of the functionpf
- the parser that returns a function resultpa
- the parser that returns a value resultstatic <I,A,B> Parser<I,B> ap(Functions.F<A,B> f, Parser<I,A> pa)
pa
succeeds, yielding a function a
,
then it returns the result of applying function f
to value a
.
If pa
fails then the parser returns the failure.I
- the input stream symbol typeA
- the input type of the functionB
- the return type of the functionf
- the functionpa
- the parser that returns a value resultstatic <I,T,U> Parser<I,IList<U>> traverse(IList<T> lt, Functions.F<T,Parser<I,U>> f)
Equivalent to
sequence(lt.map(f)).
I
- the error typeT
- the type of list elementsU
- the type wrapped by the Try
returned by the functionlt
- the list of valuesf
- the function to be applied to each value in the listParser
which wraps an IList
of valuesstatic <I,T> Parser<I,IList<T>> sequence(IList<Parser<I,T>> lpt)
Translate a IList
of Parser
into a Parser
of an IList
,
by composing each consecutive Parser
using the ap(Parser, Parser)
method.
I
- the error typeT
- the value type of the Parser
s in the listlpt
- the list of Parser
valuesParser
which wraps an IList
of valuesstatic <E,T> Parser<E,Stream<T>> sequence(Stream<Parser<E,T>> spt)
sequence(IList)
for Stream
.E
- the error typeT
- the value type of the Parser
s in the streamspt
- the stream of Parser
valuesParser
which wraps an Stream
of valuesdefault Result<I,A> parse(Input<I> in)
in
- the input streamLazy<Boolean> acceptsEmpty()
Result<I,A> apply(Input<I> in, SymSet<I> follow)
parse(Input)
to parse an input.in
- the input streamfollow
- the dynamic follow setdefault Result<I,A> apply(Input<I> in)
parse(Input)
to parse an input.in
- the input streamdefault <B> Parser<I,B> map(Functions.F<A,B> f)
f
to the result,
otherwise return the failure.B
- the function return typef
- the function to be mapped over this parserf
mapped over this parser's resultdefault <B extends A> Parser<I,A> or(Parser<I,B> rhs)
rhs
parser.B
- the rhs parser result typerhs
- the second parser to attemptrhs
parser.default <B> ApplyBuilder._2<I,A,B> and(Parser<I,B> pb)
B
- the result type of second parserpb
- the second parserApplyBuilder
which accumulates the parse results.default <B> Parser<I,A> andL(Parser<I,B> pb)
B
- the result type of second parserpb
- the second parserdefault <B> Parser<I,B> andR(Parser<I,B> pb)
B
- the result type of second parserpb
- the second parserdefault Parser<I,IList<A>> many()
IList
of the results.
If this parser fails on the first attempt then the parser succeeds,
with an empty list of results.default <B> Parser<I,IList<A>> manyTill(Parser<I,B> end)
IList
of the results.B
- the result type of the end parserend
- the end parserstatic <I,A> Parser<I,A> choice(IList.NonEmpty<Parser<I,A>> ps)
I
- the input stream symbol typeA
- the parser result typeps
- the list of parsers@SafeVarargs static <I,A> Parser<I,A> choice(Parser<I,A>... ps)
I
- the input stream symbol typeA
- the parser result typeps
- the list of parsersdefault Parser<I,IList.NonEmpty<A>> many1()
IList
of the results.
Note, if this parser fails on the first attempt then the parser fails.default Parser<I,Unit> skipMany()
default <SEP> Parser<I,IList<A>> sepBy(Parser<I,SEP> sep)
sep
parser.
The results of this parser are collected in a IList
and returned by the parser.SEP
- the separator typesep
- the separator parsersep
default <SEP> Parser<I,IList<A>> sepBy1(Parser<I,SEP> sep)
sep
parser.
The results of this parser are collected in a IList
and returned by the parser.SEP
- the separator typesep
- the separator parsersep
default Parser<I,Optional<A>> optional()
Optional
,
otherwise returns an empty Optional
.default <OPEN,CLOSE> Parser<I,A> between(Parser<I,OPEN> open, Parser<I,CLOSE> close)
A parser which applies the open
parser, then this parser,
and then close
parser.
If all three succeed then the result of this parser is returned.
OPEN
- the open parser result typeCLOSE
- the close parser result typeopen
- the open symbol parserclose
- the close symbol parserdefault Parser<I,A> chainr(Parser<I,Functions.Op2<A>> op, A a)
op
- the parser for the operatora
- the value to return if there are no operandsdefault Parser<I,A> chainr1(Parser<I,Functions.Op2<A>> op)
op
- the parser for the operatordefault Parser<I,A> chainl(Parser<I,Functions.Op2<A>> op, A a)
op
- the parser for the operatora
- the value to return if there are no operandsdefault Parser<I,A> chainl1(Parser<I,Functions.Op2<A>> op)
op
- the parser for the operatorCopyright © 2019. All rights reserved.