Closed sealmove closed 4 years ago
True, will document. Try instead:
let p = peg o:
o <- &>1:
echo len($1)
-- :wq ^X^Cy^K^X^C^C^C^C
Unfortunately you snippet fails with:
Error: unhandled exception: Capture out of range, 1 is not in [0..0] [NPegException]
Sure, it needs this instead:
let p = peg o:
o <- &p
p <- >1:
echo len($1)
The reason is that &
can have no side effects and internally restores the match state and all its captures to the state it was before. I'll add this to the documentation, thanks for reporting!
I think this behavior is somewhat surprising.
Possible solutions:
>
is used along with&