-
Notifications
You must be signed in to change notification settings - Fork 641
Improved Elixir optlib parser #2024
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
Changes from all commits
adf6cdc
ffd1e98
e06ed3a
37bb27e
1ad9b8d
5aec4f8
3161d4f
c0aca49
eff912a
88a6546
ef545ae
750386c
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CallbackModule input.ex /^defmodule CallbackModule do$/;" module | ||
new_callback input.ex /^ @callback new_callback() :: integer$/;" callback | ||
old_callback input.ex /^ defcallback old_callback(info :: integer) :: integer$/;" callback |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule CallbackModule do | ||
use Behaviour | ||
# This is the new callback syntax | ||
@callback new_callback() :: integer | ||
|
||
# This is the old (deprecated) callback syntax | ||
defcallback old_callback(info :: integer) :: integer | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Exceptions are defined like structs but their name is the name of module they | ||
are defined in. For this I'll have to use a multiline regex | ||
(`--mline-regex-<LANG>`) which I don't know yet how to use. | ||
|
||
This is more a TODO than a bug. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ModuleError input.ex /^defmodule ModuleError do$/;" module | ||
ModuleError input.ex /^ defexception [:message]$/;" delegate |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule ErrorModule do | ||
defexception [:message] | ||
|
||
@impl true | ||
def exception(value) do | ||
msg = "did not get what was expected, got: #{inspect(value)}" | ||
%ErrorModule{message: msg} | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FunctionModule input.ex /^defmodule FunctionModule do$/;" module | ||
one_liner_func input.ex /^ def one_liner_func, do: :baz$/;" function | ||
func_no_params input.ex /^ def func_no_params do$/;" function | ||
func_head input.ex /^ def func_head(string1, string2 \\\\ nil, separator \\\\ " ")$/;" function | ||
func_one_arity input.ex /^ def func_one_arity(string1, nil, _separator) do$/;" function | ||
normal_func input.ex /^ def normal_func(string1, string2, separator) do$/;" function | ||
private_func input.ex /^ defp private_func(a), do: a <> " alone"$/;" function | ||
private_func_no_params input.ex /^ defp private_func_no_params do$/;" function |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule FunctionModule do | ||
def one_liner_func, do: :baz | ||
|
||
def func_no_params do | ||
# | ||
end | ||
|
||
# Function head | ||
def func_head(string1, string2 \\ nil, separator \\ " ") | ||
|
||
# Function with 1 arity | ||
def func_one_arity(string1, nil, _separator) do | ||
private_function(string1) | ||
end | ||
|
||
# Normal function | ||
def normal_func(string1, string2, separator) do | ||
string1 <> separator <> string2 | ||
end | ||
|
||
# Private function | ||
defp private_func(a), do: a <> " alone" | ||
|
||
defp private_func_no_params do | ||
# | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MacroModule input.ex /^defmodule MacroModule do$/;" module | ||
macro input.ex /^ defmacro macro(expr, opts) do$/;" macro | ||
macro_no_params input.ex /^ defmacro macro_no_params do$/;" macro | ||
private_macro input.ex /^ defmacrop private_macro(expr, opts) do$/;" macro | ||
private_macro_no_params input.ex /^ defmacrop private_macro_no_params do$/;" macro |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule MacroModule do | ||
defmacro macro(expr, opts) do | ||
# | ||
end | ||
|
||
defmacro macro_no_params do | ||
# | ||
end | ||
|
||
defmacrop private_macro(expr, opts) do | ||
# | ||
end | ||
|
||
defmacrop private_macro_no_params do | ||
# | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Foo input.ex /^defmodule Foo do$/;" module | ||
Bar input.ex /^defmodule Foo.Bar do$/;" module | ||
Baz input.ex /^ defmodule Baz do$/;" module |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule Foo do | ||
end | ||
|
||
defmodule Foo.Bar do | ||
defmodule Baz do | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RecordsModule input.ex /^defmodule RecordsModule do$/;" module | ||
user1 input.ex /^ Record.defrecord(:user1, name: "megan", age: "25")$/;" record | ||
user2 input.ex /^ Record.defrecordp :user2, name: "ivan", age: "23"$/;" record |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule RecordsModule do | ||
require Record | ||
Record.defrecord(:user1, name: "megan", age: "25") | ||
Record.defrecordp :user2, name: "ivan", age: "23" | ||
# This is not a typo but an intentional bad test, used to test the parser | ||
Record.defrecordp:bad, name: "ivan", age: "23" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
OperatorModule input.ex /^defmodule OperatorModule do$/;" module | ||
+ input.ex /^ def a + b, do: max(a, b)$/;" operator | ||
- input.ex /^ def a - b, do: max(a, b)$/;" operator | ||
* input.ex /^ def a * b, do: max(a, b)$/;" operator | ||
/ input.ex /^ def a \/ b, do: max(a, b)$/;" operator | ||
= input.ex /^ def a = b, do: max(a, b)$/;" operator | ||
. input.ex /^ def a . b, do: max(a, b)$/;" operator | ||
| input.ex /^ def a | b, do: max(a, b)$/;" operator | ||
||| input.ex /^ def _ ||| b, do: max(a, b)$/;" operator | ||
&&& input.ex /^ def a &&& _, do: max(a, b)$/;" operator | ||
<<< input.ex /^ def a <<< b, do: max(a, b)$/;" operator | ||
>>> input.ex /^ defp a >>> b, do: max(a, b)$/;" operator | ||
<<~ input.ex /^ defp _ <<~ _, do: max(a, b)$/;" operator | ||
~>> input.ex /^ defp a ~>> b, do: max(a, b)$/;" operator | ||
<~ input.ex /^ defmacro a <~ b, do: max(a, b)$/;" operator | ||
~> input.ex /^ defmacro _ ~> b, do: max(a, b)$/;" operator | ||
<~> input.ex /^ defmacro a <~> _, do: max(a, b)$/;" operator | ||
<|> input.ex /^ defmacrop a <|> b, do: max(a, b)$/;" operator | ||
^^^ input.ex /^ defmacrop _ ^^^ _, do: max(a, b)$/;" operator | ||
~~~ input.ex /^ defmacrop a ~~~ b, do: max(a, b)$/;" operator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule OperatorModule do | ||
def a + b, do: max(a, b) | ||
def a - b, do: max(a, b) | ||
def a * b, do: max(a, b) | ||
def a / b, do: max(a, b) | ||
def a = b, do: max(a, b) | ||
def a . b, do: max(a, b) | ||
|
||
# The 13 operators bellow are ALL the operators that Elixir is CAPABLE of | ||
# parsing and are not used by default, so the user can | ||
def a | b, do: max(a, b) | ||
def _ ||| b, do: max(a, b) | ||
def a &&& _, do: max(a, b) | ||
def a <<< b, do: max(a, b) | ||
defp a >>> b, do: max(a, b) | ||
defp _ <<~ _, do: max(a, b) | ||
defp a ~>> b, do: max(a, b) | ||
defmacro a <~ b, do: max(a, b) | ||
defmacro _ ~> b, do: max(a, b) | ||
defmacro a <~> _, do: max(a, b) | ||
defmacrop a <|> b, do: max(a, b) | ||
defmacrop _ ^^^ _, do: max(a, b) | ||
defmacrop a ~~~ b, do: max(a, b) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
MyList input.ex /^defmodule MyList do$/;" module | ||
reverse input.ex /^ defdelegate reverse(list), to: Enum$/;" delegate | ||
other_reverse input.ex /^ defdelegate other_reverse(list), to: Enum, as: :reverse$/;" delegate | ||
Size input.ex /^defprotocol Size do$/;" protocol | ||
size input.ex /^ def size(data)$/;" function | ||
MyGuards input.ex /^defmodule Integer.MyGuards do$/;" module | ||
is_even input.ex /^ defguard is_even(value) when is_integer(value) and rem(value, 2) == 0$/;" guard | ||
is_odd input.ex /^ defguardp is_odd(value) when is_integer(value) and rem(value, 2) != 0$/;" guard | ||
Size input.ex /^defimpl Size, for: BitString do$/;" implementation | ||
size input.ex /^ def size(binary), do: byte_size(binary)$/;" function |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Most of this code is taken from the official Elixir documentation. | ||
# With comments and modifications | ||
# by Ivan Gonzalez Polanco <[email protected]> | ||
# | ||
# This code doesn't compile, since it's supposed to test de ctags elixir | ||
# parser, not the elixir elixir parser. | ||
|
||
# | ||
# d delegates (defdelegate ...) | ||
# | ||
defmodule MyList do | ||
defdelegate reverse(list), to: Enum | ||
defdelegate other_reverse(list), to: Enum, as: :reverse | ||
end | ||
|
||
# | ||
# p protocols (defprotocol ...) | ||
# | ||
defprotocol Size do | ||
@doc "Calculates the size (and not the length!) of a data structure" | ||
def size(data) | ||
end | ||
|
||
# | ||
# g guards (defguard ...) | ||
# | ||
defmodule Integer.MyGuards do | ||
defguard is_even(value) when is_integer(value) and rem(value, 2) == 0 | ||
defguardp is_odd(value) when is_integer(value) and rem(value, 2) != 0 | ||
end | ||
|
||
# | ||
# i implementations (defimpl ...) | ||
# | ||
defimpl Size, for: BitString do | ||
def size(binary), do: byte_size(binary) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TestModule input.ex /^defmodule TestModule do$/;" module | ||
good with spaces input.ex /^ test "good with spaces" do$/;" test | ||
good with parens input.ex /^ test("good with parens") do$/;" test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule TestModule do | ||
use ExUnit.Case, async: true | ||
|
||
test "good with spaces" do | ||
assert 1 + 1 == 2 | ||
end | ||
|
||
test("good with parens") do | ||
assert 1 + 1 == 2 | ||
end | ||
test"bad without spaces" do | ||
assert 1 + 1 == 2 | ||
end | ||
|
||
test "bad without 'do' word" | ||
assert 1 + 1 == 2 | ||
end | ||
|
||
test 'bad with single quotes' do | ||
assert 1 + 1 == 2 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+K |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
OperatorModule input.ex /^defmodule OperatorModule do$/;" module | ||
and input.ex /^ def a and b, do: max(a, b)$/;" operator | ||
or input.ex /^ def a or b, do: max(a, b)$/;" operator | ||
not input.ex /^ defp a not b, do: max(a, b)$/;" operator | ||
in input.ex /^ defmacro a in b, do: max(a, b)$/;" operator | ||
not in input.ex /^ defmacrop a not in b, do: max(a, b)$/;" operator | ||
when input.ex /^ defmacrop a when b, do: max(a, b)$/;" operator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule OperatorModule do | ||
def a and b, do: max(a, b) | ||
def a or b, do: max(a, b) | ||
defp a not b, do: max(a, b) | ||
defmacro a in b, do: max(a, b) | ||
defmacrop a not in b, do: max(a, b) | ||
defmacrop a when b, do: max(a, b) | ||
end |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3,7 +3,8 @@ OPTLIB2C_INPUT = \ | |||||||
optlib/RSpec.ctags \ | ||||||||
optlib/cmake.ctags \ | ||||||||
optlib/ctags-optlib.ctags \ | ||||||||
optlib/elm.ctags \ | ||||||||
optlib/elixir.ctags \ | ||||||||
optlib/elm.ctags \ | ||||||||
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. You should not touch elm.ctags. 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. 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. (trying out Github's suggestions feature, sorry if it's messy)
Suggested change
|
||||||||
optlib/gdbinit.ctags \ | ||||||||
optlib/man.ctags \ | ||||||||
optlib/markdown.ctags \ | ||||||||
|
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.
Excellent.