Fix constants for non-base16 themes

This commit is contained in:
Roberto Alsina 2024-08-09 14:17:24 -03:00
parent f98f44365f
commit d1762f477a
2 changed files with 115 additions and 86 deletions

View File

@ -1,24 +1,46 @@
import sys
import string
import glob
# Run it as grep token lexers/* | python scripts/token_abbrevs.py
tokens = {"Highlight"}
abbrevs = {"Highlight": "hl"}
def abbr(line):
return "".join(c for c in line if c in string.ascii_uppercase).lower()
abbrevs = {}
tokens = {"Highlight"}
for line in sys.stdin:
if "<token" not in line:
continue
line = line.strip()
line = line.split('<token ',1)[-1]
line = line.split('"')[1]
abbrevs[line] = abbr(line)
tokens.add(line)
def check_abbrevs():
if len(abbrevs) != len(tokens):
print("Warning: Abbreviations are not unique")
print(len(abbrevs), len(tokens))
sys.exit(1)
print("Abbreviations: {")
# Processes all files in lexers looking for token names
for fname in glob.glob("lexers/*.xml"):
with open(fname) as f:
for line in f:
if "<token" not in line:
continue
line = line.strip()
line = line.split('<token ',1)[-1]
line = line.split('"')[1]
abbrevs[line] = abbr(line)
tokens.add(line)
check_abbrevs()
# Processes all files in styles looking for token names too
for fname in glob.glob("styles/*.xml"):
with open(fname) as f:
for line in f:
if "<entry" not in line:
continue
line = line.strip()
line = line.split('type=',1)[-1]
line = line.split('"')[1]
abbrevs[line] = abbr(line)
tokens.add(line)
check_abbrevs()
print("Abbreviations = {")
for k, v in abbrevs.items():
print(f' "{k}" => "{v}",')
print("}")

View File

