diff --git a/scripts/token_abbrevs.py b/scripts/token_abbrevs.py index bfb54d9..30f2071 100644 --- a/scripts/token_abbrevs.py +++ b/scripts/token_abbrevs.py @@ -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") \ No newline at end of file diff --git a/src/actions.cr b/src/actions.cr index f35f225..4ed4008 100644 --- a/src/actions.cr +++ b/src/actions.cr @@ -1,5 +1,4 @@ require "./actions" -require "./constants" require "./formatter" require "./rules" require "./styles" diff --git a/src/constants.cr b/src/constants/token_abbrevs.cr similarity index 98% rename from src/constants.cr rename to src/constants/token_abbrevs.cr index ee4009a..98c8eb0 100644 --- a/src/constants.cr +++ b/src/constants/token_abbrevs.cr @@ -22,6 +22,7 @@ module Tartrazine "GenericSubheading" => "gs", "GenericTraceback" => "gt", "GenericUnderline" => "gu", + "Highlight" => "hl", "Keyword" => "k", "KeywordConstant" => "kc", "KeywordDeclaration" => "kd", diff --git a/src/formatter.cr b/src/formatter.cr index 418c4c9..8336c00 100644 --- a/src/formatter.cr +++ b/src/formatter.cr @@ -1,5 +1,4 @@ require "./actions" -require "./constants" require "./formatter" require "./rules" require "./styles" diff --git a/src/formatters/html.cr b/src/formatters/html.cr index 2aacf69..40af672 100644 --- a/src/formatters/html.cr +++ b/src/formatters/html.cr @@ -1,3 +1,4 @@ +require "../constants/token_abbrevs.cr" require "../formatter" module Tartrazine diff --git a/src/rules.cr b/src/rules.cr index d84e85b..4259505 100644 --- a/src/rules.cr +++ b/src/rules.cr @@ -1,5 +1,4 @@ require "./actions" -require "./constants" require "./formatter" require "./rules" require "./styles" diff --git a/src/styles.cr b/src/styles.cr index 1822377..b3d6f1c 100644 --- a/src/styles.cr +++ b/src/styles.cr @@ -1,5 +1,4 @@ require "./actions" -require "./constants" require "./formatter" require "./rules" require "./styles" diff --git a/src/tartrazine.cr b/src/tartrazine.cr index 8665f0f..67d33f9 100644 --- a/src/tartrazine.cr +++ b/src/tartrazine.cr @@ -1,5 +1,4 @@ require "./actions" -require "./constants" require "./formatter" require "./rules" require "./styles"