Skip to content

Commit

Permalink
Elixir: new parser
Browse files Browse the repository at this point in the history
Imported from https://github.com/mmorearty/elixir-ctags.
Close universal-ctags#1758.
See also mmorearty/elixir-ctags#5.

The change from the original .ctags.

* Put the original LICENSE file as the header of the .ctags.
* Use --map= option instead of --langmap because optlib2c doesn't handle
  --langmap option.
* Define kinds explicitly with --kinddef-<LANG> option.
* Remove backslashes before double quotes chars in the regex pattern for
  "test".
* Use singular forms for kind names.

TODO: Test cases for above kinds are needed.

    c  callbacks (defcallback ...)
    d  delegates (defdelegate ...)
    e  exceptions (defexception ...)
    i  implementations (defimpl ...)
    a  macros (defmacro ...)
    o  operators (e.g. "defmacro a <<< b")
    p  protocols (defprotocol...)
    r  records (defrecord...)
  • Loading branch information
masatake committed Mar 7, 2019
1 parent 6cecfb9 commit 1c38aec
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The following parsers have been added:
* Diff
* DTD
* DTS
* Elixir *optlib*
* Elm *optlib*
* Falcon
* Gdbinit script *optlib*
Expand Down
1 change: 1 addition & 0 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
DTSParser, \
DosBatchParser, \
EiffelParser, \
ElixirParser, \
ElmParser, \
ErlangParser, \
FalconParser, \
Expand Down
3 changes: 2 additions & 1 deletion makefiles/optlib2c_input.mak
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
optlib/gdbinit.ctags \
optlib/man.ctags \
optlib/markdown.ctags \
Expand Down
106 changes: 106 additions & 0 deletions optlib/elixir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Generated by ./misc/optlib2c from optlib/elixir.ctags, Don't edit this manually.
*/
#include "general.h"
#include "parse.h"
#include "routines.h"
#include "field.h"
#include "xtag.h"


static void initializeElixirParser (const langType language CTAGS_ATTR_UNUSED)
{
}

extern parserDefinition* ElixirParser (void)
{
static const char *const extensions [] = {
"ex",
"exs",
NULL
};

static const char *const aliases [] = {
NULL
};

static const char *const patterns [] = {
NULL
};

static kindDefinition ElixirKindTable [] = {
{
true, 'f', "function", "functions (def ...)",
},
{
true, 'c', "callback", "callbacks (defcallback ...)",
},
{
true, 'd', "delegate", "delegates (defdelegate ...)",
},
{
true, 'e', "exception", "exceptions (defexception ...)",
},
{
true, 'i', "implementation", "implementations (defimpl ...)",
},
{
true, 'a', "macro", "macros (defmacro ...)",
},
{
true, 'o', "operator", "operators (e.g. \"defmacro a <<< b\")",
},
{
true, 'm', "module", "modules (defmodule ...)",
},
{
true, 'p', "protocol", "protocols (defprotocol...)",
},
{
true, 'r', "record", "records (defrecord...)",
},
{
true, 't', "test", "tests (test ...)",
},
};
static tagRegexTable ElixirTagRegexTable [] = {
{"^[ \t]*def(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)", "\\2",
"f", NULL, NULL, false},
{"^[ \t]*defcallback[ \t]+([a-z_][a-zA-Z0-9_?!]*)", "\\1",
"c", NULL, NULL, false},
{"^[ \t]*defdelegate[ \t]+([a-z_][a-zA-Z0-9_?!]*)", "\\1",
"d", NULL, NULL, false},
{"^[ \t]*defexception[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"e", NULL, NULL, false},
{"^[ \t]*defimpl[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"i", NULL, NULL, false},
{"^[ \t]*defmacro(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)\\(", "\\2",
"a", NULL, NULL, false},
{"^[ \t]*defmacro(p?)[ \t]+([a-zA-Z0-9_?!]+)?[ \t]+([^ \tA-Za-z0-9_]+)[ \t]*[a-zA-Z0-9_!?!]", "\\3",
"o", NULL, NULL, false},
{"^[ \t]*defmodule[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"m", NULL, NULL, false},
{"^[ \t]*defprotocol[ \t]+([A-Z][a-zA-Z0-9_]*\\.)*([A-Z][a-zA-Z0-9_?!]*)", "\\2",
"p", NULL, NULL, false},
{"^[ \t]*Record\\.defrecord[ \t]+:([a-zA-Z0-9_]+)", "\\1",
"r", NULL, NULL, false},
{"^[ \t]*test[ \t]+\"([a-z_][a-zA-Z0-9_?! ]*)\"*", "\\1",
"t", NULL, NULL, false},
};


parserDefinition* const def = parserNew ("Elixir");

def->enabled = true;
def->extensions = extensions;
def->patterns = patterns;
def->aliases = aliases;
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
def->kindTable = ElixirKindTable;
def->kindCount = ARRAY_SIZE(ElixirKindTable);
def->tagRegexTable = ElixirTagRegexTable;
def->tagRegexCount = ARRAY_SIZE(ElixirTagRegexTable);
def->initialize = initializeElixirParser;

return def;
}
77 changes: 77 additions & 0 deletions optlib/elixir.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org>
#

#
# WHEN FIXING A BUG OF THIS PARSER, WORK WITH THE UPSTREAM PROJECT.
#

#
# This file is imported from https://github.com/mmorearty/elixir-ctags
# by Masatake YAMATO <yamato@redhat.com> with some modifications.
# See https://github.com/mmorearty/elixir-ctags/issues/5 and
# https://github.com/universal-ctags/ctags/issues/1758#issuecomment-391692762.
# @dylan-chong and @FredrikAugust realized this u-ctags integration.
#

#
# * Put the original LICENSE file as the header of the .ctags.
# * Use --map= option instead of --langmap because optlib2c doesn't handle
# --langmap option.
# * Define kinds explicitly with --kinddef-<LANG> option.
# * Remove backslashes before double quotes chars in the regex pattern for
# "test".
# * Use singular forms for kind names.
#

--langdef=Elixir

--map-Elixir=+.ex
--map-Elixir=+.exs

--kinddef-Elixir=f,function,functions (def ...)
--kinddef-Elixir=c,callback,callbacks (defcallback ...)
--kinddef-Elixir=d,delegate,delegates (defdelegate ...)
--kinddef-Elixir=e,exception,exceptions (defexception ...)
--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?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\2/f/
--regex-Elixir=/^[ \t]*defcallback[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\1/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]*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]*defmacro(p?)[ \t]+([a-zA-Z0-9_?!]+)?[ \t]+([^ \tA-Za-z0-9_]+)[ \t]*[a-zA-Z0-9_!?!]/\3/o/
--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[ \t]+:([a-zA-Z0-9_]+)/\1/r/
--regex-Elixir=/^[ \t]*test[ \t]+"([a-z_][a-zA-Z0-9_?! ]*)"*/\1/t/
1 change: 1 addition & 0 deletions win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<ClCompile Include="..\optlib\RSpec.c" />
<ClCompile Include="..\optlib\cmake.c" />
<ClCompile Include="..\optlib\ctags-optlib.c" />
<ClCompile Include="..\optlib\elixir.c" />
<ClCompile Include="..\optlib\elm.c" />
<ClCompile Include="..\optlib\gdbinit.c" />
<ClCompile Include="..\optlib\man.c" />
Expand Down
3 changes: 3 additions & 0 deletions win32/ctags_vs2013.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
<ClCompile Include="..\optlib\ctags-optlib.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
<ClCompile Include="..\optlib\elixir.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
<ClCompile Include="..\optlib\elm.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
Expand Down

0 comments on commit 1c38aec

Please sign in to comment.