-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add support for field-local %error
handlers.
#1838
Conversation
@sethhall another one to try |
This doesn't seem to work if you have any attributes attached to the field...
|
Turns out this gets parsed as |
... and this is because in the past we have explicitly added support for parsing things like |
haha, well I'm glad I bumped across that when I tried to use the feature! |
f0910a6
to
63199fe
Compare
%error
handlers.%error
handlers.
63199fe
to
71d0e8b
Compare
7de841d
to
1d91bf5
Compare
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.
Thanks! 🚀
1d91bf5
to
d7dc372
Compare
Currently we only have two types of field hooks: standard hooks and `foreach` hooks. To prepare for more types, this refactors the code to represent the type with an `enum` instead of a `foreach` boolean. It also moves validation of permitted attributes from the parser to the validator.
d7dc372
to
fec6193
Compare
We now support attaching an `%error` handler to an individual field: type Test = unit { a: b"A"; b: b"B" %error { print "field B %error", self; } c: b"C"; }; With input `AxC`, that handler will trigger, whereas with `ABx` it won't. If the unit had a unit-wide `%error` handler as well, that one would trigger in both cases (i.e., for `b`, in addition to its field local handler). The handler can also be provided separately from the field: on b %error { ... } In that separate version, one can receive the error message as well by declaring a corresponding string parameter: on b(msg: string) %error { ... } This works externally, from outside the unit, as well: on Test::b(msg: string) %error { ... } This is eebased on top of `topic/robin/optimize-type-parsing` so that we get the peephole optimizer. Addresses #1824.
The old text was very outdated. This extends the content, documents the new per-field `%error` handler, and moves it all into the "parsing" section to have it closer to the error recovery content.
In the past, we had special-cased properties in our Flex/Bison parser so that when parsing an expression, they wouldn't be recognized. However, that now led an error field hook of the form `x: bytes &size=42 %error` to be parsed as `&size=(42 % error)`. We now switch to white-listing all known properties, just as we already do for attributes. That way conflicts should be extremely rare.
fec6193
to
7fba8bf
Compare
Add support for field-local
%error
handlers.We now support attaching an
%error
handler to an individual field:With input
AxC
, that handler will trigger, whereas withABx
itwon't. If the unit had a unit-wide
%error
handler as well, that onewould trigger in both cases (i.e., for
b
, in addition to its fieldlocal handler).
The handler can also be provided separately from the field:
In that separate version, one can receive the error message as well by
declaring a corresponding string parameter:
This works externally, from outside the unit, as well:
This is debased on top of
topic/robin/optimize-type-parsing
so thatwe get the peephole optimizer.
Addresses #1824.