Cleanup token abbreviation generation script

This commit is contained in:
Roberto Alsina 2024-08-11 12:06:02 -03:00
parent e8d405fc99
commit 08daabe1c3
8 changed files with 15 additions and 9 deletions

View File

@ -1,3 +1,10 @@
# Script to generate abbreviations for tokens. Parses all lexers
# and styles files to find all token names and generate a unique
# abbreviation for each one. The abbreviations are generated by
# taking the uppercase letters of the token name and converting
# them to lowercase. If the abbreviation is not unique, the script
# will print a warning and exit.
import sys
import string
import glob
@ -40,7 +47,9 @@ for fname in glob.glob("styles/*.xml"):
tokens.add(line)
check_abbrevs()
print("Abbreviations = {")
for k, v in abbrevs.items():
print(f' "{k}" => "{v}",')
print("}")
with open ("src/constants/token_abbrevs.cr", "w") as outf:
outf.write("module Tartrazine\n")
outf.write(" Abbreviations = {\n")
for k in sorted(abbrevs.keys()):
outf.write(f' "{k}" => "{abbrevs[k]}",\n')
outf.write(" }\nend\n")

View File

@ -1,5 +1,4 @@
require "./actions"
require "./constants"
require "./formatter"
require "./rules"
require "./styles"

View File

@ -22,6 +22,7 @@ module Tartrazine
"GenericSubheading" => "gs",
"GenericTraceback" => "gt",
"GenericUnderline" => "gu",
"Highlight" => "hl",
"Keyword" => "k",
"KeywordConstant" => "kc",
"KeywordDeclaration" => "kd",

View File

@ -1,5 +1,4 @@
require "./actions"
require "./constants"
require "./formatter"
require "./rules"
require "./styles"

View File

@ -1,3 +1,4 @@
require "../constants/token_abbrevs.cr"
require "../formatter"
module Tartrazine

View File

@ -1,5 +1,4 @@
require "./actions"
require "./constants"
require "./formatter"
require "./rules"
require "./styles"

View File

@ -1,5 +1,4 @@
require "./actions"
require "./constants"
require "./formatter"
require "./rules"
require "./styles"

View File

@ -1,5 +1,4 @@
require "./actions"
require "./constants"
require "./formatter"
require "./rules"
require "./styles"