Skip to content

Commit f55f9c8

Browse files
committed
Merge pull request #85 from elixir-lang/defmodule-highlight
Improve regex for defmodule highlighting.
2 parents 035d4a9 + a4b983c commit f55f9c8

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

elixir-mode.el

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,27 @@
278278
(or "+" "++" "<>" "-" "/" "*" "div" "rem" "==" "!=" "<="
279279
"<" ">=" ">" "===" "!==" "and" "or" "not" "&&" "||"
280280
"!" "." "#" "=" ":=" "<-")))
281-
(resource-name . ,(rx symbol-start
282-
(zero-or-more (any "A-Z")
283-
(zero-or-more
284-
(any "a-z"))
285-
"."
286-
(any "A-Z")
287-
(zero-or-more
288-
(any "a-z")))
289-
symbol-end))
281+
;; Module and submodule names start with upper case letter or `_'. This
282+
;; can then be followed by any combination of alphanumeric chars + `_'.
283+
;; In turn, this can be followed by a `.' which begins the notation of
284+
;; a submodule, which follows the same naming pattern of the module.
285+
;; Finally, like other identifiers, it can be terminated with either `?'
286+
;; or `!'.
287+
(module-names . ,(rx symbol-start
288+
(one-or-more (any "A-Z" "_"))
289+
(zero-or-more (any "A-Z" "a-z" "_" "0-9"))
290+
(zero-or-more
291+
(and "."
292+
(one-or-more (any "A-Z" "_"))
293+
(zero-or-more (any "A-Z" "a-z" "_" "0-9"))))
294+
(optional (or "!" "?"))
295+
symbol-end))
296+
;; The first character of an identifier must be a letter or an underscore.
297+
;; After that, they may contain any alphanumeric character + underscore.
298+
;; Additionally, the final character may be either `?' or `!'.
290299
(identifiers . ,(rx symbol-start
291300
(one-or-more (any "A-Z" "a-z""_"))
292-
(zero-or-more (any "0-9" "_"))
301+
(zero-or-more (any "A-Z" "a-z" "0-9" "_"))
293302
(optional (or "?" "!"))
294303
symbol-end))
295304
(atoms . ,(rx ":"
@@ -310,10 +319,10 @@
310319

311320
(defconst elixir-mode-font-lock-defaults
312321
`(
313-
;; Import, module- and method-defining keywords
314-
(,(elixir-rx (or method-defines module-defines imports)
322+
;; Module-defining & namespace builtins
323+
(,(elixir-rx (or module-defines imports)
315324
space
316-
(group resource-name))
325+
(group module-names))
317326
1 font-lock-type-face)
318327

319328
;; Keywords

0 commit comments

Comments
 (0)