diff options
-rw-r--r--custom/extensions/syntax-highlight.lua31
-rw-r--r--tests/extensions/fake-lexers/lexer.lua33
-rw-r--r--tests/extensions/test-syntax-highlight.lua4
3 files changed, 38 insertions, 30 deletions
diff --git a/custom/extensions/syntax-highlight.lua b/custom/extensions/syntax-highlight.lua
index c178f25..8a1e7ab 100644
--- a/custom/extensions/syntax-highlight.lua
+++ b/custom/extensions/syntax-highlight.lua
@@ -55,20 +55,23 @@ local scintillua_dirs = {
-- tag with no row renders as plain text, which is what most themes want for
-- operators and identifiers.
local css = {
- comment = "hl-comment",
- string = "hl-string",
- regex = "hl-string",
- number = "hl-number",
- constant = "hl-number",
- keyword = "hl-keyword",
- preprocessor = "hl-keyword",
- tag = "hl-keyword",
- label = "hl-keyword",
- annotation = "hl-keyword",
- type = "hl-type",
- class = "hl-type",
- attribute = "hl-type",
- ["function"] = "hl-func",
+ comment = "hl-comment",
+ string = "hl-string",
+ regex = "hl-string",
+ number = "hl-number",
+ constant = "hl-number",
+ property = "hl-number",
+ keyword = "hl-keyword",
+ preprocessor = "hl-keyword",
+ tag = "hl-keyword",
+ label = "hl-keyword",
+ annotation = "hl-keyword",
+ type = "hl-type",
+ class = "hl-type",
+ attribute = "hl-type",
+ ["function"] = "hl-func",
+ pseudoclass = "hl-func",
+ pseudoelement = "hl-func",
}
-- Extension to lexer name fixes for the fallback path, reached only when
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, " &amp; ")
h.contains("later tokens still highlight", out, "<span class='hl-keyword'>zz</span>")
h.equals("close answers zero", ret, 0)
+out = render("hello.fake", "$color :hover")
+h.contains("a css property takes the number class", out, "<span class='hl-number'>$color</span>")
+h.contains("a css pseudo-class takes the function class", out, "<span class='hl-func'>:hover</span>")
+
out = h.run({ "split.fake" }, { "i", "f" })
h.equals("writes are joined before lexing", out, "<span class='hl-keyword'>if</span>")