You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Earlier versions of this specification allowed for different (usually more liberal) syntax than is allowed in this version. Also, there have been syntactic elements used in messages on the Internet whose interpretations have never been documented. Though these syntactic forms MUST NOT be generated according to the grammar in section 3, they MUST be accepted and parsed by a conformant receiver.
The obsolete syntax leaves room for ambiguity, which nom cannot deal with. Instead, a more powerful parser would be required. Options are:
Background: nom does not (fully) support backtracking, meaning a valid input might not be accepted.
use nom::{
branch::alt,
bytes::complete::tag,
combinator::{all_consuming, recognize},
multi::many0_count,
sequence::terminated,IResult,};use regex::Regex;fnmain(){let input = "aaaaab";println!("{:?}", parser(input));let re = Regex::new(r"^(ab|a)*b$").unwrap();println!("{:?}", re.find(input));}fnparser(i:&str) -> IResult<&str,&str>{all_consuming(terminated(recognize(many0_count(alt((tag("ab"),tag("a"))))),tag("b"),))(i)}
This will print
$ cargo run
Err(Error(Error { input: "", code: Tag }))
Some(Match { text: "aaaaab", start: 0, end: 6 })
Of course, in this simple example there would be workarounds, such as swapping ab and a. However, this is not possible in the general case, leaving the problem unsolved for more complex parser combinators.
See Section 4 for some background:
The obsolete syntax leaves room for ambiguity, which nom cannot deal with. Instead, a more powerful parser would be required. Options are:
The text was updated successfully, but these errors were encountered: