Skip to content
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

wanted function #653

Open
sineptic opened this issue Jul 23, 2024 · 5 comments
Open

wanted function #653

sineptic opened this issue Jul 23, 2024 · 5 comments

Comments

@sineptic
Copy link

sineptic commented Jul 23, 2024

Is there any function that read only if in input pattern occurs EXACTLY N times. existed function exactly() read even if there more than N occurs.

// This don't work:
let pattern = || {...};
let a = || read_until(pattern().repeated().exactly(N).then_ignore(pattern().not().rewind()));
// Example
let N = 2;
let pattern = || just::<_, Simple<_>>('a');
let a = ...;
assert!(a().parse("aaa ").is_ok());

//  ++-        +++
// "a̲aa " -> "aa̲a "

And I can't read already processed input.

@sineptic
Copy link
Author

More general, I need function, that return only if pattern matches after not match.

I need matches equal number of backticks, but

_```abc``_ matches with _`_ | _``abc``_

@sineptic
Copy link
Author

I think to work it must be names smth like (take/skip)_until_exactly

@zesterer
Copy link
Owner

You can do a.repeated().exactly(n).then_ignore(a.not()).

The final part expects anything that isn't an a immediately after the repeating section, effectively preventing more than n instances ever occurring.

@zesterer
Copy link
Owner

That said, the pattern you are looking for (the backticks) is context-sensitive and won't be solved with this alone. See my response here about parsing Rust-like raw strings, which pretty much follow the same pattern: #441 (reply in thread)

@sineptic
Copy link
Author

You can do a.repeated().exactly(n).then_ignore(a.not()).

The final part expects anything that isn't an a immediately after the repeating section, effectively preventing more than n instances ever occurring.

It don't works with my example

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

2 participants