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,15 +1,23 @@
import sys import sys
import string import string
import glob
# Run it as grep token lexers/* | python scripts/token_abbrevs.py tokens = {"Highlight"}
abbrevs = {"Highlight": "hl"}
def abbr(line): def abbr(line):
return "".join(c for c in line if c in string.ascii_uppercase).lower() return "".join(c for c in line if c in string.ascii_uppercase).lower()
abbrevs = {} def check_abbrevs():
tokens = {"Highlight"} if len(abbrevs) != len(tokens):
for line in sys.stdin: print("Warning: Abbreviations are not unique")
print(len(abbrevs), len(tokens))
sys.exit(1)
# 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: if "<token" not in line:
continue continue
line = line.strip() line = line.strip()
@ -17,8 +25,22 @@ for line in sys.stdin:
line = line.split('"')[1] line = line.split('"')[1]
abbrevs[line] = abbr(line) abbrevs[line] = abbr(line)
tokens.add(line) tokens.add(line)
check_abbrevs()
print("Abbreviations: {") # 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(): for k, v in abbrevs.items():
print(f' "{k}" => "{v}",') print(f' "{k}" => "{v}",')
print("}") print("}")

View File

@ -1,93 +1,100 @@
module Tartrazine module Tartrazine
Abbreviations = { Abbreviations = {
"Background" => "b", "Highlight" => "hl",
"Highlight" => "h", "NameTag" => "nt",
"NameBuiltin" => "nb",
"NameVariable" => "nv",
"Comment" => "c",
"Keyword" => "k",
"Error" => "e",
"Text" => "t", "Text" => "t",
"CommentSingle" => "cs", "CommentSingle" => "cs",
"CommentMultiline" => "cm",
"CommentSpecial" => "cs", "CommentSpecial" => "cs",
"NameVariable" => "nv", "LiteralString" => "ls",
"Keyword" => "k", "LiteralStringSymbol" => "lss",
"NameFunction" => "nf",
"Punctuation" => "p",
"Operator" => "o", "Operator" => "o",
"LiteralNumberInteger" => "lni", "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", "LiteralNumber" => "ln",
"Other" => "o", "LiteralNumberFloat" => "lnf",
"LiteralStringBoolean" => "lsb", "LiteralStringChar" => "lsc",
"NameProperty" => "np", "LiteralOther" => "lo",
"Comment" => "c", "NameFunction" => "nf",
"NameTag" => "nt",
"LiteralStringOther" => "lso",
"NameVariableGlobal" => "nvg",
"NameBuiltinPseudo" => "nbp",
"LiteralNumberBin" => "lnb", "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", "KeywordPseudo" => "kp",
"KeywordType" => "kt",
"NameDecorator" => "nd",
"NameLabel" => "nl",
"NameNamespace" => "nn",
"NameOperator" => "no",
"CommentPreprocFile" => "cpf", "CommentPreprocFile" => "cpf",
"LiteralStringAffix" => "lsa", "LiteralStringAffix" => "lsa",
"LiteralStringDelimiter" => "lsd", "NameOther" => "no",
"LiteralNumberOct" => "lno",
"Error" => "e",
"Generic" => "g",
"LiteralNumberIntegerLong" => "lnil",
"NameDecorator" => "nd",
"LiteralStringInterpol" => "lsi",
"LiteralStringBacktick" => "lsb", "LiteralStringBacktick" => "lsb",
"GenericPrompt" => "gp", "LiteralStringRegex" => "lsr",
"GenericOutput" => "go", "NameProperty" => "np",
"LiteralStringName" => "lsn", "Other" => "o",
"LiteralStringHeredoc" => "lsh", "Generic" => "g",
"LiteralStringSymbol" => "lss", "GenericEmph" => "ge",
"NameVariableInstance" => "nvi", "GenericError" => "ge",
"LiteralOther" => "lo", "LiteralNumberIntegerLong" => "lnil",
"NameVariableClass" => "nvc",
"NameOperator" => "no",
"None" => "n",
"LiteralStringDoc" => "lsd",
"NameException" => "ne",
"GenericSubheading" => "gs", "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", "GenericStrong" => "gs",
"GenericDeleted" => "gd", "GenericDeleted" => "gd",
"GenericInserted" => "gi",
"GenericHeading" => "gh",
"NameEntity" => "ne",
"NamePseudo" => "np",
"CommentHashbang" => "ch",
"TextPunctuation" => "tp",
"NameVariableAnonymous" => "nva",
"NameVariableMagic" => "nvm",
"NameFunctionMagic" => "nfm",
"GenericEmph" => "ge",
"GenericUnderline" => "gu", "GenericUnderline" => "gu",
"LiteralStringAtom" => "lsa", "LiteralStringName" => "lsn",
"LiteralDate" => "ld",
"GenericError" => "ge",
"TextSymbol" => "ts",
"NameKeyword" => "nk", "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 end