-
Notifications
You must be signed in to change notification settings - Fork 105
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
Stop parsing on pattern match #179
Comments
Right now the generated wrapper function checks that the match reaches the end of input, and reports a |
|
For someone who looking for concrete solution: peg::parser! {
pub grammar stream() for str {
pub rule event() -> T = ...;
pub rule event_list() -> Vec<T> = event()*;
#[no_eof] // Do not check for EOF after parsing rule
pub rule event_iter() -> (T, usize)
// Return position after parsing
= r:event() p:position!() { (r, p) };
}
}
let mut content = "...";
while !content.is_empty() {
let (event, pos) = stream::event_iter(content)?;
content = &content[pos..];
// process event...
} We add a new |
Hi, I'd like to stop parsing the string input when a given pattern is matched. I'll give example for SMTP:
The desire is that I could parse all the commands until including the data command. There is no point parsing further as there may be binary data there.
You could add a #quit instruction to terminate further processing:
pub cmd_data -> SmtpCommand
= "data"i NL #quit
{ SmtpCommand::Data }
FYI: the full SMTP grammar on github. Btw, thanks a lot for PEG.
The text was updated successfully, but these errors were encountered: