Skip to content

Commit

Permalink
Merge pull request #2038 from endersstocker/scope-elixir
Browse files Browse the repository at this point in the history
Add scopes to Elixir tags
  • Loading branch information
masatake committed Mar 12, 2019
2 parents b51837e + 443b88f commit e13416d
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 80 deletions.
4 changes: 2 additions & 2 deletions Units/parser-elixir.r/elixir-callbacks.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,3 +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
new_callback input.ex /^ @callback new_callback() :: integer$/;" callback module:CallbackModule
old_callback input.ex /^ defcallback old_callback(info :: integer) :: integer$/;" callback module:CallbackModule
2 changes: 1 addition & 1 deletion Units/parser-elixir.r/elixir-exceptions.b/expected.tags
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ModuleError input.ex /^defmodule ModuleError do$/;" module
ModuleError input.ex /^ defexception [:message]$/;" delegate
ModuleError input.ex /^ defexception [:message]$/;" delegate module:ModuleError
14 changes: 7 additions & 7 deletions Units/parser-elixir.r/elixir-functions.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,8 +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
one_liner_func input.ex /^ def one_liner_func, do: :baz$/;" function module:FunctionModule
func_no_params input.ex /^ def func_no_params do$/;" function module:FunctionModule
func_head input.ex /^ def func_head(string1, string2 \\\\ nil, separator \\\\ " ")$/;" function module:FunctionModule
func_one_arity input.ex /^ def func_one_arity(string1, nil, _separator) do$/;" function module:FunctionModule
normal_func input.ex /^ def normal_func(string1, string2, separator) do$/;" function module:FunctionModule
private_func input.ex /^ defp private_func(a), do: a <> " alone"$/;" function module:FunctionModule
private_func_no_params input.ex /^ defp private_func_no_params do$/;" function module:FunctionModule
8 changes: 4 additions & 4 deletions Units/parser-elixir.r/elixir-macros.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,5 +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
macro input.ex /^ defmacro macro(expr, opts) do$/;" macro module:MacroModule
macro_no_params input.ex /^ defmacro macro_no_params do$/;" macro module:MacroModule
private_macro input.ex /^ defmacrop private_macro(expr, opts) do$/;" macro module:MacroModule
private_macro_no_params input.ex /^ defmacrop private_macro_no_params do$/;" macro module:MacroModule
4 changes: 2 additions & 2 deletions Units/parser-elixir.r/elixir-records.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,3 +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
user1 input.ex /^ Record.defrecord(:user1, name: "megan", age: "25")$/;" record module:RecordsModule
user2 input.ex /^ Record.defrecordp :user2, name: "ivan", age: "23"$/;" record module:RecordsModule
38 changes: 19 additions & 19 deletions Units/parser-elixir.r/elixir-sign-operators.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,20 +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
+ input.ex /^ def a + b, do: max(a, b)$/;" operator module:OperatorModule
- input.ex /^ def a - b, do: max(a, b)$/;" operator module:OperatorModule
* input.ex /^ def a * b, do: max(a, b)$/;" operator module:OperatorModule
/ input.ex /^ def a \/ b, do: max(a, b)$/;" operator module:OperatorModule
= input.ex /^ def a = b, do: max(a, b)$/;" operator module:OperatorModule
. input.ex /^ def a . b, do: max(a, b)$/;" operator module:OperatorModule
| input.ex /^ def a | b, do: max(a, b)$/;" operator module:OperatorModule
||| input.ex /^ def _ ||| b, do: max(a, b)$/;" operator module:OperatorModule
&&& input.ex /^ def a &&& _, do: max(a, b)$/;" operator module:OperatorModule
<<< input.ex /^ def a <<< b, do: max(a, b)$/;" operator module:OperatorModule
>>> input.ex /^ defp a >>> b, do: max(a, b)$/;" operator module:OperatorModule
<<~ input.ex /^ defp _ <<~ _, do: max(a, b)$/;" operator module:OperatorModule
~>> input.ex /^ defp a ~>> b, do: max(a, b)$/;" operator module:OperatorModule
<~ input.ex /^ defmacro a <~ b, do: max(a, b)$/;" operator module:OperatorModule
~> input.ex /^ defmacro _ ~> b, do: max(a, b)$/;" operator module:OperatorModule
<~> input.ex /^ defmacro a <~> _, do: max(a, b)$/;" operator module:OperatorModule
<|> input.ex /^ defmacrop a <|> b, do: max(a, b)$/;" operator module:OperatorModule
^^^ input.ex /^ defmacrop _ ^^^ _, do: max(a, b)$/;" operator module:OperatorModule
~~~ input.ex /^ defmacrop a ~~~ b, do: max(a, b)$/;" operator module:OperatorModule
16 changes: 8 additions & 8 deletions Units/parser-elixir.r/elixir-simple.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,10 +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
reverse input.ex /^ defdelegate reverse(list), to: Enum$/;" delegate module:MyList
other_reverse input.ex /^ defdelegate other_reverse(list), to: Enum, as: :reverse$/;" delegate module:MyList
Size input.ex /^defprotocol Size do$/;" protocol module:MyList
size input.ex /^ def size(data)$/;" function module:MyList
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
is_even input.ex /^ defguard is_even(value) when is_integer(value) and rem(value, 2) == 0$/;" guard module:MyGuards
is_odd input.ex /^ defguardp is_odd(value) when is_integer(value) and rem(value, 2) != 0$/;" guard module:MyGuards
Size input.ex /^defimpl Size, for: BitString do$/;" implementation module:MyGuards
size input.ex /^ def size(binary), do: byte_size(binary)$/;" function module:MyGuards
4 changes: 2 additions & 2 deletions Units/parser-elixir.r/elixir-tests.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,3 +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
good with spaces input.ex /^ test "good with spaces" do$/;" test module:TestModule
good with parens input.ex /^ test("good with parens") do$/;" test module:TestModule
12 changes: 6 additions & 6 deletions Units/parser-elixir.r/elixir-word-operators.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,7 +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
and input.ex /^ def a and b, do: max(a, b)$/;" operator module:OperatorModule
or input.ex /^ def a or b, do: max(a, b)$/;" operator module:OperatorModule
not input.ex /^ defp a not b, do: max(a, b)$/;" operator module:OperatorModule
in input.ex /^ defmacro a in b, do: max(a, b)$/;" operator module:OperatorModule
not in input.ex /^ defmacrop a not in b, do: max(a, b)$/;" operator module:OperatorModule
when input.ex /^ defmacrop a when b, do: max(a, b)$/;" operator module:OperatorModule
33 changes: 17 additions & 16 deletions optlib/elixir.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ extern parserDefinition* ElixirParser (void)
};

static kindDefinition ElixirKindTable [] = {
{
true, 'm', "module", "modules (defmodule ...)",
},
{
true, 'f', "function", "functions (def ...)",
},
Expand All @@ -53,9 +56,6 @@ extern parserDefinition* ElixirParser (void)
{
true, 'o', "operator", "operators (e.g. \"defmacro a <<< b\")",
},
{
true, 'm', "module", "modules (defmodule ...)",
},
{
true, 'p', "protocol", "protocols (defprotocol...)",
},
Expand All @@ -67,30 +67,30 @@ extern parserDefinition* ElixirParser (void)
},
};
static tagRegexTable ElixirTagRegexTable [] = {
{"^[ \t]*defmodule[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"m", "{scope=set}", NULL, false},
{"^[ \t]*def((p?)|macro(p?))[ \t]+([a-zA-Z0-9_?!]+)[ \t]+([\\|\\^/&<>~.=!*+-]{1,3}|and|or|in|not|when|not in)[ \t]+[a-zA-Z0-9_?!]", "\\5",
"o", "{exclusive}", NULL, false},
"o", "{scope=ref}{exclusive}", NULL, false},
{"^[ \t]*def(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\\|\\^/&<>~.=!*+-]+)", "\\2",
"f", NULL, NULL, false},
"f", "{scope=ref}", NULL, false},
{"^[ \t]*(@|def)callback[ \t]+([a-z_][a-zA-Z0-9_?!]*)", "\\2",
"c", NULL, NULL, false},
"c", "{scope=ref}", NULL, false},
{"^[ \t]*defdelegate[ \t]+([a-z_][a-zA-Z0-9_?!]*)", "\\1",
"d", NULL, NULL, false},
"d", "{scope=ref}", NULL, false},
{"^[ \t]*defexception[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"e", NULL, NULL, false},
"e", "{scope=ref}", NULL, false},
{"^[ \t]*defguard(p?)[ \t]+(is_[a-zA-Z0-9_?!]+)", "\\2",
"g", NULL, NULL, false},
"g", "{scope=ref}", NULL, false},
{"^[ \t]*defimpl[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"i", NULL, NULL, false},
"i", "{scope=ref}", NULL, false},
{"^[ \t]*defmacro(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\\|\\^/&<>~.=!*+-]+)", "\\2",
"a", NULL, NULL, false},
{"^[ \t]*defmodule[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"m", NULL, NULL, false},
"a", "{scope=ref}", NULL, false},
{"^[ \t]*defprotocol[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"p", NULL, NULL, false},
"p", "{scope=ref}", NULL, false},
{"^[ \t]*Record\\.defrecord(p?)[ \t(]+:([a-zA-Z0-9_]+)(\\)?)", "\\2",
"r", NULL, NULL, false},
"r", "{scope=ref}", NULL, false},
{"^[ \t]*test[ \t(]+\"([a-z_][a-zA-Z0-9_?! ]*)\"*(\\)?)[ \t]*do", "\\1",
"t", NULL, NULL, false},
"t", "{scope=ref}", NULL, false},
};


