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

Fully support obsolete syntax from RFC 5322 #13

Open
eikendev opened this issue Apr 2, 2023 · 2 comments
Open

Fully support obsolete syntax from RFC 5322 #13

eikendev opened this issue Apr 2, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@eikendev
Copy link
Owner

eikendev commented Apr 2, 2023

See Section 4 for some background:

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:

@eikendev eikendev added the bug Something isn't working label Apr 2, 2023
@eikendev eikendev self-assigned this Apr 2, 2023
@eikendev
Copy link
Owner Author

eikendev commented Apr 2, 2023

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;

fn main() {
    let input = "aaaaab";

    println!("{:?}", parser(input));

    let re = Regex::new(r"^(ab|a)*b$").unwrap();
    println!("{:?}", re.find(input));
}

fn parser(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.

@eikendev
Copy link
Owner Author

For now, there are no plans to support the obsolete syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant