emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]