Skip to content
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

Elm: Add support for Elm-Lang via optlib #1260

Merged
merged 9 commits into from
Jan 31, 2017
Merged
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
1 change: 1 addition & 0 deletions Units/simple-elm.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
14 changes: 14 additions & 0 deletions Units/simple-elm.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Main input.elm /^port module Main exposing (..)$/;" m
Je input.elm /^import Json.Encode as Je$/;" n
Thing input.elm /^type Thing$/;" t
One input.elm /^ = One$/;" c type:Thing
Two Int input.elm /^ | Two Int$/;" c type:Thing
Param a input.elm /^type Param a$/;" t
Cons a input.elm /^ = Cons a$/;" c type:Param a
Other a input.elm /^ | Other a$/;" c type:Param a
Num input.elm /^type alias Num =$/;" a
outward input.elm /^port outward : String -> Cmd a$/;" p
inward input.elm /^port inward : (b -> a) -> Sub a$/;" p
foo input.elm /^foo a =$/;" f
bar input.elm /^bar =$/;" f
bas input.elm /^ bas =$/;" f function:bar
38 changes: 38 additions & 0 deletions Units/simple-elm.d/input.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
port module Main exposing (..)

import List
import Maybe exposing (withDefault)
import Json.Encode as Je


type Thing
= One
| Two Int


type Param a
= Cons a
| Other a


type alias Num =
Int


port outward : String -> Cmd a


port inward : (b -> a) -> Sub a


foo : Int -> Int
foo a =
a + 1


bar =
let
bas =
1
in
bas
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following parsers have been added:
* Diff
* DTD
* DTS
* Elm *optlib*
* Falcon
* Glade *libxml*
* Go
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, \
ElmParser, \
ErlangParser, \
FalconParser, \
FlexParser, \
Expand Down
1 change: 1 addition & 0 deletions makefiles/translator_input.mak
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TRANSLATOR_INPUT = \
optlib/CoffeeScript.ctags \
optlib/ctags-optlib.ctags \
optlib/elm.ctags \
optlib/gdbinit.ctags \
optlib/man.ctags \
optlib/pod.ctags \
Expand Down
64 changes: 64 additions & 0 deletions optlib/elm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Generated by ./misc/optlib2c from optlib/elm.ctags, Don't edit this manually.
*/
#include "general.h"
#include "parse.h"
#include "routines.h"


static void initializeElmParser (const langType language CTAGS_ATTR_UNUSED)
{
}

extern parserDefinition* ElmParser (void)
{
static const char *const extensions [] = {
"elm",
NULL
};

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

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

static tagRegexTable ElmTagRegexTable [] = {
{"^(port[[:blank:]]+)?module[[:blank:]]+([[:upper:]][[:alnum:]_.]*)", "\\2",
"m,module,Module", "{scope=push}{exclusive}"},
{"^import[[:blank:]]+[[:alnum:]_.]+[[:blank:]]+as[[:blank:]]+([[:alnum:]]+)", "\\1",
"n,namespace,Renamed Imported Module", "{scope=clear}{exclusive}"},
{"^import[[:blank:]]+([[:alnum:]_.]+)[[:blank:]]exposing", "",
"", "{scope=clear}{exclusive}"},
{"^import[[:blank:]]+([[:alnum:]_.]+)", "",
"", "{scope=clear}{exclusive}"},
{"^port[[:blank:]]+([[:lower:]][[:alnum:]_]*).*", "\\1",
"p,port,Port", "{scope=clear}{exclusive}"},
{"^type +([[:upper:]][[:alnum:]_]*.*)", "\\1",
"t,type,Type Definition", "{scope=set}{exclusive}"},
{"^[[:blank:]]+[|=][[:blank:]]+([[:upper:]][[:alnum:]_]*.*)$", "\\1",
"c,constructor,Type Constructor", "{scope=ref}{exclusive}"},
{"^type[[:blank:]]+alias[[:blank:]]+([[:upper:]][[:alnum:]_]*[[:blank:][:alnum:]_]*)", "\\1",
"a,alias,Type Alias", "{scope=set}{exclusive}"},
{"^([[:lower:]_][[:alnum:]_]*)[^=]*=$", "\\1",
"f,function,Functions", "{scope=set}"},
{"^[[:blank:]]+([[:lower:]_][[:alnum:]_]*)[^=]*=$", "\\1",
"f,function,Functions", "{scope=ref}"},
};


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

def->enabled = true;
def->extensions = extensions;
def->patterns = patterns;
def->aliases = aliases;
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
def->tagRegexTable = ElmTagRegexTable;
def->tagRegexCount = ARRAY_SIZE(ElmTagRegexTable);
def->initialize = initializeElmParser;

return def;
}
35 changes: 35 additions & 0 deletions optlib/elm.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (c) 2016, Mark Skipper
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
#
--langdef=elm
--map-elm=+.elm
--regex-elm=/^(port[[:blank:]]+)?module[[:blank:]]+([[:upper:]][[:alnum:]_.]*)/\2/m,module,Module/{scope=push}{exclusive}
--regex-elm=/^import[[:blank:]]+[[:alnum:]_.]+[[:blank:]]+as[[:blank:]]+([[:alnum:]]+)/\1/n,namespace,Renamed Imported Module/{scope=clear}{exclusive}
#
# Following two patterns are just for clearing scope stack.
# X in "import X" should be captured as a reference tag in the future.
#
--regex-elm=/^import[[:blank:]]+([[:alnum:]_.]+)[[:blank:]]exposing///{scope=clear}{exclusive}
--regex-elm=/^import[[:blank:]]+([[:alnum:]_.]+)///{scope=clear}{exclusive}
--regex-elm=/^port[[:blank:]]+([[:lower:]][[:alnum:]_]*).*/\1/p,port,Port/{scope=clear}{exclusive}
--regex-elm=/^type +([[:upper:]][[:alnum:]_]*.*)/\1/t,type,Type Definition/{scope=set}{exclusive}
--regex-elm=/^[[:blank:]]+[|=][[:blank:]]+([[:upper:]][[:alnum:]_]*.*)$/\1/c,constructor,Type Constructor/{scope=ref}{exclusive}
--regex-elm=/^type[[:blank:]]+alias[[:blank:]]+([[:upper:]][[:alnum:]_]*[[:blank:][:alnum:]_]*)/\1/a,alias,Type Alias/{scope=set}{exclusive}
--regex-elm=/^([[:lower:]_][[:alnum:]_]*)[^=]*=$/\1/f,function,Functions/{scope=set}
--regex-elm=/^[[:blank:]]+([[:lower:]_][[:alnum:]_]*)[^=]*=$/\1/f,function,Functions/{scope=ref}
1 change: 1 addition & 0 deletions win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<ClCompile Include="..\parsers\clojure.c" />
<ClCompile Include="..\parsers\cobol.c" />
<ClCompile Include="..\optlib\CoffeeScript.c" />
<ClCompile Include="..\optlib\elm.c" />
<ClCompile Include="..\parsers\css.c" />
<ClCompile Include="..\optlib\ctags-optlib.c" />
<ClCompile Include="..\main\debug.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 @@ -390,6 +390,9 @@
<ClCompile Include="..\optlib\pod.c">
<Filter>Source Files\Main</Filter>
</ClCompile>
<ClCompile Include="..\optlib\elm.c">
<Filter>Source Files\Main</Filter>
</ClCompile>
<ClCompile Include="..\parsers\protobuf.c">
<Filter>Source Files\Main</Filter>
</ClCompile>
Expand Down