aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjohn muhl2025-03-20 17:32:28 -0500
committerPo Lu2025-08-25 09:59:04 +0800
commit426167a8f307e3fb47fa97d333c08d76dec8f014 (patch)
treefeecbd0c76fb86a957bd761a20249180485a9a25
parent2e454bea03ed7186141e9e1d9b3eb4e888699149 (diff)
downloademacs-426167a8f307e3fb47fa97d333c08d76dec8f014.tar.gz
emacs-426167a8f307e3fb47fa97d333c08d76dec8f014.zip
Replace big regexps w/ rx expressions in 'lua-mode'
* lisp/progmodes/lua-mode.el (lua-block-regexp) (lua-indentation-modifier-regexp, lua-cont-eol-regexp) (lua-cont-bol-regexp): Use rx.
-rw-r--r--lisp/progmodes/lua-mode.el79
1 files changed, 38 insertions, 41 deletions
diff --git a/lisp/progmodes/lua-mode.el b/lisp/progmodes/lua-mode.el
index dcb8a27da64..bc1217be82d 100644
--- a/lisp/progmodes/lua-mode.el
+++ b/lisp/progmodes/lua-mode.el
@@ -838,12 +838,11 @@ found, returns point position, nil otherwise."
838 838
839(defconst lua-block-regexp 839(defconst lua-block-regexp
840 (eval-when-compile 840 (eval-when-compile
841 (concat 841 (rx (or (group symbol-start
842 "\\(\\_<" 842 (group (or "do" "function" "repeat" "then"
843 (regexp-opt '("do" "function" "repeat" "then" 843 "else" "elseif" "end" "until"))
844 "else" "elseif" "end" "until") t) 844 symbol-end)
845 "\\_>\\)\\|" 845 (group (any "()[]{}"))))))
846 (regexp-opt '("{" "(" "[" "]" ")" "}") t))))
847 846
848(defconst lua-block-token-alist 847(defconst lua-block-token-alist
849 '(("do" "\\_<end\\_>" "\\_<for\\|while\\_>" middle-or-open) 848 '(("do" "\\_<end\\_>" "\\_<for\\|while\\_>" middle-or-open)
@@ -875,17 +874,15 @@ TOKEN-TYPE determines where the token occurs on a statement. open indicates that
875 ;; The absence of else is deliberate, since it does not modify the 874 ;; The absence of else is deliberate, since it does not modify the
876 ;; indentation level per se. It only may cause the line, in which the 875 ;; indentation level per se. It only may cause the line, in which the
877 ;; else is, to be shifted to the left. 876 ;; else is, to be shifted to the left.
878 (concat 877 (rx (or (group (or (seq symbol-start
879 "\\(\\_<" 878 (group (or "do" "function" "repeat" "then" "if"
880 (regexp-opt '("do" "function" "repeat" "then" "if" "else" "elseif" "for" "while") t) 879 "else" "elseif" "for" "while"))
881 "\\_>\\|" 880 symbol-end)
882 (regexp-opt '("{" "(" "[")) 881 (any "([{")))
883 "\\)\\|\\(\\_<" 882 (group (or (seq symbol-start
884 (regexp-opt '("end" "until") t) 883 (group (or "end" "until"))
885 "\\_>\\|" 884 symbol-end)
886 (regexp-opt '("]" ")" "}")) 885 (any ")]}"))))))
887 "\\)")
888 )
889 886
890(defun lua-get-block-token-info (token) 887(defun lua-get-block-token-info (token)
891 "Returns the block token info entry for TOKEN from lua-block-token-alist" 888 "Returns the block token info entry for TOKEN from lua-block-token-alist"
@@ -1076,19 +1073,19 @@ Returns final value of point as integer or nil if operation failed."
1076 1073
1077(defconst lua-cont-eol-regexp 1074(defconst lua-cont-eol-regexp
1078 (eval-when-compile 1075 (eval-when-compile
1079 (concat 1076 (rx-to-string
1080 "\\(?:\\(?1:\\_<" 1077 `(seq (or (group-n 1
1081 (regexp-opt '("and" "or" "not" "in" "for" "while" 1078 symbol-start
1082 "local" "function" "if" "until" "elseif" "return") 1079 (group (or "and" "or" "not" "in" "for" "while" "local"
1083 t) 1080 "function" "if" "until" "elseif" "return"))
1084 "\\_>\\)\\|" 1081 symbol-end)
1085 "\\(?:^\\|[^" lua-operator-class "]\\)\\(?2:" 1082 (seq (or bol (not (any ,lua-operator-class)))
1086 (regexp-opt '("+" "-" "*" "/" "%" "^" ".." "==" 1083 (group-n 2
1087 "=" "<" ">" "<=" ">=" "~=" "." ":" 1084 (group (or "%" "&" "*" "+" "," "-" "." ".." "/" ":"
1088 "&" "|" "~" ">>" "<<" "~" ",") 1085 "<" "<<" "<=" "=" "==" ">" ">=" ">>" "^"
1089 t) 1086 "|" "~" "~=")))))
1090 "\\)\\)" 1087 (zero-or-more (syntax whitespace))
1091 "\\s *\\=")) 1088 point)))
1092 "Regexp that matches the ending of a line that needs continuation. 1089 "Regexp that matches the ending of a line that needs continuation.
1093 1090
1094This regexp starts from eol and looks for a binary operator or an unclosed 1091This regexp starts from eol and looks for a binary operator or an unclosed
@@ -1097,17 +1094,17 @@ an optional whitespace till the end of the line.")
1097 1094
1098(defconst lua-cont-bol-regexp 1095(defconst lua-cont-bol-regexp
1099 (eval-when-compile 1096 (eval-when-compile
1100 (concat 1097 (rx-to-string
1101 "\\=\\s *" 1098 `(seq point (zero-or-more (syntax whitespace))
1102 "\\(?:\\(?1:\\_<" 1099 (or (group-n 1
1103 (regexp-opt '("and" "or" "not" "in") t) 1100 symbol-start
1104 "\\_>\\)\\|\\(?2:" 1101 (group (or "and" "in" "not" "or"))
1105 (regexp-opt '("," "+" "-" "*" "/" "%" "^" ".." "==" 1102 symbol-end)
1106 "=" "<" ">" "<=" ">=" "~=" "." ":" 1103 (seq (group-n 2
1107 "&" "|" "~" ">>" "<<" "~") 1104 (group (or "%" "&" "*" "+" "," "-" "." ".." "/" ":"
1108 t) 1105 "<" "<<" "<=" "=" "==" ">" ">=" ">>" "^"
1109 "\\)\\(?:$\\|[^" lua-operator-class "]\\)" 1106 "|" "~" "~=")))
1110 "\\)")) 1107 (or eol (not (any ,lua-operator-class))))))))
1111 "Regexp that matches a line that continues previous one. 1108 "Regexp that matches a line that continues previous one.
1112 1109
1113This regexp means, starting from point there is an optional whitespace followed 1110This regexp means, starting from point there is an optional whitespace followed