22# This scripts reads the data from named-characters and converts it to the
33# format used by the library internally
44
5+ from collections import OrderedDict
6+
57import click
68
79import json
@@ -113,9 +115,9 @@ def compile_tables(data: dict) -> dict:
113115
114116 # operator-to-unicode dictionary entry
115117 operator_to_unicode = {
116- v ["operator-name" ]: v [ "unicode-equivalent" ]
118+ v ["operator-name" ]: v . get ( "unicode-equivalent" , v . get ( "ascii" ))
117119 for k , v in data .items ()
118- if "operator-name" in v and "unicode-equivalent" in v
120+ if "operator-name" in v and ( "unicode-equivalent" in v or "ascii" in v )
119121 }
120122
121123 # Conversion from unicode or ascii to wl dictionary entry.
@@ -147,20 +149,21 @@ def compile_tables(data: dict) -> dict:
147149 [v ["ascii" ] for v in data .values () if "operator-name" in v and "ascii" in v ]
148150 )
149151
150- # unicode-equivalent list entry
151- unicode_operators = sorted (
152- [
153- v ["unicode-equivalent" ]
152+ # Mathics core stores the ascii operator value, Use that to get an operator name
153+ # Operators with ASCII sequences list entry
154+ ascii_operator_to_name = OrderedDict (
155+ {
156+ v ["ascii" ]: rf'\[{ v ["operator-name" ]} ]'
154157 for v in data .values ()
155- if "operator-name" in v and "unicode-equivalent " in v
156- ]
158+ if "operator-name" in v and "ascii " in v
159+ }. items ()
157160 )
158161
159162 # unicode-to-operator dictionary entry
160163 unicode_to_operator = {
161- v [ "unicode-equivalent" ] : v ["operator-name" ]
164+ v . get ( "unicode-equivalent" , v . get ( "ascii" )) : v ["operator-name" ]
162165 for k , v in data .items ()
163- if "operator-name" in v and "unicode-equivalent" in v
166+ if "operator-name" in v
164167 }
165168 # Conversion from WL to the fully qualified names dictionary entry
166169 wl_to_ascii_dict = {
@@ -184,13 +187,14 @@ def compile_tables(data: dict) -> dict:
184187 return {
185188 "aliased-characters" : aliased_characters ,
186189 "ascii-operators" : ascii_operators ,
190+ "ascii-operator-to-name" : ascii_operator_to_name ,
187191 "letterlikes" : letterlikes ,
188192 "named-characters" : named_characters ,
189193 "operator-to-precedence" : operator_to_precedence ,
190194 "operator-to-unicode" : operator_to_unicode ,
191- "unicode-equivalent" : unicode_operators ,
195+ # unicode-operators is irregular, but this is what
196+ # mathics-pygments uses
192197 "unicode-operators" : unicode_to_operator ,
193- "unicode-to-operator" : unicode_to_operator ,
194198 "unicode-to-wl-dict" : unicode_to_wl_dict ,
195199 "unicode-to-wl-re" : unicode_to_wl_re ,
196200 "wl-to-ascii-dict" : wl_to_ascii_dict ,
0 commit comments