%then% {parcr} | R Documentation |
Applying parsers in sequence
Description
(p1 %then% p2)
recognizes anything that p1
and p2
would if applied in
succession.
Usage
p1 %then% p2
Arguments
p1 , p2 |
two parsers. |
Value
A parser.
Pseudocode
(p1 %then% p2)(x): if p1(x)==[] or x==null then fail()(x) else if p2(x[-1])==[] then fail()(x) else succeed([p1(x)$L, p2(x[-1])$L])(x[-2])
where null
is the empty vector, x[-1]
and x[-2]
are the vector x
without the first element and without the first two elements, respectively.
See Also
The discarding versions %xthen% and %thenx%
Examples
starts_with_a <- function(x) grepl("^a",x[1])
starts_with_b <- function(x) grepl("^b",x[1])
(satisfy(starts_with_a) %then% satisfy(starts_with_b)) (c("ab", "bc", "de")) # success
(satisfy(starts_with_a) %then% satisfy(starts_with_b)) (c("bb", "bc", "de")) # failure
(satisfy(starts_with_a) %then% satisfy(starts_with_b)) (c("ab", "ac", "de")) # failure
[Package parcr version 0.5.2 Index]