Skip to content

Instantly share code, notes, and snippets.

@fionn
Last active July 21, 2024 03:46
Show Gist options
  • Save fionn/7a8675aa8a6d69142cc50124acfac0a1 to your computer and use it in GitHub Desktop.
Save fionn/7a8675aa8a6d69142cc50124acfac0a1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from dataclasses import dataclass
@dataclass
class Map:
code_point: str
character: str
command: str
alt_command: str
character_class: str
math_category: str
requirements: str
comment: str
def main() -> None:
"""Entry point"""
character_maps: list[Map] = []
with open("unimathsymbols.txt") as f:
db = [l.strip().split("^") for l in f if l[0] != "#"]
for entry in db:
character_maps.append((Map(*entry)))
table_entries = []
for m in character_maps:
commands = [c for c in [m.command, m.alt_command] if c and "{" not in c]
for command in commands:
if "{" not in command and m.character not in command:
word = "word = \"\\" + command + "\""
label = "label = \"\\" + f"{command} {m.character}\""
insert_text = f"insertText = \"{m.character}\""
filter_text= "filter_text = \"\\" + command + "\""
table = "{" + ", ".join([word, label, insert_text, filter_text]) + "}"
table_entries.append(table)
table_entries = list(dict.fromkeys(table_entries))
print("local symbols = {")
for t in table_entries:
if "\\\\" in t:
print(" " + t + ",")
print("}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment