Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Units/simple-elixir.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+K
3 changes: 3 additions & 0 deletions Units/simple-elixir.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
drive input.ex /^def drive(%User{age: age}) when age >= 16 do$/;" function
MathTest input.ex /^defmodule MathTest do$/;" module
can add two numbers input.ex /^ test "can add two numbers" do$/;" test
18 changes: 18 additions & 0 deletions Units/simple-elixir.d/input.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Taken from https://elixir-lang.org/
#

def drive(%User{age: age}) when age >= 16 do
# Code that drives a car
end

drive(User.get("John Doe"))
#=> Fails if the user is under 16

defmodule MathTest do
use ExUnit.Case, async: true

test "can add two numbers" do
assert 1 + 1 == 2
end
end
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
DTSParser, \
DosBatchParser, \
EiffelParser, \
ElixirParser, \
ElmParser, \
ErlangParser, \
FalconParser, \
Expand Down
1 change: 1 addition & 0 deletions makefiles/translator_input.mak
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
TRANSLATOR_INPUT = \
optlib/RSpec.ctags \
optlib/ctags-optlib.ctags \
optlib/elixir.ctags \
optlib/elm.ctags \
optlib/gdbinit.ctags \
optlib/man.ctags \
Expand Down
29 changes: 25 additions & 4 deletions misc/optlib2c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,23 @@ sub emit_patterns {
emit_list $_[0], "patterns";
}

sub escape_dquotes {
my $input = shift;
my $output = "";

my $c;

foreach $c (split //, $input) {
if ($c eq '"') {
$output = $output . '\\' . '"';
} else {
$output = $output . $c;
}
}

return $output;
}

sub emit_roledefs {
my $opts = shift;

Expand All @@ -521,8 +538,9 @@ sub emit_roledefs {
static roleDefinition $opts->{'Clangdef'}${Kind}RoleTable [] = {
EOF
for (@{$_->{'roles'}}) {
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
{ true, "$_->{'name'}", "$_->{'desc'}" },
{ true, "$_->{'name'}", "$desc" },
EOF
}

Expand All @@ -546,8 +564,9 @@ EOF
print <<EOF;
{
EOF
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
true, \'$_->{'letter'}\', "$_->{'name'}", "$_->{'desc'}",
true, \'$_->{'letter'}\', "$_->{'name'}", "$desc",
EOF
if ($_->{'refonly'}) {
print <<EOF;
Expand Down Expand Up @@ -633,11 +652,12 @@ sub emit_xtags {
EOF
for (@{$opts->{'extradefs'}}) {
my $enabled = $_->{"enabled"}? "true": "false";
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
{
.enabled = $enabled,
.name = "$_->{'name'}",
.description = "$_->{'desc'}",
.description = "$desc",
},
EOF
}
Expand All @@ -656,11 +676,12 @@ sub emit_fields {
EOF
for (@{$opts->{'fielddefs'}}) {
my $enabled = $_->{"enabled"}? "true": "false";
my $desc = escape_dquotes $_->{'desc'};
print <<EOF;
{
.enabled = $enabled,
.name = "$_->{'name'}",
.description = "$_->{'desc'}",
.description = "$desc",
},
EOF
}
Expand Down
104 changes: 104 additions & 0 deletions optlib/elixir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Generated by ./misc/optlib2c from optlib/elixir.ctags, Don't edit this manually.
*/
#include "general.h"
#include "parse.h"
#include "routines.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 <[email protected]> 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 @@ -140,6 +140,7 @@
<ClCompile Include="..\main\xtag.c" />
<ClCompile Include="..\optlib\RSpec.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 @@ -174,6 +174,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