View source: R/parsers_basic.R
| succeed | R Documentation |
These are the most basic constructors of a parser, but they are important
cogs of the parser machinery. The succeed parser always succeeds, without
consuming any input, whereas the fail parser always fails.
succeed(left)
fail(lnr = LNR())
left |
any R-object constructed from a parsed vector. |
lnr |
integer. The line number (element number) at which the fail occurs |
The succeed parser constructs a list object with a 'left' or L-element
that contains the parser result of the consumed part of the input vector and
the 'right' or R-element that contains the unconsumed part of the vector.
Since the outcome of succeed does not depend on its input, its result value
must be pre-determined, so it is included as a parameter.
While succeed never fails, fail always does, regardless of the input
vector. It returns the empty list list() to signal this fact.
A list. succeed() returns a list with two elements named L and
R. fail() returns a marker object which is basically an empty list
with a line number n as attribute. It is printed as the icon [],
see print.marker(). Note that n will only correctly represent the line
number of failure when a parser is wrapped in the reporter() function.
succeed(y)(x): [L=[y],R=[x]] fail()(x): []
where [L=[y],R=[x]] is a named list with lists [y] and [x] as elements
and [] is an empty list.
It is very unlikely that you will ever have to use these functions when constructing parsers.
succeed("A")("abc")
succeed(data.frame(title="Keisri hull", author="Jaan Kross"))(c("Unconsumed","text"))
fail()("abc")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.