Skip to content

Strange trace during cache_left_rec #407

@A4-Tacks

Description

@A4-Tacks
peg::parser!(grammar p() for str {
    rule pack(p: rule<()>) -> ()
        = p() {}
    rule number() = ['0'..='9']+
    rule atom() -> () = n:$(number()) {}
    #[cache_left_rec]
    rule add() -> ()
        = add() "+" atom()
        / atom()
    rule cmp() -> ()
        = add() "<" add()
        / add()
    rule equalty() -> ()
        = pack(<cmp() "=" cmp()>) // pack Failed, but equality Matched
        / cmp()
    pub rule top() = equalty()
});

fn main() {
    let _ = dbg!(p::top("1+2<3"));
}

trace output:

[PEG_TRACE] Attempting to match rule `equalty` at 1:1
[PEG_TRACE] Attempting to match rule `pack` at 1:1
...
[PEG_TRACE] Failed to match rule `pack` at 1:1
[PEG_TRACE] Attempting to match rule `cmp` at 1:1
[PEG_TRACE] Cached match of rule add at 1:1
[PEG_TRACE] Cached match of rule add at 1:5
[PEG_TRACE] Matched rule `cmp` at 1:1 to 1:6
[PEG_TRACE] Matched rule `equalty` at 1:1 to 1:6

Why did the pack fail but equalty succeeded?

Image

Why is parent matching smaller than child matching? (rule add)

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