@ -1,93 +1,100 @@
module Tartrazine
Abbreviations = {
"Background" => "b",
"Highlight" => "h",
"Highlight" => "hl",
"NameTag" => "nt",
"NameBuiltin" => "nb",
"NameVariable" => "nv",
"Comment" => "c",
"Keyword" => "k",
"Error" => "e",
"Text" => "t",
"CommentSingle" => "cs",
"CommentMultiline" => "cm",
"CommentSpecial" => "cs",
"NameVariable" => "nv",
"Keyword" => "k",
"NameFunction" => "nf",
"Punctuation" => "p",
"LiteralString" => "ls",
"LiteralStringSymbol" => "lss",
"Operator" => "o",
"LiteralNumberInteger" => "lni",
"NameBuiltin" => "nb",
"Name" => "n",
"OperatorWord" => "ow",
"LiteralStringSingle" => "lss",
"Literal" => "l",
"NameClass" => "nc",
"CommentMultiline" => "cm",
"LiteralStringRegex" => "lsr",
"KeywordDeclaration" => "kd",
"KeywordConstant" => "kc",
"NameOther" => "no",
"LiteralNumberFloat" => "lnf",
"LiteralNumberHex" => "lnh",
"LiteralStringDouble" => "lsd",
"KeywordType" => "kt",
"NameNamespace" => "nn",
"NameAttribute" => "na",
"KeywordReserved" => "kr",
"CommentPreproc" => "cp",
"KeywordNamespace" => "kn",
"NameConstant" => "nc",
"NameLabel" => "nl",
"LiteralString" => "ls",
"LiteralStringChar" => "lsc",
"TextWhitespace" => "tw",
"LiteralStringEscape" => "lse",
"LiteralNumber" => "ln",
"Other" => "o",
"LiteralStringBoolean" => "lsb",
"NameProperty" => "np",
"Comment" => "c",
"NameTag" => "nt",
"LiteralStringOther" => "lso",
"NameVariableGlobal" => "nvg",
"NameBuiltinPseudo" => "nbp",
"LiteralNumberFloat" => "lnf",
"LiteralStringChar" => "lsc",
"LiteralOther" => "lo",
"NameFunction" => "nf",
"LiteralNumberBin" => "lnb",
"LiteralNumberOct" => "lno",
"LiteralNumberHex" => "lnh",
"Punctuation" => "p",
"CommentPreproc" => "cp",
"NameConstant" => "nc",
"NameVariableGlobal" => "nvg",
"LiteralStringOther" => "lso",
"LiteralStringHeredoc" => "lsh",
"LiteralStringInterpol" => "lsi",
"LiteralStringEscape" => "lse",
"OperatorWord" => "ow",
"KeywordDeclaration" => "kd",
"KeywordNamespace" => "kn",
"NamePseudo" => "np",
"NameAttribute" => "na",
"Name" => "n",
"NameClass" => "nc",
"NameEntity" => "ne",
"LiteralStringDouble" => "lsd",
"LiteralStringSingle" => "lss",
"TextWhitespace" => "tw",
"LiteralStringDoc" => "lsd",
"KeywordReserved" => "kr",
"KeywordConstant" => "kc",
"KeywordPseudo" => "kp",
"KeywordType" => "kt",
"NameDecorator" => "nd",
"NameLabel" => "nl",
"NameNamespace" => "nn",
"NameOperator" => "no",
"CommentPreprocFile" => "cpf",
"LiteralStringAffix" => "lsa",
"LiteralStringDelimiter" => "lsd",
"LiteralNumberOct" => "lno",
"Error" => "e",
"Generic" => "g",
"LiteralNumberIntegerLong" => "lnil",
"NameDecorator" => "nd",
"LiteralStringInterpol" => "lsi",
"NameOther" => "no",
"LiteralStringBacktick" => "lsb",
"GenericPrompt" => "gp",
"GenericOutput" => "go",
"LiteralStringName" => "lsn",
"LiteralStringHeredoc" => "lsh",
"LiteralStringSymbol" => "lss",
"NameVariableInstance" => "nvi",
"LiteralOther" => "lo",
"NameVariableClass" => "nvc",
"NameOperator" => "no",
"None" => "n",
"LiteralStringDoc" => "lsd",
"NameException" => "ne",
"LiteralStringRegex" => "lsr",
"NameProperty" => "np",
"Other" => "o",
"Generic" => "g",
"GenericEmph" => "ge",
"GenericError" => "ge",
"LiteralNumberIntegerLong" => "lnil",
"GenericSubheading" => "gs",
"GenericHeading" => "gh",
"TextPunctuation" => "tp",
"CommentHashbang" => "ch",
"NameVariableAnonymous" => "nva",
"NameBuiltinPseudo" => "nbp",
"Literal" => "l",
"LiteralStringDelimiter" => "lsd",
"NameException" => "ne",
"NameFunctionMagic" => "nfm",
"NameVariableMagic" => "nvm",
"NameVariableInstance" => "nvi",
"LiteralDate" => "ld",
"GenericStrong" => "gs",
"GenericDeleted" => "gd",
"GenericInserted" => "gi",
"GenericHeading" => "gh",
"NameEntity" => "ne",
"NamePseudo" => "np",
"CommentHashbang" => "ch",
"TextPunctuation" => "tp",
"NameVariableAnonymous" => "nva",
"NameVariableMagic" => "nvm",
"NameFunctionMagic" => "nfm",
"GenericEmph" => "ge",
"GenericUnderline" => "gu",
"LiteralStringAtom" => "lsa",
"LiteralDate" => "ld",
"GenericError" => "ge",
"TextSymbol" => "ts",
"LiteralStringName" => "lsn",
"NameKeyword" => "nk",
"GenericInserted" => "gi",
"None" => "n",
"NameVariableClass" => "nvc",
"LiteralStringBoolean" => "lsb",
"LiteralStringAtom" => "lsa",
"TextSymbol" => "ts",
"GenericPrompt" => "gp",
"GenericOutput" => "go",
"Background" => "b",
"CodeLine" => "cl",
"LineTableTD" => "lttd",
"LineTable" => "lt",
"LineHighlight" => "lh",
"LineNumbersTable" => "lnt",
"LineNumbers" => "ln",
"GenericTraceback" => "gt",
}
end