You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a grammar rule invokes a function before recognizing any input, the subsequent failure of the rule does not restore the capture stack to its state before the rule was attempted.
Example
This example grammar recognizes lines of digits and returns a (reversed) list of the sums of digits.
Digit adds the integer value of a digit to the sum on the capture stack.
Line initializes a line's sum on the capture stack and recognizes one or more digits followed by a newline.
Summary
When a grammar rule invokes a function before recognizing any input, the subsequent failure of the rule does not restore the capture stack to its state before the rule was attempted.
Example
This example grammar recognizes lines of digits and returns a (reversed) list of the sums of digits.
Digit
adds the integer value of a digit to the sum on the capture stack.Line
initializes a line's sum on the capture stack and recognizes one or more digits followed by a newline.Sums
recognizes one or more lines.The parser builds as expected.
The parser recognizes sample input and computes digit sums correctly, leaving them on the capture stack.
Problem: The capture stack includes an extra
0
, apparently from the final, failed attempt to try ruleLine
.Environment and Versions
Tested in Livebook running on Windows 11.
{:xpeg, git: "https://github.com/zevv/xpeg"}
The text was updated successfully, but these errors were encountered: