commit c7d76b1b83635cc79c2f4594a9a1c55021da9974
parent 96db04c77b0eaf347800af9cadf59c095c461f1e
Author: Robert Russell <robert@rr3.xyz>
Date: Thu, 21 May 2026 12:08:29 -0700
vis: update theme and lexers to support newer versions (clanked)
Diffstat:
7 files changed, 115 insertions(+), 260 deletions(-)
diff --git a/vis/lexers/ansi_c.lua b/vis/lexers/ansi_c.lua
@@ -1,8 +1,7 @@
-local M = {_NAME = "ansi_c"}
-
local l = require("lexer")
+local lex = l.new(...)
local P, R, S = lpeg.P, lpeg.R, lpeg.S
-local T = l.token
+local T = function(name, patt) return lex:tag(name, patt) end
local any = P(1)
local oct = R"07"
local dec = R"09"
@@ -171,55 +170,21 @@ local function_ = T("function", word) * #P"("
local identifier = T("identifier", word)
-M._rules = {
- {"whitespace", whitespace},
- {"comment", comment},
- {"numlit", numlit},
- {"charlit", charlit},
- {"strlit", strlit},
- {"delimiter", delimiter},
- {"operator", operator},
- {"preproc", preproc},
- {"keyword", keyword},
- {"constant", constant},
- {"type", type_},
- {"label", label},
- {"function", function_},
- {"identifier", identifier},
-
- {"error", T("error", any)}, -- TODO: TEMP
-}
-
-M._tokenstyles = {
- whitespace = l.STYLE_WHITESPACE,
-
- comment_text = l.STYLE_COMMENT,
- comment_keyword = l.STYLE_COMMENT_KEYWORD,
-
- numlit = l.STYLE_NUMBER,
-
- escape = l.STYLE_ESCAPE,
- bad_escape = l.STYLE_ERROR,
-
- charlit_delim = l.STYLE_NUMBER,
- charlit_text = l.STYLE_NUMBER,
-
- strlit_delim = l.STYLE_STRING,
- strlit_text = l.STYLE_STRING,
- strlit_format = l.STYLE_STRING_FORMAT,
-
- delimiter = l.STYLE_DELIMITER,
- operator = l.STYLE_OPERATOR,
-
- preproc = l.STYLE_PREPROCESSOR,
- preproc_cond = l.STYLE_PREPROCESSOR_CONDITIONAL,
-
- keyword = l.STYLE_KEYWORD,
- constant = l.STYLE_CONSTANT,
- ["type"] = l.STYLE_TYPE,
- label = l.STYLE_LABEL,
- ["function"] = l.STYLE_FUNCTION,
- identifier = l.STYLE_IDENTIFIER,
-}
-
-return M
+lex:add_rule("whitespace", whitespace)
+lex:add_rule("comment", comment)
+lex:add_rule("numlit", numlit)
+lex:add_rule("charlit", charlit)
+lex:add_rule("strlit", strlit)
+lex:add_rule("delimiter", delimiter)
+lex:add_rule("operator", operator)
+lex:add_rule("preproc", preproc)
+lex:add_rule("keyword", keyword)
+lex:add_rule("constant", constant)
+lex:add_rule("type", type_)
+lex:add_rule("label", label)
+lex:add_rule("function", function_)
+lex:add_rule("identifier", identifier)
+
+lex:add_rule("error", T("error", any)) -- TODO: TEMP
+
+return lex
diff --git a/vis/lexers/caml.lua b/vis/lexers/caml.lua
@@ -1,8 +1,7 @@
-local M = {_NAME = "caml"}
-
local l = require("lexer")
+local lex = l.new(...)
local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V
-local T = l.token
+local T = function(name, patt) return lex:tag(name, patt) end
local any = P(1)
local bin = R"01"
local oct = R"07"
@@ -90,45 +89,17 @@ local type_ = T("type", P"'" * word)
local identifier = T("identifier", word * P"'"^0)
-M._rules = {
- {"whitespace", whitespace},
- {"comment", comment},
- {"numlit", numlit},
- {"chrlit", chrlit},
- {"strlit", strlit},
- {"delimiter", delimiter},
- {"operator", operator},
- {"keyword", keyword},
- {"type", type_},
- {"identifier", identifier},
-
- {"error", T("error", any)}, -- TODO: TEMP
-}
-
-M._tokenstyles = {
- whitespace = l.STYLE_WHITESPACE,
-
- comment_keyword = l.STYLE_COMMENT_KEYWORD,
- comment_text = l.STYLE_COMMENT,
-
- numlit = l.STYLE_NUMBER,
-
- bad_escape = l.STYLE_ERROR,
-
- chrlit_escape = l.STYLE_ESCAPE,
- chrlit_delim = l.STYLE_NUMBER,
- chrlit_text = l.STYLE_NUMBER,
-
- strlit_escape = l.STYLE_ESCAPE,
- strlit_delim = l.STYLE_STRING,
- strlit_text = l.STYLE_STRING,
-
- delimiter = l.STYLE_DELIMITER,
- operator = l.STYLE_OPERATOR,
+lex:add_rule("whitespace", whitespace)
+lex:add_rule("comment", comment)
+lex:add_rule("numlit", numlit)
+lex:add_rule("chrlit", chrlit)
+lex:add_rule("strlit", strlit)
+lex:add_rule("delimiter", delimiter)
+lex:add_rule("operator", operator)
+lex:add_rule("keyword", keyword)
+lex:add_rule("type", type_)
+lex:add_rule("identifier", identifier)
- keyword = l.STYLE_KEYWORD,
- ["type"] = l.STYLE_TYPE,
- identifier = l.STYLE_IDENTIFIER,
-}
+lex:add_rule("error", T("error", any)) -- TODO: TEMP
-return M
+return lex
diff --git a/vis/lexers/glsl.lua b/vis/lexers/glsl.lua
@@ -1,10 +1,9 @@
-- TODO: Hack: This is just a copy of the ansi_c lexer with some additions.
-local M = {_NAME = "glsl"}
-
local l = require("lexer")
+local lex = l.new(...)
local P, R, S = lpeg.P, lpeg.R, lpeg.S
-local T = l.token
+local T = function(name, patt) return lex:tag(name, patt) end
local any = P(1)
local oct = R"07"
local dec = R"09"
@@ -191,55 +190,21 @@ local function_ = T("function", word) * #P"("
local identifier = T("identifier", word)
-M._rules = {
- {"whitespace", whitespace},
- {"comment", comment},
- {"numlit", numlit},
- {"charlit", charlit},
- {"strlit", strlit},
- {"delimiter", delimiter},
- {"operator", operator},
- {"preproc", preproc},
- {"keyword", keyword},
- {"constant", constant},
- {"type", type_},
- {"label", label},
- {"function", function_},
- {"identifier", identifier},
-
- {"error", T("error", any)}, -- TODO: TEMP
-}
-
-M._tokenstyles = {
- whitespace = l.STYLE_WHITESPACE,
-
- comment_text = l.STYLE_COMMENT,
- comment_keyword = l.STYLE_COMMENT_KEYWORD,
-
- numlit = l.STYLE_NUMBER,
-
- escape = l.STYLE_ESCAPE,
- bad_escape = l.STYLE_ERROR,
-
- charlit_delim = l.STYLE_NUMBER,
- charlit_text = l.STYLE_NUMBER,
-
- strlit_delim = l.STYLE_STRING,
- strlit_text = l.STYLE_STRING,
- strlit_format = l.STYLE_STRING_FORMAT,
-
- delimiter = l.STYLE_DELIMITER,
- operator = l.STYLE_OPERATOR,
-
- preproc = l.STYLE_PREPROCESSOR,
- preproc_cond = l.STYLE_PREPROCESSOR_CONDITIONAL,
-
- keyword = l.STYLE_KEYWORD,
- constant = l.STYLE_CONSTANT,
- ["type"] = l.STYLE_TYPE,
- label = l.STYLE_LABEL,
- ["function"] = l.STYLE_FUNCTION,
- identifier = l.STYLE_IDENTIFIER,
-}
-
-return M
+lex:add_rule("whitespace", whitespace)
+lex:add_rule("comment", comment)
+lex:add_rule("numlit", numlit)
+lex:add_rule("charlit", charlit)
+lex:add_rule("strlit", strlit)
+lex:add_rule("delimiter", delimiter)
+lex:add_rule("operator", operator)
+lex:add_rule("preproc", preproc)
+lex:add_rule("keyword", keyword)
+lex:add_rule("constant", constant)
+lex:add_rule("type", type_)
+lex:add_rule("label", label)
+lex:add_rule("function", function_)
+lex:add_rule("identifier", identifier)
+
+lex:add_rule("error", T("error", any)) -- TODO: TEMP
+
+return lex
diff --git a/vis/lexers/haskell.lua b/vis/lexers/haskell.lua
@@ -1,8 +1,7 @@
-local M = {_NAME = "haskell"}
-
local l = require("lexer")
+local lex = l.new(...)
local P, R, S = lpeg.P, lpeg.R, lpeg.S
-local T = l.token
+local T = function(name, patt) return lex:tag(name, patt) end
local function I(s) -- Case-insensitive string match
local p = P(true)
@@ -105,44 +104,17 @@ local operator = qualifier * T("operator", hs_varsym + hs_consym)
local type_ = qualifier * T("type", hs_conid)
local identifier = qualifier * T("identifier", hs_varid)
-M._rules = {
- {"whitespace", whitespace},
- {"comment", comment},
- {"numlit", numlit},
- {"chrlit", chrlit},
- {"strlit", strlit},
- {"delimiter", delimiter},
- {"keyword", keyword},
- {"operator", operator},
- {"type", type_},
- {"identifier", identifier},
-
- {"error", T("error", P(1))}, -- TODO: TEMP
-}
-
-M._tokenstyles = {
- whitespace = l.STYLE_WHITESPACE,
-
- comment_text = l.STYLE_COMMENT,
- comment_keyword = l.STYLE_COMMENT_KEYWORD,
-
- numlit = l.STYLE_NUMBER,
-
- escape = l.STYLE_ESCAPE,
-
- chrlit_delim = l.STYLE_NUMBER,
- chrlit_text = l.STYLE_NUMBER,
-
- strlit_delim = l.STYLE_STRING,
- strlit_text = l.STYLE_STRING,
-
- delimiter = l.STYLE_DELIMITER,
- keyword = l.STYLE_KEYWORD,
+lex:add_rule("whitespace", whitespace)
+lex:add_rule("comment", comment)
+lex:add_rule("numlit", numlit)
+lex:add_rule("chrlit", chrlit)
+lex:add_rule("strlit", strlit)
+lex:add_rule("delimiter", delimiter)
+lex:add_rule("keyword", keyword)
+lex:add_rule("operator", operator)
+lex:add_rule("type", type_)
+lex:add_rule("identifier", identifier)
- qualifier = l.STYLE_IDENTIFIER,
- operator = l.STYLE_OPERATOR,
- ["type"] = l.STYLE_TYPE,
- identifier = l.STYLE_IDENTIFIER,
-}
+lex:add_rule("error", T("error", P(1))) -- TODO: TEMP
-return M
+return lex
diff --git a/vis/lexers/mp.lua b/vis/lexers/mp.lua
@@ -1,8 +1,7 @@
-local M = {_NAME = "mp"}
-
local l = require("lexer")
+local lex = l.new(...)
local P, R, S = lpeg.P, lpeg.R, lpeg.S
-local T = l.token
+local T = function(name, patt) return lex:tag(name, patt) end
local any = P(1)
local dec = R"09"
local alpha = R("AZ", "az")
@@ -132,38 +131,16 @@ local type_ = T("type", l.word_match{
local identifier = T("identifier", (alpha + P"_")^1)
-M._rules = {
- {"whitespace", whitespace},
- {"comment", comment},
- {"numlit", numlit},
- {"strlit", strlit},
- {"delimiter", delimiter},
- {"operator", operator},
- {"suffix", suffix},
- {"keyword", keyword},
- {"constant", constant},
- {"type", type_},
- {"identifier", identifier},
-}
-
-M._tokenstyles = {
- whitespace = l.STYLE_WHITESPACE,
-
- comment_text = l.STYLE_COMMENT,
- comment_keyword = l.STYLE_COMMENT_KEYWORD,
-
- numlit = l.STYLE_NUMBER,
-
- strlit = l.STYLE_STRING,
-
- delimiter = l.STYLE_DELIMITER,
- operator = l.STYLE_OPERATOR,
- suffix = l.STYLE_LABEL, -- TODO: this makes no sense
-
- keyword = l.STYLE_KEYWORD,
- constant = l.STYLE_CONSTANT,
- ["type"] = l.STYLE_TYPE,
- identifier = l.STYLE_IDENTIFIER,
-}
-
-return M
+lex:add_rule("whitespace", whitespace)
+lex:add_rule("comment", comment)
+lex:add_rule("numlit", numlit)
+lex:add_rule("strlit", strlit)
+lex:add_rule("delimiter", delimiter)
+lex:add_rule("operator", operator)
+lex:add_rule("suffix", suffix)
+lex:add_rule("keyword", keyword)
+lex:add_rule("constant", constant)
+lex:add_rule("type", type_)
+lex:add_rule("identifier", identifier)
+
+return lex
diff --git a/vis/lexers/tex.lua b/vis/lexers/tex.lua
@@ -1,8 +1,7 @@
-local M = {_NAME = "tex"}
-
local l = require("lexer")
+local lex = l.new(...)
local P, R, S = lpeg.P, lpeg.R, lpeg.S
-local T = l.token
+local T = function(name, patt) return lex:tag(name, patt) end
local any = P(1)
local function I(s) -- Case-insensitive string match
local p = P(true)
@@ -33,28 +32,12 @@ local operator = T("operator", S"^_~&" + (P"#" * (R"19" + P"#" + #P"{")) + P"---
local command = T("function", P"\\") * (upup + T("function", (R("AZ", "az") + P"@")^1 + any))
-M._rules = {
- {"whitespace", whitespace},
- {"comment", comment},
- {"tex_upup", upup},
- {"delimiter", delimiter},
- {"tex_math", math_},
- {"operator", operator},
- {"function", command},
-}
-
-M._tokenstyles = {
- whitespace = l.STYLE_WHITESPACE,
-
- comment_text = l.STYLE_COMMENT,
- comment_keyword = l.STYLE_COMMENT_KEYWORD,
-
- tex_upup = l.STYLE_ESCAPE,
- delimiter = l.STYLE_DELIMITER,
- tex_math = l.STYLE_STRING,
- operator = l.STYLE_OPERATOR,
-
- ["function"] = l.STYLE_FUNCTION,
-}
+lex:add_rule("whitespace", whitespace)
+lex:add_rule("comment", comment)
+lex:add_rule("tex_upup", upup)
+lex:add_rule("delimiter", delimiter)
+lex:add_rule("tex_math", math_)
+lex:add_rule("operator", operator)
+lex:add_rule("function", command)
-return M
+return lex
diff --git a/vis/themes/custom.lua b/vis/themes/custom.lua
@@ -47,6 +47,28 @@ l.STYLE_IDENTIFIER = ""
l.STYLE_VARIABLE = ""
l.STYLE_ERROR = unknown
+-- Custom token styles for the bundled lexers. Newer vis maps a token named
+-- "foo_bar" to STYLE_FOO_BAR here, replacing the per-lexer _tokenstyles tables.
+l.STYLE_COMMENT_TEXT = l.STYLE_COMMENT
+l.STYLE_NUMLIT = l.STYLE_NUMBER
+l.STYLE_BAD_ESCAPE = l.STYLE_ERROR
+l.STYLE_CHARLIT_DELIM = l.STYLE_NUMBER
+l.STYLE_CHARLIT_TEXT = l.STYLE_NUMBER
+l.STYLE_CHRLIT_DELIM = l.STYLE_NUMBER
+l.STYLE_CHRLIT_TEXT = l.STYLE_NUMBER
+l.STYLE_CHRLIT_ESCAPE = l.STYLE_ESCAPE
+l.STYLE_STRLIT = l.STYLE_STRING
+l.STYLE_STRLIT_DELIM = l.STYLE_STRING
+l.STYLE_STRLIT_TEXT = l.STYLE_STRING
+l.STYLE_STRLIT_ESCAPE = l.STYLE_ESCAPE
+l.STYLE_STRLIT_FORMAT = l.STYLE_STRING_FORMAT
+l.STYLE_PREPROC = l.STYLE_PREPROCESSOR
+l.STYLE_PREPROC_COND = l.STYLE_PREPROCESSOR_CONDITIONAL
+l.STYLE_QUALIFIER = l.STYLE_IDENTIFIER
+l.STYLE_SUFFIX = l.STYLE_LABEL -- TODO: this makes no sense
+l.STYLE_TEX_UPUP = l.STYLE_ESCAPE
+l.STYLE_TEX_MATH = l.STYLE_STRING
+
l.STYLE_LINENUMBER = fg..gray4
l.STYLE_LINENUMBER_CURSOR = fg..gray3
l.STYLE_CURSOR = bg..dorange