Skip to content

Feature request: re_take_until #3

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

Open
daboross opened this issue Mar 8, 2023 · 0 comments
Open

Feature request: re_take_until #3

daboross opened this issue Mar 8, 2023 · 0 comments

Comments

@daboross
Copy link

daboross commented Mar 8, 2023

This is a continuation of rust-bakery/nom#709, since regex nom functions have since moved into this crate.

I have a specific use case: I'd like to parse "[thing1, thing2part1,part2, thing3]" into ["thing1", "thing2part1,part2", "thing3"].

If I could guarantee no item-internal commas, I could implement this as:

delimited(
    tag("["),
    separated_list0(tag(", "), take_while(|c| ![',', ']'].contains(&c))),
    tag("]"),
)

However, since I want to parse a multi-letter sequence, this won't work.

I could do something with take_till, and probably will for this case, but I think that ends up pretty hacky.

On the other hand, regex engines are optimized for this kind of matching, so I believe using regex (or anything aho_corasick-based) is the best option.

I'd propose re_take_until, matching the interface of complete::take_until except taking in a regex rather than byte/string directly.

It'd be used like this to match the above pattern:

let closing_bracket_or_comma_space = regex::Regex::new(r"]|, ").unwrap();
delimited(
    tag("["),
    separated_list0(tag(", "), re_take_until(closing_bracket_or_comma_space),
    tag("]"),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant