View source: R/parsers_error.R
| named | R Documentation |
named() wraps a parser and provides a meaningful name that will be shown
in error messages when the parser fails. This is particularly useful for
user-defined parsers to make error messages more informative.
named(p, name)
p |
a parser. |
name |
a character string describing what the parser expects. |
A parser.
# Define a parser with a semantic name
Nucleotide <- function() {
named(
satisfy(function(x) grepl("^[GATC]+$", x)),
"nucleotide sequence"
)
}
# When this parser fails, the error will say "Expected: nucleotide sequence"
try(reporter(Nucleotide() %then% eof())(c("GATCxTC")))
# Combine named parsers with %or% to get helpful "Expected one of:" messages
Nucleotide_or_Protein <- function() {
named(satisfy(function(x) grepl("^[GATC]+$", x)), "nucleotide") %or%
named(satisfy(function(x) grepl("^[ARNDCQEGHILKMFPSTWYV]+$", x)), "protein")
}
try(reporter(Nucleotide_or_Protein() %then% eof())(c("Some text")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.