[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode ff3f5e1 199/468: lua-font-lock-keywords: don't ev
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode ff3f5e1 199/468: lua-font-lock-keywords: don't eval-when-compile initial value |
Date: |
Thu, 5 Aug 2021 04:58:36 -0400 (EDT) |
branch: elpa/lua-mode
commit ff3f5e1a8c73f90433f151a039e3f34f4a56992d
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
lua-font-lock-keywords: don't eval-when-compile initial value
It seems to cause issues with lexical-let & byte-compilation.
---
lua-mode.el | 289 ++++++++++++++++++++++++++++++------------------------------
1 file changed, 143 insertions(+), 146 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 328005c..df3c6d1 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -414,9 +414,8 @@ traceback location."
This is a compilation of 5.1 and 5.2 builtins taken from the
index of respective Lua reference manuals.")
-(eval-when-compile
- (defun lua-make-delimited-matcher (elt-regexp sep-regexp end-regexp)
- "Construct matcher function for `font-lock-keywords' to match a sequence.
+(defun lua-make-delimited-matcher (elt-regexp sep-regexp end-regexp)
+ "Construct matcher function for `font-lock-keywords' to match a sequence.
It's supposed to match sequences with following EBNF:
@@ -434,151 +433,149 @@ groups set according to next matched token:
Blanks & comments between tokens are silently skipped.
Groups 6-9 can be used in any of argument regexps."
- (lexical-let*
- ((delimited-matcher-re-template
-
"\\=\\(?2:.*?\\)\\(?:\\(?%s:\\(?4:%s\\)\\|\\(?5:%s\\)\\)\\|\\(?%s:\\(?1:%s\\)\\)\\)")
- ;; There's some magic to this regexp. It works as follows:
- ;;
- ;; A. start at (point)
- ;; B. non-greedy match of garbage-characters (?2:)
- ;; C. try matching separator (?4:) or end-token (?5:)
- ;; D. try matching element (?1:)
- ;;
- ;; Simple, but there's a trick: pt.C and pt.D are embraced by one more
- ;; group whose purpose is determined only after the template is
- ;; formatted (?%s:):
- ;;
- ;; - if element is expected, then D's parent group becomes "shy" and
C's
- ;; parent becomes group 3 (aka misplaced token), so if D matches
when
- ;; an element is expected, it'll be marked with warning face.
- ;;
- ;; - if separator-or-end-token is expected, then it's the opposite:
- ;; C's parent becomes shy and D's will be matched as misplaced
token.
- (elt-expected-re (format delimited-matcher-re-template
- 3 sep-regexp end-regexp "" elt-regexp))
- (sep-or-end-expected-re (format delimited-matcher-re-template
- "" sep-regexp end-regexp 3
elt-regexp)))
-
- (lambda (end)
- (let* ((prev-elt-p (match-beginning 1))
- (prev-sep-p (match-beginning 4))
- (prev-end-p (match-beginning 5))
-
- (regexp (if prev-elt-p sep-or-end-expected-re elt-expected-re))
- (comment-start (lua-comment-start-pos (syntax-ppss)))
- (parse-stop end))
-
- ;; If token starts inside comment, or end-token was encountered,
stop.
- (when (and (not comment-start)
- (not prev-end-p))
- ;; Skip all comments & whitespace. forward-comment doesn't have
boundary
- ;; argument, so make sure point isn't beyond parse-stop afterwards.
- (while (and (< (point) end)
- (forward-comment 1)))
- (goto-char (min (point) parse-stop))
-
- ;; Reuse comment-start variable to store beginning of comment that
is
- ;; placed before line-end-position so as to make sure token search
doesn't
- ;; enter that comment.
- (setq comment-start
- (lua-comment-start-pos
- (save-excursion
- (parse-partial-sexp (point) parse-stop
- nil nil nil 'stop-inside-comment)))
- parse-stop (or comment-start parse-stop))
-
- ;; Now, let's match stuff. If regular matcher fails, declare a
span of
- ;; non-blanks 'garbage', and the next iteration will start from
where the
- ;; garbage ends. If couldn't match any garbage, move point to the
end
- ;; and return nil.
- (or (re-search-forward regexp parse-stop t)
- (re-search-forward "\\(?1:\\(?2:[^ \t]+\\)\\)" parse-stop
'skip)
- (prog1 nil (goto-char end))))))))
-
- (defconst lua-local-defun-regexp
- ;; Function matchers are very crude, need rewrite at some point.
- (rx (or (seq (regexp "\\(?:\\_<function\\_>\\)")
- (* blank)
- (? (regexp "\\(?1:\\_<[[:alpha:]][[:alnum:]]*\\_>\\)"))
- (regexp "\\(?2:.*\\)"))
- (seq (? (regexp "\\(?1:\\_<[[:alpha:]][[:alnum:]]*\\_>\\)"))
- (* blank) "=" (* blank)
- (regexp "\\(?:\\_<function\\_>\\)")
- (regexp "\\(?2:.*\\)"))))))
+ (lexical-let*
+ ((delimited-matcher-re-template
+
"\\=\\(?2:.*?\\)\\(?:\\(?%s:\\(?4:%s\\)\\|\\(?5:%s\\)\\)\\|\\(?%s:\\(?1:%s\\)\\)\\)")
+ ;; There's some magic to this regexp. It works as follows:
+ ;;
+ ;; A. start at (point)
+ ;; B. non-greedy match of garbage-characters (?2:)
+ ;; C. try matching separator (?4:) or end-token (?5:)
+ ;; D. try matching element (?1:)
+ ;;
+ ;; Simple, but there's a trick: pt.C and pt.D are embraced by one more
+ ;; group whose purpose is determined only after the template is
+ ;; formatted (?%s:):
+ ;;
+ ;; - if element is expected, then D's parent group becomes "shy" and C's
+ ;; parent becomes group 3 (aka misplaced token), so if D matches when
+ ;; an element is expected, it'll be marked with warning face.
+ ;;
+ ;; - if separator-or-end-token is expected, then it's the opposite:
+ ;; C's parent becomes shy and D's will be matched as misplaced token.
+ (elt-expected-re (format delimited-matcher-re-template
+ 3 sep-regexp end-regexp "" elt-regexp))
+ (sep-or-end-expected-re (format delimited-matcher-re-template
+ "" sep-regexp end-regexp 3 elt-regexp)))
+
+ (lambda (end)
+ (let* ((prev-elt-p (match-beginning 1))
+ (prev-sep-p (match-beginning 4))
+ (prev-end-p (match-beginning 5))
+
+ (regexp (if prev-elt-p sep-or-end-expected-re elt-expected-re))
+ (comment-start (lua-comment-start-pos (syntax-ppss)))
+ (parse-stop end))
+
+ ;; If token starts inside comment, or end-token was encountered, stop.
+ (when (and (not comment-start)
+ (not prev-end-p))
+ ;; Skip all comments & whitespace. forward-comment doesn't have
boundary
+ ;; argument, so make sure point isn't beyond parse-stop afterwards.
+ (while (and (< (point) end)
+ (forward-comment 1)))
+ (goto-char (min (point) parse-stop))
+
+ ;; Reuse comment-start variable to store beginning of comment that is
+ ;; placed before line-end-position so as to make sure token search
doesn't
+ ;; enter that comment.
+ (setq comment-start
+ (lua-comment-start-pos
+ (save-excursion
+ (parse-partial-sexp (point) parse-stop
+ nil nil nil 'stop-inside-comment)))
+ parse-stop (or comment-start parse-stop))
+
+ ;; Now, let's match stuff. If regular matcher fails, declare a span
of
+ ;; non-blanks 'garbage', and the next iteration will start from
where the
+ ;; garbage ends. If couldn't match any garbage, move point to the
end
+ ;; and return nil.
+ (or (re-search-forward regexp parse-stop t)
+ (re-search-forward "\\(?1:\\(?2:[^ \t]+\\)\\)" parse-stop 'skip)
+ (prog1 nil (goto-char end))))))))
+
+(defconst lua-local-defun-regexp
+ ;; Function matchers are very crude, need rewrite at some point.
+ (rx (or (seq (regexp "\\(?:\\_<function\\_>\\)")
+ (* blank)
+ (? (regexp "\\(?1:\\_<[[:alpha:]][[:alnum:]]*\\_>\\)"))
+ (regexp "\\(?2:.*\\)"))
+ (seq (? (regexp "\\(?1:\\_<[[:alpha:]][[:alnum:]]*\\_>\\)"))
+ (* blank) "=" (* blank)
+ (regexp "\\(?:\\_<function\\_>\\)")
+ (regexp "\\(?2:.*\\)")))))
(defvar lua-font-lock-keywords
- (eval-when-compile
- (list
- ;; highlight the hash-bang line "#!/foo/bar/lua" as comment
- '("^#!.*$" . font-lock-comment-face)
-
- ;; Keywords.
- `(,(rx symbol-start
- (or "and" "break" "do" "else" "elseif" "end" "false"
- "for" "function" "if" "in" "local" "nil" "not"
- "or" "repeat" "return" "then" "true" "until"
- "while")
- symbol-end)
- . font-lock-keyword-face)
-
- ;; Highlight lua builtin functions and variables
- `(,lua--builtins
- (1 font-lock-builtin-face) (2 font-lock-builtin-face nil noerror))
-
- ;; hexadecimal numbers
- '("\\_<0x[[:xdigit:]]+\\_>" . font-lock-constant-face)
-
- ;; regular numbers
- ;;
- ;; This regexp relies on '.' being symbol constituent. Whenever this
- ;; changes, the regexp needs revisiting --immerrr
- `(, (rx symbol-start
- ;; make a digit on either side of dot mandatory
- (or (seq (+ num) (? ".") (* num))
- (seq (* num) (? ".") (+ num)))
- (? (regexp "[eE][+-]?") (+ num))
- symbol-end)
- . font-lock-constant-face)
-
- `("^[ \t]*\\_<for\\_>"
- (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
"\\_<in\\_>")
- nil nil
- (1 font-lock-variable-name-face nil noerror)
- (2 font-lock-warning-face t noerror)
- (3 font-lock-warning-face t noerror)))
-
- ;; Handle local variable/function names
- ;; local blalba, xyzzy =
- ;; ^^^^^^ ^^^^^
- ;;
- ;; local function foobar(x,y,z)
- ;; ^^^^^^
- ;; local foobar = function(x,y,z)
- ;; ^^^^^^
- `("^[ \t]*\\_<local\\_>"
- (0 font-lock-keyword-face)
-
- ((lambda (end)
- (re-search-forward
- (rx point (* blank) (regexp ,lua-local-defun-regexp)) end t))
- nil nil
- (1 font-lock-function-name-face nil noerror))
-
- (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
"=\\(?:[^=]\\)")
- nil nil
- (1 font-lock-variable-name-face nil noerror)
- (2 font-lock-warning-face t noerror)
- (3 font-lock-warning-face t noerror)))
-
- ;; Function matchers are very crude, need rewrite at some point.
- ;; Function name declarations.
- '("^[ \t]*\\_<function\\_>[
\t]+\\([[:alnum:]_]+\\(?:\\.[[:alnum:]_]+\\)*\\(?::[[:alnum:]_]+\\)?\\)"
- (1 font-lock-function-name-face))
-
- ;; Function matchers are very crude, need rewrite at some point.
- ;; Handle function names in assignments
- '("^[
\t]*\\([[:alnum:]_]+\\(?:\\.[[:alnum:]_]+\\)*\\(?::[[:alnum:]_]+\\)?\\)[ \t]*=[
\t]*\\_<function\\_>"
- (1 font-lock-function-name-face))))
+ `(;; highlight the hash-bang line "#!/foo/bar/lua" as comment
+ ("^#!.*$" . font-lock-comment-face)
+
+ ;; Keywords.
+ (,(rx symbol-start
+ (or "and" "break" "do" "else" "elseif" "end" "false"
+ "for" "function" "if" "in" "local" "nil" "not"
+ "or" "repeat" "return" "then" "true" "until"
+ "while")
+ symbol-end)
+ . font-lock-keyword-face)
+
+ ;; Highlight lua builtin functions and variables
+ (,lua--builtins
+ (1 font-lock-builtin-face) (2 font-lock-builtin-face nil noerror))
+
+ ;; hexadecimal numbers
+ ("\\_<0x[[:xdigit:]]+\\_>" . font-lock-constant-face)
+
+ ;; regular numbers
+ ;;
+ ;; This regexp relies on '.' being symbol constituent. Whenever this
+ ;; changes, the regexp needs revisiting --immerrr
+ (, (rx symbol-start
+ ;; make a digit on either side of dot mandatory
+ (or (seq (+ num) (? ".") (* num))
+ (seq (* num) (? ".") (+ num)))
+ (? (regexp "[eE][+-]?") (+ num))
+ symbol-end)
+ . font-lock-constant-face)
+
+ ("^[ \t]*\\_<for\\_>"
+ (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
"\\_<in\\_>")
+ nil nil
+ (1 font-lock-variable-name-face nil noerror)
+ (2 font-lock-warning-face t noerror)
+ (3 font-lock-warning-face t noerror)))
+
+ ;; Handle local variable/function names
+ ;; local blalba, xyzzy =
+ ;; ^^^^^^ ^^^^^
+ ;;
+ ;; local function foobar(x,y,z)
+ ;; ^^^^^^
+ ;; local foobar = function(x,y,z)
+ ;; ^^^^^^
+ ("^[ \t]*\\_<local\\_>"
+ (0 font-lock-keyword-face)
+
+ ((lambda (end)
+ (re-search-forward
+ (rx point (* blank) (regexp ,lua-local-defun-regexp)) end t))
+ nil nil
+ (1 font-lock-function-name-face nil noerror))
+
+ (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
"=\\(?:[^=]\\)")
+ nil nil
+ (1 font-lock-variable-name-face nil noerror)
+ (2 font-lock-warning-face t noerror)
+ (3 font-lock-warning-face t noerror)))
+
+ ;; Function matchers are very crude, need rewrite at some point.
+ ;; Function name declarations.
+ ("^[ \t]*\\_<function\\_>[
\t]+\\([[:alnum:]_]+\\(?:\\.[[:alnum:]_]+\\)*\\(?::[[:alnum:]_]+\\)?\\)"
+ (1 font-lock-function-name-face))
+
+ ;; Function matchers are very crude, need rewrite at some point.
+ ;; Handle function names in assignments
+ ("^[
\t]*\\([[:alnum:]_]+\\(?:\\.[[:alnum:]_]+\\)*\\(?::[[:alnum:]_]+\\)?\\)[ \t]*=[
\t]*\\_<function\\_>"
+ (1 font-lock-function-name-face)))
"Default expressions to highlight in Lua mode.")
- [nongnu] elpa/lua-mode eab8fc0 136/468: Move docstrings to the end of constants., (continued)
- [nongnu] elpa/lua-mode eab8fc0 136/468: Move docstrings to the end of constants., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a5cc71f 149/468: Bump version & URL, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode caa3d0c 162/468: lua-jump-to-traceback: fix compilation warning about goto-line func, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode fb53190 164/468: First part of the fix for #34, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 086736c 168/468: #36 Don't continue lines on some keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b9541ce 173/468: lua-send-proc is now an alias to lua-send-defun, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8d28342 187/468: Revisit block-close unindentation logic (issue #26), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b1ac542 191/468: Major refactoring of font-lock-keywords:, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 57c696c 192/468: Add var name highlighting in "for x, y in ..." construct, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 97ce427 198/468: Restore compatibility with Emacs23 broken by commit 8d28342, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ff3f5e1 199/468: lua-font-lock-keywords: don't eval-when-compile initial value,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 2a0314b 200/468: Improve multiline highlighting via font-lock-syntactic-keywords, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cd5c071 201/468: Clean up lua-mode start-up function a bit, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b195cdc 205/468: Bump TODO, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cee511c 206/468: for/local varname highlighting: match '=' at EOL properly, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a1dc850 207/468: Post-refactoring fix: evaluate string variables in font-lock-defaults value, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8ffd075 208/468: lua-calculate-indentation-info: non-functional refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4484128 215/468: lua-calculate-indentation-override: unindent to the last block-close token, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 79e6815 216/468: Rewrite lua-beginning-of-proc, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f2e7138 220/468: Move font-lock test helpers into a separate file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 94aadfd 221/468: Font-lock "nil", "true" and "false" as constants rather than keywords, Philip Kaludercic, 2021/08/05