-
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
enh(elixir) Improves and fixes many issues with Elixir grammar #3212
Changes from 3 commits
76a58ed
1385181
4d17178
740119b
5f78052
67c5e97
e929414
969b834
c90b2f4
729dec8
3605ef9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,10 @@ end | |
|
||
def f!, do: IO.puts "hello world" | ||
|
||
defp f?, do: true | ||
|
||
defmacro foo, do: :ok | ||
|
||
defmacrop do_foo, do: :ok | ||
|
||
x = 5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">User</span></span> <span class="hljs-keyword">do</span> | ||
<span class="hljs-class"><span class="hljs-keyword">defstruct</span></span> [<span class="hljs-symbol">:name</span>, <span class="hljs-symbol">:email</span>, <span class="hljs-symbol">age:</span> <span class="hljs-number">18</span>] | ||
<span class="hljs-keyword">end</span> | ||
|
||
<span class="hljs-class"><span class="hljs-keyword">defprotocol</span> <span class="hljs-title">Size</span></span> <span class="hljs-keyword">do</span> | ||
<span class="hljs-variable">@doc</span> <span class="hljs-string">"Calculates the size (and not the length!) of a data structure"</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">size</span></span>(data) | ||
<span class="hljs-keyword">end</span> | ||
|
||
<span class="hljs-class"><span class="hljs-keyword">defimpl</span> <span class="hljs-title">Size</span></span>, <span class="hljs-symbol">for:</span> Map <span class="hljs-keyword">do</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">size</span></span>(map), <span class="hljs-symbol">do:</span> map_size(map) | ||
<span class="hljs-keyword">end</span> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule User do | ||
defstruct [:name, :email, age: 18] | ||
end | ||
|
||
defprotocol Size do | ||
@doc "Calculates the size (and not the length!) of a data structure" | ||
def size(data) | ||
end | ||
|
||
defimpl Size, for: Map do | ||
def size(map), do: map_size(map) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
a = <span class="hljs-string">"""test"""</span> | ||
b = <span class="hljs-string">'''test'''</span> | ||
a = <span class="hljs-string">""" | ||
test | ||
"""</span> | ||
b = <span class="hljs-string">''' | ||
test | ||
'''</span> | ||
c = <span class="hljs-string">"test"</span> | ||
d = <span class="hljs-string">'test'</span> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
a = """test""" | ||
b = '''test''' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see how these are better examples (that you added), but if the previous were valid we should also leave them to serve as additional regression tests... one can still use a multi-line string for a single line - that is valid grammar, yes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, those were syntax errors in Elixir. The only allowed characters after the opening My assumption is that it's not a big deal if the syntax highlighting colors something that doesn't compile so I didn't feel the need to change the regexes for multiline strings, but the test examples should be valid Elixir code, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Whoa. I stand corrected. ;-)
Right, it's not our job to detect invalid code.
For the most part, yes. In this particular case this indeed makes sense. I just see people "swap" test cases often when they should be adding new cases instead, [not removing old ones]. Thought this was perhaps yet another case of that. :) |
||
a = """ | ||
test | ||
""" | ||
b = ''' | ||
test | ||
''' | ||
c = "test" | ||
d = 'test' |
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.
class
is deprecated now. More likely you'd want this to be a newer multi-match rule and then usetitle.class
for the name of the struct... Seewren.js
for examples. I can also do this myself after though... I already had a few commits patching the other declarations to the newer standard but decided they didn't fit in our regex fix PR.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.
Hmm... since the struct's name is not part of the
defstruct
call but it's defined by the module name in whichdefstruct
is called, I think I just need to makedefstruct
a keyword instead?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.
Ah, yes, just a keyword then for
defstruct
...defmodule
though would probably be a multi-matcher.