#
# 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=p,protocol,protocols (defprotocol...)
--kinddef-Elixir=m,module,modules (defmodule ...)
--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=g,guard,guards (defguard ...)
--kinddef-Elixir=i,implementation,implementations (defimpl ...)
--kinddef-Elixir=a,macro,macros (defmacro ...)
--kinddef-Elixir=o,operator,operators (e.g. "defmacro a <<< b")
--kinddef-Elixir=r,record,records (defrecord...)
--kinddef-Elixir=t,test,tests (test ...)
--kinddef-Elixir=y,type,types (@type ...)

--_fielddef-Elixir=access,access

--fields-Elixir=+{access}

--regex-Elixir=/^[ \t]*defprotocol[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/p/{scope=set}
--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[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\1/f/{scope=ref}{_field=access:public}
--regex-Elixir=/^[ \t]*defp[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\1/f/{scope=ref}{_field=access:private}
--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[ \t]+(is_[a-zA-Z0-9_?!]+)/\1/g/{scope=ref}{_field=access:public}
--regex-Elixir=/^[ \t]*defguardp[ \t]+(is_[a-zA-Z0-9_?!]+)/\1/g/{scope=ref}{_field=access:private}
--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[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\|\^\/&<>~.=!*+-]+)/\1/a/{scope=ref}{_field=access:public}
--regex-Elixir=/^[ \t]*defmacrop[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\|\^\/&<>~.=!*+-]+)/\1/a/{scope=ref}{_field=access:private}
--regex-Elixir=/^[ \t]*Record\.defrecord[ \t(]+:([a-zA-Z0-9_]+)(\)?)/\1/r/{scope=ref}{_field=access:public}
--regex-Elixir=/^[ \t]*Record\.defrecordp[ \t(]+:([a-zA-Z0-9_]+)(\)?)/\1/r/{scope=ref}{_field=access:private}
--regex-Elixir=/^[ \t]*test[ \t(]+"([a-z_][a-zA-Z0-9_?! ]*)"*(\)?)[ \t]*do/\1/t/{scope=ref}
--regex-Elixir=/^[ \t]*@(type|opaque)[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\2/y/{scope=ref}{_field=access:public}
--regex-Elixir=/^[ \t]*@typep[ \t]+([a-z_][a-zA-Z0-9_?!]*)/\1/y/{scope=ref}{_field=access:private}
