Skip to content

Commit 8c62b5e

Browse files
committed
Include ASCII operators in tables
Correct DifferentialD unicode - it was correct in master. Note: \U0001D451 != \u1d451
1 parent 7d949ef commit 8c62b5e

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

mathics_scanner/generate/build_tables.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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+
57
import click
68

79
import 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,

mathics_scanner/tokeniser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
("ConjugateTranspose", r" \uf3c9 "),
149149
("HermitianConjugate", r" \uf3ce "),
150150
("Integral", r" \u222b "),
151-
("DifferentialD", r" \u1d451 | \uf74c"),
151+
("DifferentialD", r" \U0001D451 | \uf74c"),
152152
("Del", r" \u2207 "),
153153
# uf520 is Wolfram custom, 25ab is standard unicode
154154
("Square", r" \uf520 | \u25ab"),

test/test_ascii.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from mathics_scanner.load import (
4+
load_mathics_character_yaml,
5+
load_mathics_character_json,
6+
)
7+
8+
yaml_data = load_mathics_character_yaml()
9+
json_data = load_mathics_character_json()
10+
11+
12+
def test_ascii():
13+
ascii_operator_to_name = json_data["ascii-operator-to-name"]
14+
ascii_operators = json_data["ascii-operators"]
15+
operator_keys = frozenset(ascii_operator_to_name.keys())
16+
# operator_to_precedence = json_data["operator-to-precedence"]
17+
for chars in json_data["ascii-operators"]:
18+
assert chars in ascii_operators
19+
assert chars in operator_keys
20+
# assert chars in unicode_to_operator.keys()
21+
name = ascii_operator_to_name.get(chars)
22+
assert name is not None
23+
assert name.startswith(r"\[")
24+
assert name.endswith(r"]")
25+
raw_name = name[len(r"\[") : -len(r"]")]
26+
assert raw_name in yaml_data

0 commit comments

Comments
 (0)