[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode a0f3a6f 250/468: Simplify font-lock & imenu regex
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode a0f3a6f 250/468: Simplify font-lock & imenu regexps with lua-rx |
Date: |
Thu, 5 Aug 2021 04:58:47 -0400 (EDT) |
branch: elpa/lua-mode
commit a0f3a6f1ff901c1ea6e601c2d9ba5195b528ce52
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Simplify font-lock & imenu regexps with lua-rx
---
lua-mode.el | 52 ++++++++++++++--------------------------------------
1 file changed, 14 insertions(+), 38 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 369a446..e5c823c 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -177,6 +177,8 @@ element is itself expanded with `lua-rx-to-string'. "
:rx (seq (or (seq (+ digit) (opt ".") (* digit))
(seq (* digit) (opt ".") (+ digit)))
(opt (regexp "[eE][+-]?[0-9]+"))))
+ (lua-assignment-op
+ :rx (seq "=" (or buffer-end (not (any "=")))))
(lua-token
:rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
">" "=" ";" ":" "," "." ".." "..."))
@@ -568,32 +570,17 @@ Groups 6-9 can be used in any of argument regexps."
(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
`(;; highlight the hash-bang line "#!/foo/bar/lua" as comment
("^#!.*$" . font-lock-comment-face)
;; Builtin constants
- (,(rx symbol-start (or "true" "false" "nil") symbol-end)
+ (,(lua-rx (symbol "true" "false" "nil"))
. font-lock-constant-face)
;; Keywords
- (,(rx symbol-start
- (or "and" "break" "do" "else" "elseif" "end"
- "for" "function" "if" "in" "local" "not"
- "or" "repeat" "return" "then" "until"
- "while")
- symbol-end)
+ (,(lua-rx lua-keyword)
. font-lock-keyword-face)
;; Highlight lua builtin functions and variables
@@ -601,8 +588,8 @@ Groups 6-9 can be used in any of argument regexps."
(1 font-lock-builtin-face) (2 font-lock-builtin-face nil noerror))
("^[ \t]*\\_<for\\_>"
- (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
- "\\(?:\\_<in\\_>\\|=\\(?:[^=]\\|$\\)\\)")
+ (,(lua-make-delimited-matcher (lua-rx lua-name) ","
+ (lua-rx (or (symbol "in")
lua-assignment-op)))
nil nil
(1 font-lock-variable-name-face nil noerror)
(2 font-lock-warning-face t noerror)
@@ -619,38 +606,27 @@ Groups 6-9 can be used in any of argument regexps."
("^[ \t]*\\_<local\\_>"
(0 font-lock-keyword-face)
- ((lambda (end)
- (re-search-forward
- (lua-rx point ws lua-funcheader (* nonl)) end t))
+ ;; (* nonl) at the end is to consume trailing characters or otherwise they
+ ;; delimited matcher would attempt to parse them afterwards and wrongly
+ ;; highlight parentheses as incorrect variable name characters.
+ (,(lua-rx point ws lua-funcheader (* nonl))
nil nil
(1 font-lock-function-name-face nil noerror))
- (,(lua-make-delimited-matcher "\\_<[[:alpha:]_][[:alnum:]_]*\\_>" ","
- "=\\(?:[^=]\\|$\\)")
+ (,(lua-make-delimited-matcher (lua-rx lua-name) ","
+ (lua-rx lua-assignment-op))
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\\_>"
+ (,(lua-rx (or bol ";") ws lua-funcheader)
(1 font-lock-function-name-face)))
"Default expressions to highlight in Lua mode.")
(defvar lua-imenu-generic-expression
- ;; This regexp matches expressions which look like function
- ;; definitions, but are not necessarily allowed by Lua syntax. This
- ;; is done on purpose to avoid frustration when making a small error
- ;; might cause a function get hidden from imenu index. --immerrr
- '((nil "^[ \t]*\\(?:local[ \t]+\\)?function[ \t]+\\([[:alnum:]_:.]+\\)" 1)
- (nil "^[ \t]*\\(?:local[ \t]+\\)?\\(\\_<[[:alnum:]_:.]+\\_>\\)[ \t]*=\[
\t]*\\_<function\\_>" 1))
+ `((nil ,(lua-rx (or bol ";") ws lua-funcheader) 1))
"Imenu generic expression for lua-mode. See `imenu-generic-expression'.")
(defvar lua-sexp-alist '(("then" . "end")
- [nongnu] elpa/lua-mode 2d94dee 204/468: Don't unindent comment close-bracket if it doesn't match open-bracket, (continued)
- [nongnu] elpa/lua-mode 2d94dee 204/468: Don't unindent comment close-bracket if it doesn't match open-bracket, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c1fcfb6 211/468: Add NEWS file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d0fa50d 217/468: lua-make-delimited-matcher: wrap into eval-and-compile, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b684790 219/468: Revert "Rename lua--function-name-rx, use it in font-lock keywords init", Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8e19d23 231/468: Add basic indentation tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6729533 234/468: Rewrite lua-send-buffer function (should fix issue #60), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode afc1ea0 235/468: Send init-code in lua-start-process, enable compilation-shell-minor-mode, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1ede907 242/468: Fix several cases for `indent-new-comment-line' (M-j), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6c55abb 245/468: Add lua-rx/-to-string wrappers to simplify writing Lua-specific regexps, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1452f8e 244/468: should-lua-indent: accept strings rather than lists to simplify writing tests, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a0f3a6f 250/468: Simplify font-lock & imenu regexps with lua-rx,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode e430d01 252/468: Remove deprecated test code from test/, put current code there instead, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1d21a10 259/468: Reorganize test structure, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dc55356 261/468: lua-forward-regexp: make sure direction is `forward', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0a986f7 266/468: Add hideshow support for "repeat... until" blocks, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8d27d2c 268/468: fixed up tests && improved lua-kill-process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 82daeb5 297/468: Merge pull request #88 from tarsius/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7b2c18c 305/468: Merge pull request #99 from tarsius/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6f4035a 315/468: Merge pull request #108 from ptrv/patch-1, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f2915c3 324/468: Add string tab escape test, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 652e299 339/468: gitignore: add cask working dir, Philip Kaludercic, 2021/08/05