[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 6c55abb 245/468: Add lua-rx/-to-string wrappers t
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 6c55abb 245/468: Add lua-rx/-to-string wrappers to simplify writing Lua-specific regexps |
Date: |
Thu, 5 Aug 2021 04:58:46 -0400 (EDT) |
branch: elpa/lua-mode
commit 6c55abbf35927e0d3b71c7e58dd5c377f8226a85
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Add lua-rx/-to-string wrappers to simplify writing Lua-specific regexps
---
lua-mode.el | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/lua-mode.el b/lua-mode.el
index fc7e52a..a1c008a 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -107,6 +107,83 @@
(require 'comint)
(require 'newcomment)
+(require 'rx)
+
+
+;; rx-wrappers for Lua
+
+(eval-and-compile
+ (defvar lua-rx-constituents)
+
+ (defun lua-rx-to-string (form &optional no-group)
+ "Lua-specific replacement for `rx-to-string'.
+
+See `rx-to-string' documentation for more information FORM and
+NO-GROUP arguments."
+ (let ((rx-constituents lua-rx-constituents))
+ (rx-to-string form no-group)))
+
+ (defmacro lua-rx (&rest regexps)
+ "Lua-specific replacement for `rx'.
+
+See `rx' documentation for more information about REGEXPS param."
+ (cond ((null regexps)
+ (error "No regexp"))
+ ((cdr regexps)
+ (lua-rx-to-string `(and ,@regexps) t))
+ (t
+ (lua-rx-to-string (car regexps) t))))
+
+ (defun lua--new-rx-form (form)
+ "Add FORM definition to `lua-rx' macro.
+
+FORM is a cons (NAME . DEFN), see more in `rx-constituents' doc.
+This function enables specifying new definitions using old ones:
+if DEFN is a list that starts with `:rx' symbol its second
+element is itself expanded with `lua-rx-to-string'. "
+ (let ((name (car form))
+ (form-definition (cdr form)))
+ (when (and (listp form-definition) (eq ':rx (car form-definition)))
+ (setcdr form (lua-rx-to-string (cadr form-definition) t)))
+ (push form lua-rx-constituents)))
+
+ (defun lua--rx-symbol (form)
+ (rx-form `(seq symbol-start (or ,@(cdr form))
+ symbol-end)))
+
+ (setq lua-rx-constituents (copy-sequence rx-constituents))
+
+ ;; group-n is not available in Emacs23, provide a fallback.
+ (unless (assq 'group-n rx-constituents)
+ (defun lua--rx-group-n (form)
+ (concat (format "\\(?%d:" (nth 1 form))
+ (rx-form `(seq ,@(nthcdr 2 form)) ':)
+ "\\)"))
+ (push '(group-n lua--rx-group-n 1 nil) lua-rx-constituents))
+
+ (mapc #'lua--new-rx-form
+ `((symbol lua--rx-symbol 1 nil)
+ (ws . "[ \t]*") (ws+ . "[ \t]+")
+ (lua-name :rx (symbol (regexp "[[:alpha:]_]+[[:alnum:]_]*")))
+ (lua-funcname
+ :rx (seq lua-name (* ws "." ws lua-name)
+ (opt ws ":" ws lua-name)))
+ (lua-funcheader
+ :rx (or (seq (symbol "function") ws (group-n 1 lua-funcname))
+ (seq (group-n 1 lua-funcname) ws "=" ws (symbol
"function"))))
+ (lua-number
+ :rx (seq (or (seq (+ digit) (opt ".") (* digit))
+ (seq (* digit) (opt ".") (+ digit)))
+ (opt (regexp "[eE][+-]?[0-9]+"))))
+ (lua-token
+ :rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
+ ">" "=" ";" ":" "," "." ".." "..."))
+ (lua-keyword
+ :rx (symbol "and" "break" "do" "else" "elseif" "end" "for"
"function"
+ "if" "in" "local" "not" "or" "repeat" "return" "then"
+ "until" "while")))
+ ))
+
(eval-and-compile
;; Backward compatibility for Emacsen < 24.1
- [nongnu] elpa/lua-mode 64c1e94 197/468: lua--builtins: add "self" as keyword, (continued)
- [nongnu] elpa/lua-mode 64c1e94 197/468: lua--builtins: add "self" as keyword, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d6c8419 202/468: Fix incorrect error highlighting in 'for x = ...' statements, Philip Kaludercic, 2021/08/05
- [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 <=
- [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, 2021/08/05
- [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