Represents where a failure occurred and all the expectations that were broken
An expectation reports the kind or parsing error and where it occured.
If we can parse this then that, do so, if we fail that without consuming, rewind before this without consuming.
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 can parse this then that, do so, if we fail that without consuming, rewind before this without consuming.
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 can parse this then that, do so, if we fail that without consuming, rewind before this without consuming.
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
Enables syntax to access product01, product and flatMap01 This helps us build Parser instances when starting from a Parser0
A parser that always fails with an epsilon failure
Parse 1 character from the string
Replaces parsed values with the given value.
Replaces parsed values with the given value.
If we fail, rewind the offset back so that we can try other branches.
If we fail, rewind the offset back so that we can try other branches. This tends to harm debuggability and ideally should be minimized
If we fail, rewind the offset back so that we can try other branches.
If we fail, rewind the offset back so that we can try other branches. This tends to harm debuggability and ideally should be minimized
return the current Caret (offset, line, column) this is a bit more expensive that just the index
parse a single character
parse one of a given set of characters
An empty iterable is the same as fail
parse one character that matches a given function
Parse a string while the given function is true parses at least one character
Parse a string while the given function is true
Lazily create a Parser This is useful to create some recursive parsers see Defer0[Parser].fix
Lazily create a Parser0 This is useful to create some recursive parsers see Defer0[Parser].fix
If the first parser fails to parse its input with an epsilon error, try the second parser instead.
If the first parser fails to parse its input with an epsilon error, try the second parser instead.
If the first parser fails with an arresting error, the second parser 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.
If the first parser fails to parse its input with an epsilon error, try the second parser instead.
If the first parser fails to parse its input with an epsilon error, try the second parser instead.
If the first parser fails with an arresting error, the second parser 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.
succeeds when we are at the end
A parser that always fails with an epsilon failure
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.
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.
e.g. parsing a number then validate that it is bounded.
Standard monadic flatMap Avoid this function if possible.
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
Standard monadic flatMap where you end with a Parser Avoid this function if possible.
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
Standard monadic flatMap where you start with a Parser Avoid this function if possible.
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
Parse a given string, in a case-insensitive manner, or fail.
Parse a given string, in a case-insensitive manner, or fail. This backtracks on failure this is an error if the string is empty
Parse a potentially empty string, in a case-insensitive manner, or fail.
Parse a potentially empty string, in a case-insensitive manner, or fail. This backtracks on failure
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.
Parse any single character in a set of characters as lower or upper case
Parse any single character in a set of characters as lower or upper case
return the current position in the string we are parsing.
return the current position in the string we are parsing. This lets you record position information in your ASTs you are parsing
Parse the next len characters where len > 0 if (len < 1) throw IllegalArgumentException
if len < 1, the same as pure("") else length(len)
transform a Parser result
transform a Parser0 result
returns a parser that succeeds if the current parser fails.
returns a parser that succeeds if the current parser fails. Note, this parser backtracks (never returns an arresting failure)
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.
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.
This is the same as parsers.foldLeft(fail)(_.orElse(_))
recommended style: oneOf(p1 :: p2 :: p3 :: Nil) rather than oneOf(List(p1, p2, p3))
Note: order matters here, since we don't backtrack by default.
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.
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.
This is the same as parsers.foldLeft(fail)(_.orElse(_))
recommended style: oneOf(p1 :: p2 :: p3 :: Nil) rather than oneOf(List(p1, p2, p3))
Note: order matters here, since we don't backtrack by default.
a parser that consumes nothing when it succeeds, basically rewind on success
parse first then second
product with the second argument being a Parser
product with the first argument being a Parser
Don't advance in the parsed string, just return a This is used by the Applicative typeclass.
Build a recursive parser by assuming you have it Useful for parsing recurive structures, like for instance JSON.
Repeat the parser min
or more times, but no more than max
Repeat the parser min
or more times, but no more than max
The parser fails if it can't match at least min
times After repeating the parser max
times, the parser completes succesfully
java.lang.IllegalArgumentException
if min < 1 or max < min
Repeat the parser min
or more times
Repeat the parser min
or more times
The parser fails if it can't match at least min
times
java.lang.IllegalArgumentException
if min < 1
Repeat the parser 0 or more times, but no more than max
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
java.lang.IllegalArgumentException
if max < 0
this can wind up parsing nothing
Repeat the parser 0 or more times
Repeat the parser 0 or more times
this can wind up parsing nothing
Repeat the parser exactly times
times
Repeat the parser exactly times
times
java.lang.IllegalArgumentException
if times < 1
Repeat min
or more, up to max
times with a separator, at least once.
Repeat min
or more, up to max
times with a separator, at least once.
java.lang.IllegalArgumentException
if min <= 0
or max < min
Repeat min
or more times with a separator, at least once.
Repeat min
or more times with a separator, at least once.
java.lang.IllegalArgumentException
if min <= 0
Repeat 1 or more times with a separator
Repeat min
or more, up to max
times with a separator.
Repeat min
or more, up to max
times with a separator.
java.lang.IllegalArgumentException
if min < 0
or max < min
Repeat min
or more times with a separator.
Repeat min
or more times with a separator.
java.lang.IllegalArgumentException
if min < 0
Repeat 0 or more times with a separator
parse one or more times until Parser end
succeeds.
parse zero or more times until Parser end
succeeds.
parse one or more times until Parser end
succeeds.
parse zero or more times until Parser end
succeeds.
Parser version of select
Parse p and if we get the Left side, parse fn This function name comes from seletive functors.
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
softProduct, a variant of product A soft product backtracks if the first succeeds and the second is an epsilon-failure.
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
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.
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
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.
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
see @Parser.soft
succeeds when we are at the start
Discard the result A and instead capture the matching string this is optimized to avoid internal allocations
Parse a given string or fail.
Parse a given string or fail. This backtracks on failure this is an error if the string is empty
Discard the result A and instead capture the matching string this is optimized to avoid internal allocations
Parse a potentially empty string or fail.
Parse a potentially empty string or fail. This backtracks on failure
Parse the longest matching string between alternatives.
Parse the longest matching string between alternatives. 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
Version of stringIn that allows the empty string
tail recursive monadic flatMaps on Parser This is a rarely used function, but needed to implement cats.FlatMap Avoid this function if possible.
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
tail recursive monadic flatMaps This is a rarely used function, but needed to implement cats.FlatMap Avoid this function if possible.
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
A parser that returns unit
parse one or more characters as long as they don't match p
parse zero or more characters as long as they don't match p this is useful for parsing comment strings, for instance.
discard the value in a Parser.
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.
discard the value in a Parser.
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.
Add a context string to Errors to aid debugging
Add a context string to Errors to aid debugging