Skip to content

Commit 2a98125

Browse files
committed
Add regexes to parse operators
from https://hexdocs.pm/elixir/operators.html: > Elixir is capable of parsing a predefined set of operators; this means > that it's not possible to define new operators (like one could do in > Haskell, for example). However, not all operators that Elixir can > parse are *used* by Elixir: for example, `+` and `||` are used by > Elixir for addition and boolean *or*, but `<~>` is not used (but > valid). The following is a list of all the operators that Elixir is capable of parsing, but that are not used by default (separated by a comma): |, |||, &&&, <<<, >>>, <<~, ~>>, <~, ~>, <~>, <|>, ^^^, ~~~ They could be expressed in a regex atom `(&&&|<~|<~>|etc...)` but I think it can be reduced (I don't know the difference in efficiency) to: `[\|\^&<>~]{1,3}` Adding to that bracket expression the rest of the characters and words used for the defined operators (which can be overriden): `([\|\^\/&<>~.=!*+-]{1,3}|and|or|not|in|not in)` But since the regex engine used in exhuberant-ctags can't do lookahead, I'm not gonna bother to try and make the operator regex exhaustive... plus it's also bad practice to override the default operators.
1 parent 2ef7201 commit 2a98125

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

.ctags

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
--regex-Elixir=/^[ \t]*defguard(p?)[ \t]+(is_[a-zA-Z0-9_?!]+)/\2/g,guard,guards (defguard ...)/
88
--regex-Elixir=/^[ \t]*defimpl[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/i,implementation,implementations (defimpl ...)/
99
--regex-Elixir=/^[ \t]*defmacro(p?)[ \t]+([a-z_][a-zA-Z0-9_?!]*)(.[^\|\^\/&<>~.=!*+-]+)/\2/a,macro,macros (defmacro ...)/
10-
--regex-Elixir=/^[ \t]*defmacro(p?)[ \t]+([a-zA-Z0-9_?!]+)?[ \t]+([^ \tA-Za-z0-9_]+)[ \t]*[a-zA-Z0-9_!?!]/\3/o,operator,operators (e.g. "defmacro a <<< b")/
10+
11+
# These are the operators (which can be defined with def(p) and defmacro(p))
12+
--regex-Elixir=/^[ \t]*def(p?)[ \t]+([a-zA-Z0-9_?!]+)[ \t]+([\|\^\/&<>~.=!*+-]{1,3})[ \t]+[a-zA-Z0-9_!?!]/\3/o,operator,operators (e.g. "def a <<< b")/
13+
--regex-Elixir=/^[ \t]*defmacro(p?)[ \t]+([a-zA-Z0-9_?!]+)[ \t]+([\|\^\/&<>~.=!*+-]{1,3})[ \t]+[a-zA-Z0-9_!?!]/\3/o,operator,operators (e.g. "defmacro a <<< b")/
14+
1115
--regex-Elixir=/^[ \t]*defmodule[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/m,module,modules (defmodule ...)/
1216
--regex-Elixir=/^[ \t]*defprotocol[ \t]+([A-Z][a-zA-Z0-9_]*\.)*([A-Z][a-zA-Z0-9_?!]*)/\2/p,protocol,protocols (defprotocol...)/
1317
--regex-Elixir=/^[ \t]*Record\.defrecord(p?)[ \t(]+:([a-zA-Z0-9_]+)(\)?)/\2/r,record,records (defrecord...)/

0 commit comments

Comments
 (0)