by_split {parcr} | R Documentation |
Applying a parser to a split string
Description
Splits a string by using a split pattern and then applies the parser p
to the resulting character vector. If finish = TRUE
then the parser should
completely consume its input, otherwise the parser fails. If
finish = FALSE
then any remaining part of the string is discarded.
Usage
by_split(p, split, finish = TRUE, fixed = FALSE, perl = FALSE)
Arguments
p |
A parser. |
split |
a string (or object which can be coerced to such) containing regular expression(s) (unless fixed = TRUE) to use for splitting. If empty matches occur, in particular if split has length 0, x is split into single characters. |
finish |
logical. Should the parser completely consume the string?
Defaults to |
fixed |
logical. If |
perl |
logical. Should Perl-compatible regexps be used? |
Details
The function base::strsplit()
is used to perform the splitting. The
parameters split
, fixed
and perl
are passed on to that function.
Value
A parser.
See Also
Examples
by_split((literal("a") %then% literal("b")),"\\t") ("a\tb") # success
by_split((literal("a") %then% literal("b")),"\\t") ("a\tb\tc") # failure
by_split((literal("a") %then% literal("b")),"\\t", finish=FALSE) ("a\tb\tc") # success