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
(swift) Support operator and precedencegroup declarations. #2938
Conversation
src/languages/swift.js
Outdated
const OPERATOR_DECL = { | ||
beginKeywords: 'operator', | ||
contains: [ | ||
{ | ||
match: /\s+/, | ||
relevance: 0 | ||
}, |
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.
const OPERATOR_DECL = { | |
beginKeywords: 'operator', | |
contains: [ | |
{ | |
match: /\s+/, | |
relevance: 0 | |
}, | |
const OPERATOR_DECL = { | |
beginKeywords: 'operator', | |
ends: hljs.MATCH_NEVER, | |
contains: [ |
I'm not sure what to name it (never isn't quite right) but for things like this rather than all that muck to eat spaces it should be easier to just write "leave the mode open until you find a token"... or perhaps never never is clearer than I think?
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.
I'd also be open to a new attribute to suggest this if it was clear and easy to read. But it would really just be sugar for the above.
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.
Is MATCH_NEVER
just a regex that never matches, such as \b\B
? I guess it's a bit confusing because it makes it seems as though the mode never ends. But I assume you'd have to combine this with a child mode that ends its parent?
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.
Is MATCH_NEVER just a regex that never matches, such as \b\B?
Well, it doesn't exist yet, but we'd add it - and yes, exactly.
I guess it's a bit confusing because it makes it seems as though the mode never ends.
Exactly, unless manually ended by a child... obviously the mode ends upon input termination. My concern is that confusion between "never ends, literally" and "never ends, but by child".
But I assume you'd have to combine this with a child mode that ends its parent?
Yes, as you already have... this would just avoid that extraneous parsing of whitespace.
I very much thing the approach is correct, and obviously we could do it with just \b\B
and a comment, but it seems nice to bless the pattern with a proper name. @allejo Any ideas?
Fairly straight-forward. :) |
Please add issue link to the post so the issue can auto-close when we merge. :) Pretty sure we had an issue on this? |
I've made the suggested changes/fixes. I'll leave the whitespace handling up to you. Perhaps you can already merge this PR and decide on that issue later, as it probably applies to lots of code, not just this PR? |
Yes, I'm happy to fix. I don't see a rush (no pending release). Often I use PRs as pressure on myself to get new things added. I wouldn't leave this open for weeks/months for such a reason, but if it remains open a few extra days over the holidays and encourages me to add support for never match, then that seems a win win. I'm curious if allejo has any better thoughts for the naming. |
Added the code, we only need the name. :)
Three other grammars at least use this pattern, and we probably encourage it a bit more. Edit: Actually it's possible you might want a mode to enter and TRULY never end (such as processing a header, then body) - ie the child mode process all the input to EOF... so we shouldn't assume the child mode is going to have a Unless we find the perfect name often a comment might still be helpful... I'm only obsessing over the name because once it goes into the public API we're stuck with it. :) |
@allejo Any thoughts on naming? I'm leaning towards just |
Would this ever be used anywhere else besides const OPERATOR_DECL = {
beginKeywords: 'operator',
ends: hljs.ENDS_NEVER,
// ...
} Otherwise, if this can be used elsewhere, |
OMG, at first glance I like it a lot. I'll give it a noodle but I'm not sure where else you'd use it. |
Oh, but how do you feel about the fact that technically it's wrong? Usually you'd be pairing this with
Does ENDS_NEVER cause confusion? Does the above seem clear or could a reader being be confused? |
I think reading |
This is a good point... LOL. Maybe a more literal:
Because there are sometimes good reasons to never end it at all... like HTTP response body... |
You have my support for |
@svanimpe Thanks for all the hard work. |
@joshgoebel What is the release schedule for 10.6? |
I just updated the dates... this next week is going to be busy so I'd say next weekend sounds about right. |
This was the final thing on my list :)
title
highlighting in an operator declaration.precedencegroup
declaration.precedencegroup
. These keywords were removed from the global list because they're very rarely used and would cause mostly incorrect highlights as global keywords.