| %or% | R Documentation |
The %or% combinator (p1 %or% p2) returns the result of p1 if p1 is
successful or, if p1 fails that of p2 if p2 parses successfully,
otherwise it returns a fail.
p1 %or% p2
p1, p2 |
two parsers. |
A parser.
(p1 %or% p2)(x):
if p1(x)==[] then
if p2(x)==[] then fail()(x) else p2(x)
else p1(x)
where [] is the empty list.
(literal("A") %or% literal("a"))(LETTERS[1:5]) # success on first parser
(literal("A") %or% literal("a"))(letters[1:5]) # success on second parser
(literal("A") %or% literal("a"))(LETTERS[2:6]) # failure
starts_with_a <- function(x) grepl("^a",x[1])
# success on both parsers, but returns result of p1 only
(literal("a") %or% satisfy(starts_with_a)) (letters[1:5])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.