-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backtracking support through &try/backtrack() #606
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great tool so users can build their own tooling to parse conditionally. At the same time, I could see this being used to implement error handling for which this patch doesn't seem to go all the way or at least is missing tests (e.g., can backtrack
be caught by on %error
handlers; guaranteed interaction of plain old parse errors and &try
fields; no access to particular error when &try
field fails to parse). I left a few comments along those lines below. Like discussed offline we probably still need a better idea how we want error handling to finally look like.
That tells a vector explicitly to parse until it hits the end of the input, without having to use the look-ahead machinery to figure out when to stop.
8f1a3aa
to
f4b9f4b
Compare
If a field is marked with ``&try``, a later call to ``self.backtrack()`` anywhere down in the parse tree will return to that position and continue there. (This is ported over the old prototype). Example: export type test = unit { a: bytes &length=4; foo: Foo &try; bar: Bar; b: bytes &length=6; on %done { print self; } }; type Foo = unit { a: int8 { print "Foo.a", self; } b: int8 { print "Backtracking"; self.backtrack(); } c: int8 { print "Foo.c", self; } }; type Bar = unit { a: int8 { print "Bar.a", self; } b: int8 { print "Bar.b", self; } c: int8 { print "Bar.c", self; } }; # printf '1234\001\002\003567890' | pac-driver backtrack.pac2 Foo.a <a=1, b=(not set), c=(not set)> Backtracking Bar.a <a=1, b=(not set), c=(not set)> Bar.b <a=1, b=2, c=(not set)> Bar.c <a=1, b=2, c=3> <a=1234, foo=(Null), bar=<a=1, b=2, c=3>, b=567890> Closes #25.
When an example contained multiple commands separated by semicolons, we'd execute them separately but still include all of them into each of the command lines emitted into the docs. (Couple of doc outputs show slightly changed content, including updates into this commit.)
f4b9f4b
to
2038055
Compare
No description provided.