%then% | R Documentation |
(p1 %then% p2)
recognizes anything that p1
and p2
would if applied in
succession.
p1 %then% p2
p1 , p2 |
two parsers. |
A parser.
(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.
The discarding versions %xthen% and %thenx%
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.