[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 6f7800f 258/468: Merge (and squash) pull request
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 6f7800f 258/468: Merge (and squash) pull request #66 from rolpereira/master |
Date: |
Thu, 5 Aug 2021 04:58:49 -0400 (EDT) |
branch: elpa/lua-mode
commit 6f7800f24c337f3f96845619a132ebc4e22f96f8
Author: Rolando Pereira <rolando_pereira@sapo.pt>
Commit: immerrr <immerrr+lua@gmail.com>
Merge (and squash) pull request #66 from rolpereira/master
Add support for Lua5.2 goto keyword
* font-lock: add new keyword, highlight labels as constants
* indentation: fix labels being treated as continuation lines
---
lua-mode.el | 17 ++++--
test/test-defun-font-lock.el | 32 ++++++++++++
test/test-indentation.el | 120 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 166 insertions(+), 3 deletions(-)
diff --git a/lua-mode.el b/lua-mode.el
index 5c631c7..ad10382 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -192,8 +192,8 @@ element is itself expanded with `lua-rx-to-string'. "
">" "=" ";" ":" "," "." ".." "..."))
(lua-keyword
:rx (symbol "and" "break" "do" "else" "elseif" "end" "for"
"function"
- "if" "in" "local" "not" "or" "repeat" "return" "then"
- "until" "while")))
+ "goto" "if" "in" "local" "not" "or" "repeat" "return"
+ "then" "until" "while")))
))
@@ -592,6 +592,17 @@ Groups 6-9 can be used in any of argument regexps."
(,(lua-rx lua-keyword)
. font-lock-keyword-face)
+ ;; Labels used by the "goto" statement
+ ;; Highlights the following syntax: ::label::
+ (,(lua-rx "::" ws lua-name ws "::")
+ . font-lock-constant-face)
+
+ ;; Hightlights the name of the label in the "goto" statement like
+ ;; "goto label"
+ (,(lua-rx (symbol (seq "goto" ws+ (group-n 1 lua-name))))
+ nil nil
+ (1 font-lock-constant-face))
+
;; Highlight lua builtin functions and variables
(,lua--builtins
(1 font-lock-builtin-face) (2 font-lock-builtin-face nil noerror))
@@ -1105,7 +1116,7 @@ Returns final value of point as integer or nil if
operation failed."
(eval-when-compile
(defconst lua-operator-class
- "-+*/^.=<>~"))
+ "-+*/^.=<>~:"))
(defconst lua-cont-eol-regexp
(eval-when-compile
diff --git a/test/test-defun-font-lock.el b/test/test-defun-font-lock.el
index 125ebf7..28072ab 100644
--- a/test/test-defun-font-lock.el
+++ b/test/test-defun-font-lock.el
@@ -77,3 +77,35 @@ end"
("qux_qux" function-name "function" keyword "end" keyword)
("local" keyword "quux_quux" function-name "function" keyword "end"
keyword)
("end" keyword))) )
+
+(ert-deftest lua-font-lock-labels ()
+ (should-lua-font-lock-equal
+ "\
+goto foo
+::foo::"
+ '(("goto" keyword "foo" constant)
+ ("::foo::" constant)))
+
+ (should-lua-font-lock-equal
+ "\
+local foo = 'test' ::f12o::
+goto f12o"
+ '(("local" keyword "foo" variable-name "'test'" string "::f12o::" constant)
+ ("goto" keyword "f12o" constant)))
+
+ ;; With spaces after and before "::"
+ (should-lua-font-lock-equal
+ "\
+goto foo
+:: foo ::"
+ '(("goto" keyword "foo" constant)
+ (":: foo ::" constant)))
+
+ ;; Don't font lock labels when substring "goto" appears as a suffix
+ ;; of another variable
+ (should-lua-font-lock-equal
+ "\
+JUNKgoto foo
+:: foo ::"
+ '(nil ;; don't font lock "foo"
+ (":: foo ::" constant))))
diff --git a/test/test-indentation.el b/test/test-indentation.el
index 53810db..aefbf53 100644
--- a/test/test-indentation.el
+++ b/test/test-indentation.el
@@ -493,3 +493,123 @@ for k, v
a = 0")
)
+
+(ert-deftest lua-indentation-labels ()
+ (should-lua-indent "\
+::foo::")
+
+ (should-lua-indent "\
+::foo::
+::bar::
+
+::baz::")
+
+ ;; The following tests come from the LuaWiki goto page:
+ ;; http://lua-users.org/wiki/GotoStatement
+ (should-lua-indent "\
+for z=1,10 do
+ for y=1,10 do
+ for x=1,10 do
+ if x^2 + y^2 == z^2 then
+ print('found a Pythagorean triple:', x, y, z)
+ goto done
+ goto done2
+ end
+ end
+ ::done2::
+ end
+end
+
+::done::")
+
+ (should-lua-indent "\
+-- 5.2.0-beta-rc2
+for z=1,10 do
+ for y=1,10 do
+ for x=1,10 do
+ if x^2 + y^2 == z^2 then
+ print('found a Pythagorean triple:', x, y, z)
+ print('now trying next z...')
+ goto zcontinue
+ end
+ end
+ end
+ ::zcontinue::
+end")
+
+ (should-lua-indent "\
+-- Lua 5.2.0-beta-rc2
+for x=1,5 do ::redo::
+ print(x .. ' + 1 = ?')
+ local y = tonumber(io.read'*l')
+ if y ~= x + 1 then goto redo end
+end")
+
+ (should-lua-indent "\
+-- 5.2.0-beta-rc1
+::a::
+print 'A'
+if math.random() < 0.3 then goto c end
+::b::
+print 'B'
+if math.random() < 0.5 then goto a end
+::c::
+print 'C'
+if math.random() < 0.1 then goto a else goto b end
+")
+
+ (should-lua-indent "\
+-- 5.2.0-beta-rc2 - factorial with tail recursion simulated with goto's
+-- (warning: there's no need to do this)
+function fact_(n, ans)
+ ::call::
+ if n == 0 then
+ return ans
+ else
+ n, ans = n - 1, ans * n
+ goto call
+ end
+end
+print(fact_(5, 1)) --> 120")
+
+ (should-lua-indent "\
+-- 5.2.0-beta-rc2
+function f()
+ if not g() then goto fail end
+ if not h() then goto cleanup_g end
+ if not i() then goto cleanup_h end
+ do return true end -- need do/end?
+
+ ::cleanup_h::
+ undo_h()
+ ::cleanup_g::
+ undo_g()
+ ::fail::
+ return false
+end")
+
+ (should-lua-indent "\
+-- 5.2.0-beta-rc2
+::redo::
+for x=1,10 do
+ for y=1,10 do
+ if not f(x,y) then goto continue end
+ if not g(x,y) then goto skip end
+ if not h(x,y) then goto redo end
+ ::continue::
+ end
+end ::skip::
+print('foo')"))
+
+(ert-deftest lua-indentation-indent-labels-inside-multiline-string ()
+ :expected-result :failed
+ ;; TODO: It seems that `should-lua-indent' tries to indent text
+ ;; inside the "[[ ]]" multiline string?
+ (should-lua-indent "\
+local b, bt = [[
+ if not x then goto a end
+ f()
+ goto b; ::a::
+ g()
+ ::b::
+]]"))
- [nongnu] elpa/lua-mode 478da4a 393/468: Fixed order of expected & actual in matcher's message, (continued)
- [nongnu] elpa/lua-mode 478da4a 393/468: Fixed order of expected & actual in matcher's message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d15bdb1 395/468: Merge pull request #164 from sergeyklay/fix/buttercup-matcher-message, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c1b6019 396/468: Fix reproducibility issue caused by %d pattern in export-subst, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c9b9d47 401/468: Fix typo, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d7eaa8e 403/468: Add lua-backward-up-list command, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode db8d474 408/468: Fix indentation of multiline while/for+do and if/elseif+then, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 099c130 240/468: Bump NEWS, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7099b81 248/468: Bump tests: fix some, move expected failures to separate test cases, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6a5fa6b 249/468: Remove unused tempfile functionality, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 1a0e191 255/468: lua--rx-symbol: fix shy-grouping, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6f7800f 258/468: Merge (and squash) pull request #66 from rolpereira/master,
Philip Kaludercic <=
- [nongnu] elpa/lua-mode 3265552 263/468: indentation-test: add continuation tests for unary ops and ..., Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 9abad67 273/468: Merge remote-tracking branch 'upstream/master', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ec491dd 291/468: lua-process-init-code: use load when loadstring is not available, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode d7ccb88 294/468: Add new builtin functions and operators from Lua 5.3, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c0d8c50 295/468: Merge pull request #86 from immerrr/if-loadstring-is-nil-use-load, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3f7a032 300/468: Move .nosearch in test/, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ca24f4c 302/468: Add `run-lua` alias, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 530aa9f 303/468: Merge pull request #97 from marsam/master, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 92d9729 307/468: Add init-tryout.el to persistent initialization code, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 04a2772 310/468: Fix goto label fontification, Philip Kaludercic, 2021/08/05