[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode d0fa50d 217/468: lua-make-delimited-matcher: wrap
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode d0fa50d 217/468: lua-make-delimited-matcher: wrap into eval-and-compile |
Date: |
Thu, 5 Aug 2021 04:58:39 -0400 (EDT) |
branch: elpa/lua-mode
commit d0fa50d0621ab3d94390b5838dba2212c4e2637e
Author: immerrr <immerrr@gmail.com>
Commit: immerrr <immerrr@gmail.com>
lua-make-delimited-matcher: wrap into eval-and-compile
---
lua-mode.el | 125 ++++++++++++++++++++++++++++++------------------------------
1 file changed, 63 insertions(+), 62 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 7b1db51..08862ec 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -412,8 +412,9 @@ traceback location."
This is a compilation of 5.1 and 5.2 builtins taken from the
index of respective Lua reference manuals.")
-(defun lua-make-delimited-matcher (elt-regexp sep-regexp end-regexp)
- "Construct matcher function for `font-lock-keywords' to match a sequence.
+(eval-and-compile
+ (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:
@@ -431,66 +432,66 @@ 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))))))))
+ (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)))))))))
(eval-and-compile
(defconst lua--function-name-rx
- [nongnu] elpa/lua-mode a9945c9 340/468: possibility to connect to remote lua process, (continued)
- [nongnu] elpa/lua-mode a9945c9 340/468: possibility to connect to remote lua process, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0407042 153/468: Make lua-with-silent-modifications available during byte-compilation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b1dc70c 158/468: lua-font-lock-keywords: highlight builtin symbols (issue #15), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 52dcf7b 167/468: Merge pull request #35 from vhallac/fix-34, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a3016a2 176/468: Avoid polluting "global namespace" when striving for backward compatibility, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode b124dd0 194/468: Add field containing commit SHA expanded during archive creation., Philip Kaludercic, 2021/08/05
- [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 <=
- [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, 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