Package fj.parser
Class Parser<I,A,E>
java.lang.Object
fj.parser.Parser<I,A,E>
A parser is a function that takes some input (I) and produces either an error (E) or a parse result (A) and the
remainder of the input.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Parsers that acceptStream<Character>
input.static final class
Parsers that acceptStream
input. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPerforms function application within a parser.Binds the given function across the parser with a final join.Binds the given function across the parsers with a final join.Binds the given function across the parsers with a final join.Binds the given function across the parsers with a final join.bind
(Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, F<A, F<B, F<C, F<D, F<E$, F$>>>>> f) Binds the given function across the parsers with a final join.bind
(Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, Parser<I, F$, E> pf, F<A, F<B, F<C, F<D, F<E$, F<F$, G>>>>>> f) Binds the given function across the parsers with a final join.bind
(Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, Parser<I, F$, E> pf, Parser<I, G, E> pg, F<A, F<B, F<C, F<D, F<E$, F<F$, F<G, H>>>>>>> f) Binds the given function across the parsers with a final join.bind
(Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, Parser<I, F$, E> pf, Parser<I, G, E> pg, Parser<I, H, E> ph, F<A, F<B, F<C, F<D, F<E$, F<F$, F<G, F<H, I$>>>>>>>> f) Binds the given function across the parsers with a final join.static <I,
A, E> Parser <I, A, E> fail
(E e) Returns a parser that always fails with the given error.Returns a parser that fails with the given error if the result value does not meet the given predicate.Maps the given result type across this parser.Maps the given function across this parser's error.Returns a parser that negates this parser.Returns a parser that negates this parser.Returns a parser that tries this parser and if it fails, then tries the given parser.Returns a parser that tries this parser and if it fails, then tries the given parser.Returns a parser that tries this parser and if it fails, then tries the given parser.Returns a parser that tries this parser and if it fails, then tries the given parser.Validation
<E, Result<I, A>> Parses the input to produce a result or error.static <I,
A, E> Parser <I, A, E> parser
(F<I, Validation<E, Result<I, A>>> f) Returns a parser that computes using the given function.repeat()
Returns a parser that repeats application of this parser zero or many times.repeat1()
Returns a parser that repeats application of this parser one or many times.Sequence the list of parsers throughbind(fj.F<A, fj.parser.Parser<I, B, E>>)
.Binds anonymously, ignoring the result value.static <I,
A, E> Parser <I, A, E> value
(A a) Constructs a parser that always returns the given value.Maps the parse input type through an invariant functor.
-
Field Details
-
f
-
-
Constructor Details
-
Parser
-
-
Method Details
-
parse
Parses the input to produce a result or error.- Parameters:
i
- The input to parse.- Returns:
- A parse result with the remaining input or an error.
-
xmap
Maps the parse input type through an invariant functor.- Parameters:
f
- The function to covariant map.g
- The function to contra-variant map.- Returns:
- A parser with the new input type.
-
map
Maps the given result type across this parser.- Parameters:
f
- The function to map.- Returns:
- A parser with the new result type.
-
filter
Returns a parser that fails with the given error if the result value does not meet the given predicate.- Parameters:
f
- The predicate to filter on.e
- The error to in the event that the predicate is not met.- Returns:
- A parser that fails with the given error if the result value does not meet the given predicate.
-
bind
Binds the given function across the parser with a final join.- Parameters:
f
- The function to apply to the element of this parser.- Returns:
- A new parser after performing the map, then final join.
-
bind
Binds the given function across the parsers with a final join.- Parameters:
pb
- A given parser to bind the given function with.f
- The function to apply to the element of the parsers.- Returns:
- A new parser after performing the map, then final join.
-
bind
Binds the given function across the parsers with a final join.- Parameters:
pb
- A given parser to bind the given function with.pc
- A given parser to bind the given function with.f
- The function to apply to the element of the parsers.- Returns:
- A new parser after performing the map, then final join.
-
bind
public <B,C, Parser<I,D, E$> E$, bindE> (Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, F<A, F<B, F<C, F<D, E$>>>> f) Binds the given function across the parsers with a final join.- Parameters:
pb
- A given parser to bind the given function with.pc
- A given parser to bind the given function with.pd
- A given parser to bind the given function with.f
- The function to apply to the element of the parsers.- Returns:
- A new parser after performing the map, then final join.
-
bind
public <B,C, Parser<I,D, E$, F$> F$, bindE> (Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, F<A, F<B, F<C, F<D, F<E$, F$>>>>> f) Binds the given function across the parsers with a final join.- Parameters:
pb
- A given parser to bind the given function with.pc
- A given parser to bind the given function with.pd
- A given parser to bind the given function with.pe
- A given parser to bind the given function with.f
- The function to apply to the element of the parsers.- Returns:
- A new parser after performing the map, then final join.
-
bind
public <B,C, Parser<I,D, E$, F$, G> G, bindE> (Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, Parser<I, F$, E> pf, F<A, F<B, F<C, F<D, F<E$, F<F$, G>>>>>> f) Binds the given function across the parsers with a final join.- Parameters:
pb
- A given parser to bind the given function with.pc
- A given parser to bind the given function with.pd
- A given parser to bind the given function with.pe
- A given parser to bind the given function with.pf
- A given parser to bind the given function with.f
- The function to apply to the element of the parsers.- Returns:
- A new parser after performing the map, then final join.
-
bind
public <B,C, Parser<I,D, E$, F$, G, H> H, bindE> (Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, Parser<I, F$, E> pf, Parser<I, G, E> pg, F<A, F<B, F<C, F<D, F<E$, F<F$, F<G, H>>>>>>> f) Binds the given function across the parsers with a final join.- Parameters:
pb
- A given parser to bind the given function with.pc
- A given parser to bind the given function with.pd
- A given parser to bind the given function with.pe
- A given parser to bind the given function with.pf
- A given parser to bind the given function with.pg
- A given parser to bind the given function with.f
- The function to apply to the element of the parsers.- Returns:
- A new parser after performing the map, then final join.
-
bind
public <B,C, Parser<I,D, E$, F$, G, H, I$> I$, bindE> (Parser<I, B, E> pb, Parser<I, C, E> pc, Parser<I, D, E> pd, Parser<I, E$, E> pe, Parser<I, F$, E> pf, Parser<I, G, E> pg, Parser<I, H, E> ph, F<A, F<B, F<C, F<D, F<E$, F<F$, F<G, F<H, I$>>>>>>>> f) Binds the given function across the parsers with a final join.- Parameters:
pb
- A given parser to bind the given function with.pc
- A given parser to bind the given function with.pd
- A given parser to bind the given function with.pe
- A given parser to bind the given function with.pf
- A given parser to bind the given function with.pg
- A given parser to bind the given function with.ph
- A given parser to bind the given function with.f
- The function to apply to the element of the parsers.- Returns:
- A new parser after performing the map, then final join.
-
sequence
Binds anonymously, ignoring the result value.- Parameters:
p
- The parser to bind with.- Returns:
- A parser after binding anonymously.
-
apply
Performs function application within a parser.- Parameters:
p
- The parser returning a function value.- Returns:
- A new parser after function application.
-
or
Returns a parser that tries this parser and if it fails, then tries the given parser.- Parameters:
alt
- The parser to try if this parser fails.- Returns:
- A parser that tries this parser and if it fails, then tries the given parser.
-
or
Returns a parser that tries this parser and if it fails, then tries the given parser.- Parameters:
alt
- The parser to try if this parser fails.- Returns:
- A parser that tries this parser and if it fails, then tries the given parser.
-
or
Returns a parser that tries this parser and if it fails, then tries the given parser. If both parsers fail, then append their errors with the given semigroup.- Parameters:
alt
- The parser to try if this parser fails.s
- The semigroup to append error messages if both parsers fail.- Returns:
- A parser that tries this parser and if it fails, then tries the given parser.
-
or
Returns a parser that tries this parser and if it fails, then tries the given parser. If both parsers fail, then append their errors with the given semigroup.- Parameters:
alt
- The parser to try if this parser fails.s
- The semigroup to append error messages if both parsers fail.- Returns:
- A parser that tries this parser and if it fails, then tries the given parser.
-
not
Returns a parser that negates this parser. If this parser succeeds, then the returned parser fails and vice versa.- Parameters:
e
- The error message to fail with if this parser succeeds.- Returns:
- A parser that negates this parser.
-
not
Returns a parser that negates this parser. If this parser succeeds, then the returned parser fails and vice versa.- Parameters:
e
- The error message to fail with if this parser succeeds.- Returns:
- A parser that negates this parser.
-
repeat
Returns a parser that repeats application of this parser zero or many times.- Returns:
- A parser that repeats application of this parser zero or many times.
-
repeat1
Returns a parser that repeats application of this parser one or many times.- Returns:
- A parser that repeats application of this parser one or many times.
-
mapError
Maps the given function across this parser's error.- Parameters:
f
- The function to map this parser's error with.- Returns:
- A new parser with a new error type.
-
parser
Returns a parser that computes using the given function.- Parameters:
f
- The function to construct the parser with.- Returns:
- A parser that computes using the given function.
-
value
Constructs a parser that always returns the given value. The unital for a parser.- Parameters:
a
- The value to consistently return from a parser.- Returns:
- A parser that always returns the given value.
-
fail
Returns a parser that always fails with the given error.- Parameters:
e
- The error to fail with.- Returns:
- A parser that always fails with the given error.
-
sequence
Sequence the list of parsers throughbind(fj.F<A, fj.parser.Parser<I, B, E>>)
.- Parameters:
ps
- The parsers to sequence.- Returns:
- A parser after sequencing.
-