[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 248bea3 233/468: Remove syntax hacks for '.' & '_
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 248bea3 233/468: Remove syntax hacks for '.' & '_' characters |
Date: |
Thu, 5 Aug 2021 04:58:42 -0400 (EDT) |
branch: elpa/lua-mode
commit 248bea3ecb4954aabb2b4b850be7e700a2acdaa4
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Remove syntax hacks for '.' & '_' characters
---
ert-tests/test-builtin-font-lock.el | 36 ++++++++++++++++++++++++----
ert-tests/test-indentation.el | 11 +++++++++
lua-mode.el | 47 ++++++++++++++-----------------------
3 files changed, 59 insertions(+), 35 deletions(-)
diff --git a/ert-tests/test-builtin-font-lock.el
b/ert-tests/test-builtin-font-lock.el
index 3f35940..5e3184a 100644
--- a/ert-tests/test-builtin-font-lock.el
+++ b/ert-tests/test-builtin-font-lock.el
@@ -27,8 +27,17 @@ foo. table.sort(foobar)
foo .table.sort(foobar)
foo:table.sort(foobar)
foo: table.sort(foobar)
-foo :table.sort(foobar)"
- '(nil nil nil nil nil nil))
+foo :table.sort(foobar)
+
+_table.sort(foobar)
+ table_.sort(foobar)"
+ '(nil nil nil nil nil nil nil nil nil))
+
+ (should-lua-font-lock-equal
+ "\
+ table ._sort(foobar)
+ table. sort_(foobar)"
+ '(("table" builtin) ("table" builtin)))
(should-lua-font-lock-equal
;; After concatenation operator builtins should be highlighted too.
@@ -41,8 +50,25 @@ foo :table.sort(foobar)"
"a = { nil, true, false}"
'(("nil" constant "true" constant "false" constant)))
+ ;; Hint user that builtin constants cannot be used like that
(should-lua-font-lock-equal
"a = { foo.true, foo:false }"
- '(;; This case won't work while '.' has symbol syntax
- ;; ("true" constant "false" constant)
- ("false" constant))))
+ '(("true" constant "false" constant))))
+
+
+(ert-deftest lua-font-lock-keywords ()
+ (should-lua-font-lock-equal
+ "do foo(5) end"
+ '(("do" keyword "end" keyword)))
+
+ (should-lua-font-lock-equal
+ "_do foo(5) end_"
+ '(nil))
+
+ ;; Hint user that keywords cannot be used like that
+ (should-lua-font-lock-equal
+ "do foo(5).end end"
+ '(("do" keyword "end" keyword "end" keyword)))
+ (should-lua-font-lock-equal
+ "do foo(5):end end"
+ '(("do" keyword "end" keyword "end" keyword))))
diff --git a/ert-tests/test-indentation.el b/ert-tests/test-indentation.el
index f3122bf..e51ed9e 100644
--- a/ert-tests/test-indentation.el
+++ b/ert-tests/test-indentation.el
@@ -208,3 +208,14 @@
(ert-deftest lua-indentation-tablector ()
;; FIXME: add
)
+
+(ert-deftest lua-indentation-continuation-spans-over-empty-lines ()
+ ;; FIXME: add
+ ;; FIXME: check comment-only lines too
+ )
+
+
+(ert-deftest lua-indentation-keywords-with-special-characters ()
+ (should-lua-indent '("do"
+ " foobar = _do"
+ "end")))
diff --git a/lua-mode.el b/lua-mode.el
index c15e2fe..514af67 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -373,24 +373,16 @@ traceback location."
("table" . ("concat" "insert" "maxn" "pack" "remove" "sort"
"unpack"
)))))
- ;; This code uses \\< and \\> to delimit builtin symbols instead of
- ;; \\_< and \\_>, because -- a necessity -- '.' syntax class is hacked
- ;; to 'symbol' and \\_> won't detect a symbol boundary in 'foo.bar' and
- ;; -- sufficiency -- conveniently, underscore '_' is hacked to count as
- ;; word constituent, but only for font-locking. Neither of these hacks
- ;; makes sense to me, I'm going to wipe them out as soon as I'm sure
- ;; that indentation won't get hurt. --immerrr
- ;;
(lua--cl-labels
((module-name-re (x)
- (concat "\\(?1:\\<"
+ (concat "\\(?1:\\_<"
(if (listp x) (car x) x)
- "\\>\\)"))
+ "\\_>\\)"))
(module-members-re (x) (if (listp x)
(concat "\\(?:[ \t]*\\.[ \t]*"
- "\\<\\(?2:"
+ "\\_<\\(?2:"
(regexp-opt (cdr x))
- "\\)\\>\\)?")
+ "\\)\\_>\\)?")
"")))
(concat
@@ -633,9 +625,6 @@ Groups 6-9 can be used in any of argument regexps."
(modify-syntax-entry ?= ".")
(modify-syntax-entry ?~ ".")
- ;; '.' character might be better as punctuation, as in C, but this way you
- ;; can treat table index as symbol, e.g. `io.string'
- (modify-syntax-entry ?. "_")
(syntax-table))
"`lua-mode' syntax table.")
@@ -652,10 +641,8 @@ Groups 6-9 can be used in any of argument regexps."
`(lua-font-lock-keywords ;; keywords
nil ;; keywords-only
nil ;; case-fold
- ;; Not sure, why '_' is a word constituent only when font-locking.
- ;; --immerrr
- ((?_ . "w")) ;; syntax-alist
- nil ;; syntax-begin
+ nil ;; syntax-alist
+ nil ;; syntax-begin
;; initialize font-lock buffer-local variables
(font-lock-syntactic-keywords . lua-font-lock-syntactic-keywords)
(font-lock-extra-managed-props . (syntax-table))
@@ -889,20 +876,20 @@ ignored, nil otherwise."
(regexp-opt '("{" "(" "[" "]" ")" "}") t))))
(defconst lua-block-token-alist
- '(("do" "\\<end\\>" "\\<for\\|while\\>"
middle-or-open)
- ("function" "\\<end\\>" nil open)
- ("repeat" "\\<until\\>" nil open)
- ("then" "\\<\\(e\\(lse\\(if\\)?\\|nd\\)\\)\\>" "\\<\\(else\\)?if\\>"
middle)
+ '(("do" "\\_<end\\_>" "\\_<for\\|while\\_>"
middle-or-open)
+ ("function" "\\_<end\\_>" nil open)
+ ("repeat" "\\_<until\\_>" nil open)
+ ("then" "\\_<\\(e\\(lse\\(if\\)?\\|nd\\)\\)\\_>"
"\\_<\\(else\\)?if\\_>" middle)
("{" "}" nil open)
("[" "]" nil open)
("(" ")" nil open)
- ("if" "\\<then\\>" nil open)
- ("for" "\\<do\\>" nil open)
- ("while" "\\<do\\>" nil open)
- ("else" "\\<end\\>" "\\<then\\>" middle)
- ("elseif" "\\<then\\>" "\\<then\\>" middle)
- ("end" nil "\\<\\(do\\|function\\|then\\|else\\)\\>" close)
- ("until" nil "\\<repeat\\>" close)
+ ("if" "\\_<then\\_>" nil open)
+ ("for" "\\_<do\\_>" nil open)
+ ("while" "\\_<do\\_>" nil open)
+ ("else" "\\_<end\\_>" "\\_<then\\_>"
middle)
+ ("elseif" "\\_<then\\_>" "\\_<then\\_>"
middle)
+ ("end" nil "\\_<\\(do\\|function\\|then\\|else\\)\\_>"
close)
+ ("until" nil "\\_<repeat\\_>"
close)
("}" nil "{" close)
("]" nil "\\[" close)
(")" nil "(" close))
- [nongnu] elpa/lua-mode 8aa98ae 185/468: Non-functional refactoring, (continued)
- [nongnu] elpa/lua-mode 8aa98ae 185/468: Non-functional refactoring, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7605d2c 186/468: lua-font-lock-keywords: rewrite poorly written regexp (issue #47), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c24f16e 188/468: Put Lua reference resources into TODO file, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 5d81110 196/468: Wrap symbols required during compilation into (eval-when compile ...), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 040bc8f 213/468: Bump NEWS, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1d8dc55 214/468: Rename lua--function-name-rx, use it in font-lock keywords init, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d552910 218/468: Add a test for defun font-locking; add make check target to run it, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4141c85 222/468: Make builtin font-locking more stable; enable it after ".." operator, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1716660 223/468: Fix interaction with electric-pair-mode (issue #54), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 4217513 230/468: Remove highlighting of numbers for consistency with other major-modes, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 248bea3 233/468: Remove syntax hacks for '.' & '_' characters,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode c5e9620 238/468: Fix stacktrace parsing in inferior process buffer, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode f834c21 105/468: lua-mark-all-multiline-literals: fix missed rename, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode aec4eea 117/468: lua-mark/-unmark-all-multiline-literals: fix error occurring on empty buffer (fixes #4 ?), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 535ca1b 128/468: lua-mark-char-multiline-delim, lua-unmark-multiline-literals: inhibit after-change-functions to avoid running automarking twice on the same text, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode bb9330f 132/468: Fix string contents indentation (issue #6), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d57fdaf 134/468: String content indentation: put back code that forbidden ANY indentation unless it's enabled, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8435a96 137/468: Major modifications to indentation logic., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 98f7fb0 145/468: lua-calculate-indentation: remove unneeded variables & "let" form, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 167e046 147/468: lua-calculate-indentation-override: fix typo (caddr was a reference to wrong field of token table), Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a0490fc 150/468: lua-font-lock-keywords: highlight hash-bang line as comment (#17), Philip Kaludercic, 2021/08/05