-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax for rx_or() #16
Comments
Adding rx_either_of <- function(.data = NULL, ..., rep = NULL, mode = "greedy") {
if (!inherits(.data, "rx_string")) stop("This function is not to be used as first element of the pipe! Please start pipe with constructor funcion rx()")
san_args <- sapply(list(...), sanitize)
san_args_peeled <- peel_set(san_args)
res <- paste0(.data, "(?:", paste0(san_args_peeled, collapse = "|"), ")", parse_rep_mode(rep, mode))
new_rx(res)
}
library(RVerbalExpressions)
# Alternation is eager!
rx() %>%
rx_either_of("GetValue", "Get", "Set", "SetValue") %>%
stringr::str_extract_all("Get, GetValue, Set or SetValue", .) %>%
.[[1]]
#> [1] "Get" "GetValue" "Set" "Set"
# Avoid eagerness with order of values
rx() %>%
rx_either_of("GetValue", "Get", "SetValue", "Set") %>%
stringr::str_extract_all("Get, GetValue, Set or SetValue", .) %>%
.[[1]]
#> [1] "Get" "GetValue" "Set" "SetValue"
# Avoid eagerness with word boundaries
rx() %>%
rx_word_edge() %>%
rx_either_of("GetValue", "Get", "Set", "SetValue") %>%
rx_word_edge() %>%
stringr::str_extract_all("Get, GetValue, Set or SetValue", .) %>%
.[[1]]
#> [1] "Get" "GetValue" "Set" "SetValue" Should |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now we have
rx_or
implementation which compares.data
andvalue
In the comments you mentioned:
Might the solution be similar to how now (in dev branch) we organized
rx_one_of()
:In a sense, this is
rx_one_of
with(?:a|b)
instead of[ab]
and limited to two arguments only. I actually believe nothing prevents us from allowing more arguments, if we go down this route. I think going this route will add consistency to the package.The text was updated successfully, but these errors were encountered: