-
Notifications
You must be signed in to change notification settings - Fork 82
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 !is
/!has
syntax as shorthand for negated is
/has
#1435
base: main
Are you sure you want to change the base?
Conversation
I like the idea of having a more compact syntax for |
Thanks for the suggestion, I like it! I'll change the syntax accordingly and add it for |
isnt
syntax as shorthand for !(.. is ..)
!is
/!has
syntax as shorthand for negated is
/has
Surely, for consistency with |
I do like the |
We'll need to update both |
jay is objectively correct. !s and !as are the only sensible choices |
@Chris-Hawblitzel It looks like getting I tried the naive thing of just replacing the |
There is some functionality to merge tokens to handle these cases - I can't look now but I should be able to take a look next week. |
I would recommend parsing
the
This is a pretty common approach in syn. |
I pushed a commit that treats However, I think the main issue with
which now fails to parse (before and after my commit), and I think making it contextual would be a non-trivial endeavor. That said, we've already decided that |
because "!is" is not a valid identifier, internally convert it to isnt
@Chris-Hawblitzel is looking into parsing |
I took a quick look at verus analyzer. It turns out that it currently only supports One existing annoyance is that due to the existing design of rust-analyzer's parser, back when I added support for For this PR in particular, it looks doable to support |
Verusfmt now supports Regarding contextual vs not: I think having Re macro calls: I had to handle something similar for verusfmt too :) At least for versufmt it was easy to fix by making macro calls look-ahead for an opening brace/bracket/paren immediately after the |
Interesting. In rust-analyzer, it appears they have a look ahead for |
FWIW, I have a branch of verus-analyzer where |
Negation is annoying to use with the
is
syntax, since it requires wrapping in parentheses:!(x is Variant)
. This PR addsisnt
syntax, which expands to!(x is Variant)
.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.