-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix(elixir) fix regular expression detection #3207
Conversation
"when", | ||
"while", | ||
"with|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.
I know that this PR merely reformats the list, but it caught my attention because there are a lot of keywords in it that I have never seen in Elixir. Also let my starts by saying that I am not sure if there is a formal definition of a "keyword". I'm using that term rather intuitively.
As far as I know, those are not Elixir keywords at all:
begin
break
(Inspect.Algebra.break/1
is a function in the standard lib, but it has nothing to do with breaking out of loops like it might do in other languages)defined
ensure
include
module
next
(OptionParser.next/2
is a function in the standard lib, it has nothing to do with skipping to another iteration in a loop like it might do in other languages)redo
retry
return
until
while
I'm unsure about:
self
. It exists, but IMO it is a normal macro, not a keyword. I wouldn't expect it to be colored differently than other normal macros (likerem
,round
,trunc
etc).then
. It's a new macro added in Elixir 1.12 together withtap
, I don't think those are keywords.with|0
. I'm not sure what the pipe and zero mean here.with
on its own is definitely a keyword.
Missing IMO:
- if
case
,cond
, andunless
qualify as keywords,if
andelse
should too. - if
quote
qualifies as a keyword,unquote
andunquote_splicing
should too. receive
/after
https://hexdocs.pm/elixir/Kernel.SpecialForms.html#receive/1try
/rescue
/catch
/after
https://hexdocs.pm/elixir/Kernel.SpecialForms.html#try/1raise
https://hexdocs.pm/elixir/Kernel.html#raise/1reraise
https://hexdocs.pm/elixir/Kernel.html#reraise/2
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.
alias
is also listed twice in the list.
{ | ||
begin: /\{/, | ||
end: /\}/ | ||
begin: '~r' + '(?=' + SIGIL_DELIMITERS + ')', |
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.
Will this also mark regex modifiers as part of the regex? E.g.
~r(hello)
~r(hello)i
~r(hello)ui
~r(hello)U
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.
No, but we should add that. What are all the valid modifiers in Elixir?
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.
for sigils r
/R
, combinations of those letters:
uismxfU
for sigils: w
/W
, combinations of those letters:
sac
Treating any group of lower and/or uppercase letters immediately after the closing delimiter as a modifier and thus part of the sigil could also be enough.
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 added modifiers to ~r/~R. I'll save w
for another day/PR since it's not already broken out. Really if we're going to customize these any further we perhaps need a simple data table and then programmatically auto-generate all the sigil rules from that table. Are R and W really the only ones with modifiers?
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.
Are R and W really the only ones with modifiers?
At the moment yes, but the language syntax already allows for any sigil to have any modifier that it wants. That actually makes me realize that anyone can define their own custom sigil with their own modifiers 😅.
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.
Problems for another day. :) Does the PR look workable for now you 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 find it hard to judge the code, but from playing around with tools/developer.html
I discovered that there is a problem with uppercase R sigil. It still needs to support escaping the closing delimiter.
For example for those two pairs the output HTML should literally only differ by a single letter (r
<-> R
), but right now it tries to end the R sigil too early:
Regex.match?(~r|foo\|bar|, "foo")
Regex.match?(~R|foo\|bar|, "foo")
Regex.match?(~r(hello( there\)*!)u, "hello!")
Regex.match?(~R(hello( there\)*!)u, "hello!")
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.
Because I thought uppercase sigils didn't allow escaping. I guess escaping the end sigil character is the exception to the rule?
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.
Yes, that is the exception. Quoting the docs about the sigil R:
It returns a regular expression pattern without interpolations and without escape characters. Note it still supports escape of Regex tokens (such as escaping + or ?) and it also requires you to escape the closing sigil character itself if it appears on the Regex.
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 a lot 💜
@angelikatyborska Thanks for all the help. |
Resolves #3206 and other cleanups.
Changes
regex
Checklist
CHANGES.md