From 88b6be6e6f0d43491eebecfe7dd0de13ecfe4ec1 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 25 Oct 2026 12:51:05 -1000 Subject: Colour css properties and pseudo-classes Scintillua's css lexer tags them with names the map had no row for, so they came out as plain text. --- tests/extensions/fake-lexers/lexer.lua | 33 +++++++++++++++--------------- tests/extensions/test-syntax-highlight.lua | 4 ++++ 2 files changed, 21 insertions(+), 16 deletions(-) (limited to 'tests/extensions') diff --git a/tests/extensions/fake-lexers/lexer.lua b/tests/extensions/fake-lexers/lexer.lua index 0632744..ea7768e 100644 --- a/tests/extensions/fake-lexers/lexer.lua +++ b/tests/extensions/fake-lexers/lexer.lua @@ -11,29 +11,30 @@ local M = {} -- Tokens come back the way Scintillua returns them, one flat list of a tag -- name and the position just past the token it names. Letter runs are -- keywords, digit runs are numbers, a single quoted run carries a dotted tag --- so the dotted first component lookup gets exercised, and any other byte is --- whitespace, which maps to no css class. +-- so the dotted first component lookup gets exercised, a run after a colon or +-- a dollar sign takes one of the tags only the css lexer uses, and any other +-- byte is whitespace, which maps to no css class. +local patterns = { + { "^:%a+", "pseudoclass" }, + { "^%$%a+", "property" }, + { "^%a+", "keyword" }, + { "^%d+", "number" }, + { "^'[^']*'", "string.double" }, +} + local function lex_words(self, text) local tokens = {} local pos = 1 while pos <= #text do - local start, stop = text:find("^%a+", pos) - if not start then - start, stop = text:find("^%d+", pos) + local tag, stop = "whitespace", pos + for _, pattern in ipairs(patterns) do + local start, finish = text:find(pattern[1], pos) if start then - tokens[#tokens + 1] = "number" - else - start, stop = text:find("^'[^']*'", pos) - if start then - tokens[#tokens + 1] = "string.double" - else - stop = pos - tokens[#tokens + 1] = "whitespace" - end + tag, stop = pattern[2], finish + break end - else - tokens[#tokens + 1] = "keyword" end + tokens[#tokens + 1] = tag tokens[#tokens + 1] = stop + 1 pos = stop + 1 end diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua index f831b01..50c7bc8 100644 --- a/tests/extensions/test-syntax-highlight.lua +++ b/tests/extensions/test-syntax-highlight.lua @@ -55,6 +55,10 @@ h.contains("bytes between tokens are escaped", out, " & ") h.contains("later tokens still highlight", out, "zz") h.equals("close answers zero", ret, 0) +out = render("hello.fake", "$color :hover") +h.contains("a css property takes the number class", out, "$color") +h.contains("a css pseudo-class takes the function class", out, ":hover") + out = h.run({ "split.fake" }, { "i", "f" }) h.equals("writes are joined before lexing", out, "if") -- cgit 2.9.2