From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: john muhl Newsgroups: gmane.emacs.devel Subject: Re: [ELPA] New package: ert-font-lock Date: Tue, 21 Nov 2023 10:51:40 -0600 Message-ID: <87h6lfqbp9.fsf@thelio.lan> References: <87v89zz4v4.fsf@posteo.net> <87v89zjmcx.fsf@yahoo.com> <83fs13mduq.fsf@gnu.org> <87zfz7k8ya.fsf@thelio.lan> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36429"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Po Lu , philipk@posteo.net, emacs-devel@gnu.org To: Vladimir Kazanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 21 18:49:04 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r5Urw-0009Ch-6r for ged-emacs-devel@m.gmane-mx.org; Tue, 21 Nov 2023 18:49:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5Uqx-00064E-Bk; Tue, 21 Nov 2023 12:48:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5UBp-0006fL-TW for emacs-devel@gnu.org; Tue, 21 Nov 2023 12:05:35 -0500 Original-Received: from out-189.mta1.migadu.com ([95.215.58.189]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5UBW-00026t-5J for emacs-devel@gnu.org; Tue, 21 Nov 2023 12:05:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pub.pink; s=key1; t=1700586311; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Rpz8Ly4C8yFfUw07WGqoGYEe7BA7xAK97HCK8Dk0exY=; b=Nh6Wqbu58S1HrWgGKcKGJ08SnKs4sq8rvbFkGR/KLl/Abu0OAljGWyf5ot1lAVZZnlXqzy Hzd+mjfq7BmmaEC1G0Q7pAnjlgBuKzEqDNY9a/CSQgnKTvNAK5ItwLJP3gruT1v/g8oU/N Bnefbx9YcSFvqJyl5WgR3fOTWx7T4vQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=95.215.58.189; envelope-from=jm@pub.pink; helo=out-189.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 21 Nov 2023 12:48:01 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:313121 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Vladimir Kazanov writes: > On Tue, 21 Nov 2023 at 04:48, john muhl wrote: > >> FWIW I used it to add tests for lua-ts-mode=E2=80=99s font-lock rules. >> It works well and feels to me like it would be a nice addition >> to Emacs. Thanks for working on it. > > Hey, that's nice to hear! > > Can I take a look at the code? Curious about the way comment > highlighting is implemented in your mode. https://git.sv.gnu.org/cgit/emacs.git/tree/lisp/progmodes/lua-ts-mode.el Attached are the tests. They fail against master since some bugs were found in the process. > I did test popular Emacs major modes (cc-mode and the like, python, > php, etc) but few ts-based ones. And even in the pre-Tree-sitter world > comment detection is rather unstable and needs custom hacks in some > cases. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-font-lock-tests-for-lua-ts-mode-ert-font-lock.patch >From 5e239acb7217192e74577a123ed172992402b318 Mon Sep 17 00:00:00 2001 From: john muhl Date: Mon, 20 Nov 2023 23:02:12 -0600 Subject: [PATCH] Add font-lock tests for lua-ts-mode (ert-font-lock) * test/lisp/progmodes/lua-ts-mode-tests.el (lua-ts-test-font-lock): Add test. * test/lisp/progmodes/lua-ts-mode-resources/font-lock.lua: New file. --- .../lua-ts-mode-resources/font-lock.lua | 332 ++++++++++++++++++ test/lisp/progmodes/lua-ts-mode-tests.el | 6 + 2 files changed, 338 insertions(+) create mode 100644 test/lisp/progmodes/lua-ts-mode-resources/font-lock.lua diff --git a/test/lisp/progmodes/lua-ts-mode-resources/font-lock.lua b/test/lisp/progmodes/lua-ts-mode-resources/font-lock.lua new file mode 100644 index 00000000000..86bdfa2c8f1 --- /dev/null +++ b/test/lisp/progmodes/lua-ts-mode-resources/font-lock.lua @@ -0,0 +1,332 @@ +#!/usr/bin/env lua +-- ^ font-lock-comment-face +-- Comment +-- ^ font-lock-comment-face +--[[ +Multi-line comment +-- ^ font-lock-comment-face +]] + +-- Definition +local function f1() end +-- ^ font-lock-function-name-face +local f2 = function() end +-- ^ font-lock-function-name-face +local tb = { f1 = function() end } +-- ^ font-lock-function-name-face +function tb.f2() end +-- ^ font-lock-function-name-face +function tb:f3() end +-- ^ font-lock-function-name-face +tbl.f4 = function() end +-- ^ font-lock-function-name-face +function x.y:z() end +-- ^ font-lock-function-name-face + +-- Keyword +if true then +-- <- font-lock-keyword-face +elseif true then +-- <- font-lock-keyword-face +else end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +local p = {} +-- ^ font-lock-keyword-face +for k,v in pairs({}) do end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +repeat if true then break end until false +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +-- ^ font-lock-keyword-face +while true do end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +function fn() return true end +-- <- font-lock-keyword-face +-- ^ font-lock-keyword-face +goto label +-- ^ font-lock-keyword-face +::label1:: + +-- String +local _ +_ = "x" +-- ^ font-lock-string-face +_ = 'x' +-- ^ font-lock-string-face +_ = "x\ty" +-- ^ font-lock-string-face +-- ^ font-lock-string-face +_ = "x\"y" +-- ^ font-lock-string-face +-- ^ font-lock-string-face +_ = 'x\'y' +-- ^ font-lock-string-face +-- ^ font-lock-string-face +_ = "x\z + y" +-- ^ font-lock-string-face +_ = "x\0900y" +-- ^ font-lock-string-face +_ = "x\09y" +-- ^ font-lock-string-face +_ = "x\0y" +-- ^ font-lock-string-face +_ = "x\u{1f602}y" +-- ^ font-lock-string-face +_ = [[x]] +-- ^ font-lock-string-face +_ = [=[x]=] +-- ^ font-lock-string-face + +-- Assignment +local n = 0 +-- ^ font-lock-variable-name-face +o, p, q = 1, 2, 3 +-- <- font-lock-variable-name-face +-- ^ font-lock-variable-name-face +-- ^ font-lock-variable-name-face +tbl[k] = "A" +-- ^ font-lock-variable-name-face +tbl.x = 1 +-- ^ font-lock-variable-name-face +for i=0,9 do end +-- ^ font-lock-variable-name-face + +-- Constant +local x = 1 +-- ^ font-lock-constant-face +local f = io.open('/file') +-- ^ font-lock-constant-face +local a, b, c = true, false, nil +-- ^ font-lock-constant-face +-- ^ font-lock-constant-face +-- ^ font-lock-constant-face +::label2:: +-- ^ font-lock-constant-face + +-- Number +n = 123 +-- ^ font-lock-number-face +print(99) +-- ^ font-lock-number-face +tbl[1] +-- ^ font-lock-number-face + +-- Bracket +local t = {} +-- ^ font-lock-bracket-face +-- ^ font-lock-bracket-face +print(t[1]) +-- ^ font-lock-bracket-face +-- ^ font-lock-bracket-face +-- ^ font-lock-bracket-face +-- ^ font-lock-bracket-face + +-- Builtin +assert() +-- <- font-lock-builtin-face +bit32() +-- <- font-lock-builtin-face +collectgarbage() +-- <- font-lock-builtin-face +coroutine() +-- <- font-lock-builtin-face +debug() +-- <- font-lock-builtin-face +dofile() +-- <- font-lock-builtin-face +error() +-- <- font-lock-builtin-face +getmetatable() +-- <- font-lock-builtin-face +io() +-- <- font-lock-builtin-face +ipairs() +-- <- font-lock-builtin-face +load() +-- <- font-lock-builtin-face +loadfile() +-- <- font-lock-builtin-face +math() +-- <- font-lock-builtin-face +next() +-- <- font-lock-builtin-face +os() +-- <- font-lock-builtin-face +package() +-- <- font-lock-builtin-face +pairs() +-- <- font-lock-builtin-face +pcall() +-- <- font-lock-builtin-face +print() +-- <- font-lock-builtin-face +rawequal() +-- <- font-lock-builtin-face +rawget() +-- <- font-lock-builtin-face +rawlen() +-- <- font-lock-builtin-face +rawset() +-- <- font-lock-builtin-face +require() +-- <- font-lock-builtin-face +select() +-- <- font-lock-builtin-face +setmetatable() +-- <- font-lock-builtin-face +string() +-- <- font-lock-builtin-face +table() +-- <- font-lock-builtin-face +tonumber() +-- <- font-lock-builtin-face +tostring() +-- <- font-lock-builtin-face +type() +-- <- font-lock-builtin-face +utf8() +-- <- font-lock-builtin-face +warn() +-- <- font-lock-builtin-face +xpcall() +-- <- font-lock-builtin-face +print(_G) +-- ^ font-lock-builtin-face +print(_VERSION) +-- ^ font-lock-builtin-face +f.close() +-- ^ font-lock-builtin-face +f.flush() +-- ^ font-lock-builtin-face +f.lines() +-- ^ font-lock-builtin-face +f.read() +-- ^ font-lock-builtin-face +f.seek() +-- ^ font-lock-builtin-face +f.setvbuf() +-- ^ font-lock-builtin-face +f.write() +-- ^ font-lock-builtin-face + +-- Delimiter +t = { 1, 2 }; +-- ^ font-lock-delimiter-face +-- ^ font-lock-delimiter-face + +-- Escape +_ = "x\ty" +-- ^ font-lock-escape-face +-- ^ font-lock-escape-face +_ = "x\"y" +-- ^ font-lock-escape-face +-- ^ font-lock-escape-face +_ = 'x\'y' +-- ^ font-lock-escape-face +-- ^ font-lock-escape-face +_ = "x\z + y" +-- <- font-lock-escape-face +_ = "x\x5Ay" +-- ^ font-lock-escape-face +-- ^ font-lock-escape-face +_ = "x\0900y" +-- ^ font-lock-escape-face +_ = "x\09y" +-- ^ font-lock-escape-face +_ = "x\0y" +-- ^ font-lock-escape-face +_ = "x\u{1f602}y" +-- ^ font-lock-escape-face +-- ^ font-lock-escape-face + +-- Function +func_one() +-- ^ font-lock-function-call-face +tbl.func_two() +-- ^ font-lock-function-call-face +tbl:func_three() +-- ^ font-lock-function-call-face +tbl.f = f4() +-- ^ font-lock-function-call-face + +-- Operator +local a, b = 1, 2 +-- ^ font-lock-operator-face +print(a & b) +-- ^ font-lock-operator-face +print(a | b) +-- ^ font-lock-operator-face +print(a ~ b) +-- ^ font-lock-operator-face +print(a << 1) +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +print(a >> 1) +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +print(a and b) +-- ^ font-lock-operator-face +print(a or b) +-- ^ font-lock-operator-face +print(not a) +-- ^ font-lock-operator-face +print(a+b-a*b/a%b^a//b) +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +-- ^ font-lock-operator-face +print(#t) +-- ^ font-lock-operator-face +print("h".."at") +-- ^ font-lock-operator-face +print(a==b) +-- ^ font-lock-operator-face +print(a~=b) +-- ^ font-lock-operator-face +print(a<=b) +-- ^ font-lock-operator-face +print(a>=b) +-- ^ font-lock-operator-face +print(ab) +-- ^ font-lock-operator-face +function ff(...) end +-- ^ font-lock-operator-face + +-- Property +t = { a=1 } +-- ^ font-lock-property-name-face +print(t.a) +-- ^ font-lock-property-use-face + +-- Punctuation +tbl.f2() +-- ^ font-lock-punctuation-face +tbl:f3() +-- ^ font-lock-punctuation-face + +-- Variable +function fn(x, y) end +-- ^ font-lock-variable-name-face +-- ^ font-lock-variable-name-face +fn(a, b) +-- ^ font-lock-variable-use-face +-- ^ font-lock-variable-use-face +print(a + b) +-- ^ font-lock-variable-use-face +-- ^ font-lock-variable-use-face +print(t[a]) +-- ^ font-lock-variable-use-face +tbl.f1(p) +-- ^ font-lock-variable-use-face +tbl:f2(q) +-- ^ font-lock-variable-use-face diff --git a/test/lisp/progmodes/lua-ts-mode-tests.el b/test/lisp/progmodes/lua-ts-mode-tests.el index d2105b66f6d..c644280f90d 100644 --- a/test/lisp/progmodes/lua-ts-mode-tests.el +++ b/test/lisp/progmodes/lua-ts-mode-tests.el @@ -20,6 +20,7 @@ ;;; Code: (require 'ert) +(require 'ert-font-lock) (require 'ert-x) (require 'treesit) @@ -31,6 +32,11 @@ lua-ts-mode-test-movement (skip-unless (treesit-ready-p 'lua)) (ert-test-erts-file (ert-resource-file "movement.erts"))) +(ert-deftest lua-ts-test-font-lock () + (skip-unless (treesit-ready-p 'lua)) + (let ((treesit-font-lock-level 4)) + (ert-font-lock-test-file (ert-resource-file "font-lock.lua") 'lua-ts-mode))) + (provide 'lua-ts-mode-tests) ;;; lua-ts-mode-tests.el ends here -- 2.41.0 --=-=-=--