Expand All @@ -101,6 +101,7 @@ extern parserDefinition* ElixirParser (void)
def->patterns = patterns;
def->aliases = aliases;
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
def->useCork = 1;
def->kindTable = ElixirKindTable;
def->kindCount = ARRAY_SIZE(ElixirKindTable);
def->tagRegexTable = ElixirTagRegexTable;
Expand Down
26 changes: 13 additions & 13 deletions optlib/elixir.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
--map-Elixir=+.ex
--map-Elixir=+.exs

--kinddef-Elixir=m,module,modules (defmodule ...)
--kinddef-Elixir=f,function,functions (def ...)
--kinddef-Elixir=c,callback,callbacks (defcallback ...)
--kinddef-Elixir=d,delegate,delegates (defdelegate ...)
Expand All @@ -60,20 +61,19 @@
--kinddef-Elixir=i,implementation,implementations (defimpl ...)
--kinddef-Elixir=a,macro,macros (defmacro ...)
--kinddef-Elixir=o,operator,operators (e.g. "defmacro a <<< b")
--kinddef-Elixir=m,module,modules (defmodule ...)
--kinddef-Elixir=p,protocol,protocols (defprotocol...)
--kinddef-Elixir=r,record,records (defrecord...)
--kinddef-Elixir=t,test,tests (test ...)

--regex-Elixir=/^[ \t]*def((p?)|macro(p?))[ \t]+([a-zA-Z0-9_?!]+)[ \t]+([\|\^\/&<>~.=!*+-]{1,3}|and|or|in|not|when|not in)[ \t]+[a-zA-Z0-9_?!]/\5/o/{exclusive}
--regex-Elixir=/^[ \t]*def(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\|\^\/&<>~.=!*+-]+)/\2/f/
--regex-Elixir=/^[ \t]*(@|def)callback[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\2/c/
--regex-Elixir=/^[ \t]*defdelegate[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\1/d/
--regex-Elixir=/^[ \t]*defexception[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/e/
--regex-Elixir=/^[ \t]*defguard(p?)[ \t]+(is_[a-zA-Z0-9_?!]+)/\2/g/
--regex-Elixir=/^[ \t]*defimpl[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/i/
--regex-Elixir=/^[ \t]*defmacro(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\|\^\/&<>~.=!*+-]+)/\2/a/
--regex-Elixir=/^[ \t]*defmodule[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/m/
--regex-Elixir=/^[ \t]*defprotocol[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/p/
--regex-Elixir=/^[ \t]*Record\.defrecord(p?)[ \t(]+:([a-zA-Z0-9_]+)(\)?)/\2/r/
--regex-Elixir=/^[ \t]*test[ \t(]+"([a-z_][a-zA-Z0-9_?! ]*)"*(\)?)[ \t]*do/\1/t/
--regex-Elixir=/^[ \t]*defmodule[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/m/{scope=set}
--regex-Elixir=/^[ \t]*def((p?)|macro(p?))[ \t]+([a-zA-Z0-9_?!]+)[ \t]+([\|\^\/&<>~.=!*+-]{1,3}|and|or|in|not|when|not in)[ \t]+[a-zA-Z0-9_?!]/\5/o/{scope=ref}{exclusive}
--regex-Elixir=/^[ \t]*def(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\|\^\/&<>~.=!*+-]+)/\2/f/{scope=ref}
--regex-Elixir=/^[ \t]*(@|def)callback[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\2/c/{scope=ref}
--regex-Elixir=/^[ \t]*defdelegate[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\1/d/{scope=ref}
--regex-Elixir=/^[ \t]*defexception[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/e/{scope=ref}
--regex-Elixir=/^[ \t]*defguard(p?)[ \t]+(is_[a-zA-Z0-9_?!]+)/\2/g/{scope=ref}
--regex-Elixir=/^[ \t]*defimpl[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/i/{scope=ref}
--regex-Elixir=/^[ \t]*defmacro(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\|\^\/&<>~.=!*+-]+)/\2/a/{scope=ref}
--regex-Elixir=/^[ \t]*defprotocol[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/p/{scope=ref}
--regex-Elixir=/^[ \t]*Record\.defrecord(p?)[ \t(]+:([a-zA-Z0-9_]+)(\)?)/\2/r/{scope=ref}
--regex-Elixir=/^[ \t]*test[ \t(]+"([a-z_][a-zA-Z0-9_?! ]*)"*(\)?)[ \t]*do/\1/t/{scope=ref}

0 comments on commit e13416d

Please sign in to comment.