|
| 1 | +; Reserved keywords |
| 2 | + |
| 3 | +["when" "and" "or" "not" "in" "fn" "do" "end" "catch" "rescue" "after" "else"] @keyword |
| 4 | + |
| 5 | +; Operators |
| 6 | + |
| 7 | +; * doc string |
| 8 | +(unary_operator |
| 9 | + operator: "@" @comment.doc |
| 10 | + operand: (call |
| 11 | + target: (identifier) @comment.doc.__attribute__ |
| 12 | + (arguments |
| 13 | + [ |
| 14 | + (string) @comment.doc |
| 15 | + (charlist) @comment.doc |
| 16 | + (sigil |
| 17 | + quoted_start: _ @comment.doc |
| 18 | + quoted_end: _ @comment.doc) @comment.doc |
| 19 | + (boolean) @comment.doc |
| 20 | + ])) |
| 21 | + (#match? @comment.doc.__attribute__ "^(moduledoc|typedoc|doc)$")) |
| 22 | + |
| 23 | +; * module attribute |
| 24 | +(unary_operator |
| 25 | + operator: "@" @attribute |
| 26 | + operand: [ |
| 27 | + (identifier) @attribute |
| 28 | + (call |
| 29 | + target: (identifier) @attribute) |
| 30 | + (boolean) @attribute |
| 31 | + (nil) @attribute |
| 32 | + ]) |
| 33 | + |
| 34 | +; * capture operand |
| 35 | +(unary_operator |
| 36 | + operator: "&" |
| 37 | + operand: (integer) @operator) |
| 38 | + |
| 39 | +(operator_identifier) @operator |
| 40 | + |
| 41 | +(unary_operator |
| 42 | + operator: _ @operator) |
| 43 | + |
| 44 | +(binary_operator |
| 45 | + operator: _ @operator) |
| 46 | + |
| 47 | +(dot |
| 48 | + operator: _ @operator) |
| 49 | + |
| 50 | +(stab_clause |
| 51 | + operator: _ @operator) |
| 52 | + |
| 53 | +; Literals |
| 54 | + |
| 55 | +[ |
| 56 | + (boolean) |
| 57 | + (nil) |
| 58 | +] @constant |
| 59 | + |
| 60 | +[ |
| 61 | + (integer) |
| 62 | + (float) |
| 63 | +] @number |
| 64 | + |
| 65 | +(alias) @type |
| 66 | + |
| 67 | +(char) @constant |
| 68 | + |
| 69 | +; Quoted content |
| 70 | + |
| 71 | +(interpolation "#{" @punctuation.special "}" @punctuation.special) @embedded |
| 72 | + |
| 73 | +(escape_sequence) @string.escape |
| 74 | + |
| 75 | +[ |
| 76 | + (atom) |
| 77 | + (quoted_atom) |
| 78 | + (keyword) |
| 79 | + (quoted_keyword) |
| 80 | +] @string.special.symbol |
| 81 | + |
| 82 | +[ |
| 83 | + (string) |
| 84 | + (charlist) |
| 85 | +] @string |
| 86 | + |
| 87 | +; Note that we explicitly target sigil quoted start/end, so they are not overridden by delimiters |
| 88 | + |
| 89 | +(sigil |
| 90 | + (sigil_name) @__name__ |
| 91 | + quoted_start: _ @string |
| 92 | + quoted_end: _ @string |
| 93 | + (#match? @__name__ "^[sS]$")) @string |
| 94 | + |
| 95 | +(sigil |
| 96 | + (sigil_name) @__name__ |
| 97 | + quoted_start: _ @string.regex |
| 98 | + quoted_end: _ @string.regex |
| 99 | + (#match? @__name__ "^[rR]$")) @string.regex |
| 100 | + |
| 101 | +(sigil |
| 102 | + (sigil_name) @__name__ |
| 103 | + quoted_start: _ @string.special |
| 104 | + quoted_end: _ @string.special) @string.special |
| 105 | + |
| 106 | +; Calls |
| 107 | + |
| 108 | +; * definition keyword |
| 109 | +(call |
| 110 | + target: (identifier) @keyword |
| 111 | + (#match? @keyword "^(def|defdelegate|defexception|defguard|defguardp|defimpl|defmacro|defmacrop|defmodule|defn|defnp|defoverridable|defp|defprotocol|defstruct)$")) |
| 112 | + |
| 113 | +; * kernel or special forms keyword |
| 114 | +(call |
| 115 | + target: (identifier) @keyword |
| 116 | + (#match? @keyword "^(alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$")) |
| 117 | + |
| 118 | +; * function call |
| 119 | +(call |
| 120 | + target: [ |
| 121 | + ; local |
| 122 | + (identifier) @function |
| 123 | + ; remote |
| 124 | + (dot |
| 125 | + right: (identifier) @function) |
| 126 | + ]) |
| 127 | + |
| 128 | +; * just identifier in function definition |
| 129 | +(call |
| 130 | + target: (identifier) @keyword |
| 131 | + (arguments |
| 132 | + [ |
| 133 | + (identifier) @function |
| 134 | + (binary_operator |
| 135 | + left: (identifier) @function |
| 136 | + operator: "when") |
| 137 | + ]) |
| 138 | + (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) |
| 139 | + |
| 140 | +; * pipe into identifier (definition) |
| 141 | +(call |
| 142 | + target: (identifier) @keyword |
| 143 | + (arguments |
| 144 | + (binary_operator |
| 145 | + operator: "|>" |
| 146 | + right: (identifier) @variable)) |
| 147 | + (#match? @keyword "^(def|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defp)$")) |
| 148 | + |
| 149 | +; * pipe into identifier (function call) |
| 150 | +(binary_operator |
| 151 | + operator: "|>" |
| 152 | + right: (identifier) @function) |
| 153 | + |
| 154 | +; Identifiers |
| 155 | + |
| 156 | +; * special |
| 157 | +( |
| 158 | + (identifier) @constant.builtin |
| 159 | + (#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$") |
| 160 | +) |
| 161 | + |
| 162 | +; * unused |
| 163 | +( |
| 164 | + (identifier) @comment.unused |
| 165 | + (#match? @comment.unused "^_") |
| 166 | +) |
| 167 | + |
| 168 | +; * regular |
| 169 | +(identifier) @variable |
| 170 | + |
| 171 | +; Comment |
| 172 | + |
| 173 | +(comment) @comment |
| 174 | + |
| 175 | +; Punctuation |
| 176 | + |
| 177 | +[ |
| 178 | + "%" |
| 179 | +] @punctuation |
| 180 | + |
| 181 | +[ |
| 182 | + "," |
| 183 | + ";" |
| 184 | +] @punctuation.delimiter |
| 185 | + |
| 186 | +[ |
| 187 | + "(" |
| 188 | + ")" |
| 189 | + "[" |
| 190 | + "]" |
| 191 | + "{" |
| 192 | + "}" |
| 193 | + "<<" |
| 194 | + ">>" |
| 195 | +] @punctuation.bracket |
0 commit comments