-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
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?
Why is parent matching smaller than child matching? (rule add
)
Metadata
Metadata
Assignees
Labels
No labels