Skip to content

Precedence cannot avoid generating associativity #404

@A4-Tacks

Description

@A4-Tacks
peg::parser!(grammar p() for str {
    rule x() = "x"
    pub rule foo() = "-" x() / x()
    pub rule bar() = precedence! {
        "-" @ {}
        --
        x() {}
    }
});

fn main() {
    assert_eq!(p::foo("-x"), Ok(()));
    assert_eq!(p::bar("-x"), Ok(()));
    assert!(p::foo("--x").is_err());
    assert!(p::bar("--x").is_err()); // failed!
}

Sometimes it is necessary to not associative infix, prefix, and postfix operators,
But the precedence! cannot express this situation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions