Parser
object Parser
- Companion
- class
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Type members
Classlikes
sealed abstract class Expectation
An expectation reports the kind or parsing error
and where it occured.
and where it occured.
- Companion
- object
Enables syntax to access product01, product and flatMap01
This helps us build Parser instances when starting from
a Parser0
This helps us build Parser instances when starting from
a Parser0
If we can parse this then that, do so,
if we fail that without consuming, rewind
before this without consuming.
If either consume 1 or more, do not rewind
if we fail that without consuming, rewind
before this without consuming.
If either consume 1 or more, do not rewind
If we can parse this then that, do so,
if we fail that without consuming, rewind
before this without consuming.
If either consume 1 or more, do not rewind
if we fail that without consuming, rewind
before this without consuming.
If either consume 1 or more, do not rewind
If we can parse this then that, do so,
if we fail that without consuming, rewind
before this without consuming.
If either consume 1 or more, do not rewind
if we fail that without consuming, rewind
before this without consuming.
If either consume 1 or more, do not rewind
Value members
Methods
Parse a given string, in a case-insensitive manner,
or fail. This backtracks on failure
this is an error if the string is empty
or fail. This backtracks on failure
this is an error if the string is empty
Ignore the case of a single character
If you want to know if it is upper or
lower, use .string to capture the string
and then map to process the result.
If you want to know if it is upper or
lower, use .string to capture the string
and then map to process the result.
go through the list of parsers trying each
as long as they are epsilon failures (don't advance)
see @backtrack if you want to do backtracking.
as long as they are epsilon failures (don't advance)
see @backtrack if you want to do backtracking.
This is the same as parsers.foldLeft(fail)(.orElse())
go through the list of parsers trying each
as long as they are epsilon failures (don't advance)
see @backtrack if you want to do backtracking.
as long as they are epsilon failures (don't advance)
see @backtrack if you want to do backtracking.
This is the same as parsers.foldLeft(fail)(.orElse())
Parse the longest matching string between alternatives.
The order of the strings does not matter.
The order of the strings does not matter.
If no string matches, this parser results in an epsilon failure.
It is an error to pass the empty string here, if you
need that see stringIn0
need that see stringIn0
If the first parser fails to parse its input with an epsilon error,
try the second parser instead.
try the second parser instead.
If the first parser fails with an arresting error, the second parser
won't be tried.
won't be tried.
Backtracking may be used on the first parser to allow the second
one to pick up after any error, resetting any state that was
modified by the first parser.
one to pick up after any error, resetting any state that was
modified by the first parser.
If the first parser fails to parse its input with an epsilon error,
try the second parser instead.
try the second parser instead.
If the first parser fails with an arresting error, the second parser
won't be tried.
won't be tried.
Backtracking may be used on the first parser to allow the second
one to pick up after any error, resetting any state that was
modified by the first parser.
one to pick up after any error, resetting any state that was
modified by the first parser.
Repeat the parser 0 or more times, but no more than
max
It may seem weird to accept 0 here, but without, composing
this method becomes more complex.
Since and empty parse is possible for this method, we do
allow max = 0
this method becomes more complex.
Since and empty parse is possible for this method, we do
allow max = 0
- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
- Note
- this can wind up parsing nothing
Repeat the parser
min
or more timesThe parser fails if it can't match at least
min
times- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
Repeat the parser
min
or more times, but no more than max
The parser fails if it can't match at least
After repeating the parser
min
timesAfter repeating the parser
max
times, the parser completes succesfully- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
Repeat the parser exactly
times
times- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
Repeat
min
or more times with a separator, at least once.- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
Repeat
min
or more, up to max
times with a separator, at least once.- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
Repeat
min
or more times with a separator.- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
Repeat
min
or more, up to max
times with a separator.- Throws
- java.lang.IllegalArgumentException
- java.lang.IllegalArgumentException
softProduct, a variant of product
A soft product backtracks if the first succeeds and the second
is an epsilon-failure. By contrast product will be a failure in
that case
A soft product backtracks if the first succeeds and the second
is an epsilon-failure. By contrast product will be a failure in
that case
see @Parser.soft
softProduct with the first argument being a Parser
A soft product backtracks if the first succeeds and the second
is an epsilon-failure. By contrast product will be a failure in
that case
A soft product backtracks if the first succeeds and the second
is an epsilon-failure. By contrast product will be a failure in
that case
see @Parser.soft
softProduct with the second argument being a Parser
A soft product backtracks if the first succeeds and the second
is an epsilon-failure. By contrast product will be a failure in
that case
A soft product backtracks if the first succeeds and the second
is an epsilon-failure. By contrast product will be a failure in
that case
see @Parser.soft
Parse p and if we get the Left side, parse fn
This function name comes from seletive functors.
This should be more efficient than flatMap since
the fn Parser0 is evaluated once, not on every item
parsed
This function name comes from seletive functors.
This should be more efficient than flatMap since
the fn Parser0 is evaluated once, not on every item
parsed
Standard monadic flatMap
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
Standard monadic flatMap where you start with a Parser
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
Standard monadic flatMap where you end with a Parser
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
tail recursive monadic flatMaps
This is a rarely used function, but needed to implement cats.FlatMap
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
This is a rarely used function, but needed to implement cats.FlatMap
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
tail recursive monadic flatMaps on Parser
This is a rarely used function, but needed to implement cats.FlatMap
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
This is a rarely used function, but needed to implement cats.FlatMap
Avoid this function if possible. If you can
instead use product, ~, >, or < use that.
flatMap always has to allocate a parser, and the
parser is less amenable to optimization
A parser that always fails with an epsilon failure and a given message
this is generally used with flatMap to validate a result beyond
the literal parsing.
this is generally used with flatMap to validate a result beyond
the literal parsing.
e.g. parsing a number then validate that it is bounded.
parse zero or more characters as long as they don't match p
this is useful for parsing comment strings, for instance.
this is useful for parsing comment strings, for instance.
discard the value in a Parser.
This is an optimization because we remove trailing
map operations and don't allocate internal data structures
This function is called internal to Functor.as and Apply.>
and Apply.< so those are good uses.
This is an optimization because we remove trailing
map operations and don't allocate internal data structures
This function is called internal to Functor.as and Apply.>
and Apply.< so those are good uses.
discard the value in a Parser.
This is an optimization because we remove trailing
map operations and don't allocate internal data structures
This function is called internal to Functor.as and Apply.>
and Apply.< so those are good uses.
This is an optimization because we remove trailing
map operations and don't allocate internal data structures
This function is called internal to Functor.as and Apply.>
and Apply.< so those are good uses.
Discard the result A and instead capture the matching string
this is optimized to avoid internal allocations
this is optimized to avoid internal allocations
Discard the result A and instead capture the matching string
this is optimized to avoid internal allocations
this is optimized to avoid internal allocations
returns a parser that succeeds if the
current parser fails.
Note, this parser backtracks (never returns an arresting failure)
current parser fails.
Note, this parser backtracks (never returns an arresting failure)
return the current position in the string
we are parsing. This lets you record position information
in your ASTs you are parsing
we are parsing. This lets you record position information
in your ASTs you are parsing
If we fail, rewind the offset back so that
we can try other branches. This tends
to harm debuggability and ideally should be
minimized
we can try other branches. This tends
to harm debuggability and ideally should be
minimized
Implicits
Implicits
implicit val catsInstancesParser: FlatMap[[A] =>> Parser[A]] & Defer[[A] =>> Parser[A]] & MonoidK[[A] =>> Parser[A]] & FunctorFilter[[A] =>> Parser[A]]