Skip to content

Commit 570a852

Browse files
committed
Add prefix operators, revise tables
named-characgters.yml: Add DifferentialD and Integrate even though we don't have a full set of prefix operators. Add "ascii" entry for DifferentialD Add admin-tools script to build all tables.
1 parent 9979ed2 commit 570a852

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

admin-tools/make-tables.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Create a complete set of tables.
3+
# This just runs build_tables.py in this distribution
4+
bs=${BASH_SOURCE[0]}
5+
mydir=$(dirname $bs)
6+
PYTHON=${PYTHON:-python}
7+
8+
cd $mydir/../mathics_scanner/data
9+
$PYTHON ../generate/build_tables.py -o characters.json

mathics_scanner/data/named-characters.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ CapitalDelta:
653653

654654
CapitalDifferentialD:
655655
amslatex: "\\CapitalDifferentialD"
656+
ascii: "d"
656657
esc-alias: DD
657658
has-unicode-inverse: true
658659
is-letter-like: true
@@ -1787,6 +1788,8 @@ DifferentialD:
17871788
has-unicode-inverse: true
17881789
# This can't be letter-like because it is used in derivatives as a function
17891790
is-letter-like: false
1791+
# TODO: This should be a prefix operator
1792+
operator-name: DifferentialD
17901793
unicode-equivalent: "\U0001D451"
17911794
unicode-equivalent-name: MATHEMATICAL ITALIC SMALL D
17921795
wl-unicode: "\uF74C"
@@ -5026,6 +5029,7 @@ Integral:
50265029
esc-alias: int
50275030
has-unicode-inverse: false
50285031
is-letter-like: false
5032+
# TODO: This should be a prefix operator
50295033
operator-name: Integral
50305034
unicode-equivalent: "\u222B"
50315035
unicode-equivalent-name: INTEGRAL

mathics_scanner/generate/build_tables.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ def compile_tables(data: dict) -> dict:
118118
if "operator-name" in v and ("unicode-equivalent" in v or "ascii" in v)
119119
}
120120

121+
# operator-to-ascii or character symbol name
122+
operator_to_ascii = {
123+
v["operator-name"]: v.get("ascii", rf'\[{v["operator-name"]}]')
124+
for k, v in data.items()
125+
if "operator-name" in v and ("unicode-equivalent" in v or "ascii" in v)
126+
}
127+
121128
# Conversion from unicode or ascii to wl dictionary entry.
122129
# We filter the dictionary after it's first created to redundant entries
123130
unicode_to_wl_dict = {
@@ -145,7 +152,8 @@ def compile_tables(data: dict) -> dict:
145152
operator_names = sorted([k for k, v in data.items() if "operator-name" in v])
146153

147154
ascii_operators = []
148-
ascii_operator_to_name = {}
155+
ascii_operator_to_character_symbol = {}
156+
ascii_operator_to_symbol = {}
149157
ascii_operator_to_unicode = {}
150158
ascii_operator_to_wl_unicode = {}
151159

@@ -155,7 +163,8 @@ def compile_tables(data: dict) -> dict:
155163
ascii_name = v.get("ascii", None)
156164
if ascii_name is not None:
157165
ascii_operators.append(v["ascii"])
158-
ascii_operator_to_name[ascii_name] = rf'\[{v["operator-name"]}]'
166+
ascii_operator_to_character_symbol[ascii_name] = rf'\[{v["operator-name"]}]'
167+
ascii_operator_to_symbol[ascii_name] = v["operator-name"]
159168
# Mathics core stores the ascii operator value, Use that to get standard unicode
160169
# symbol, and failing use the ASCII sequence.
161170
ascii_operator_to_unicode[ascii_name] = v.get(
@@ -193,13 +202,15 @@ def compile_tables(data: dict) -> dict:
193202
return {
194203
"aliased-characters": aliased_characters,
195204
"ascii-operators": ascii_operators,
196-
"ascii-operator-to-name": ascii_operator_to_name,
205+
"ascii-operator-to-symbol": ascii_operator_to_symbol,
206+
"ascii-operator-to-character-symbol": ascii_operator_to_character_symbol,
197207
"ascii-operator-to-unicode": ascii_operator_to_unicode,
198208
"ascii-operator-to-wl-unicode": ascii_operator_to_wl_unicode,
199209
"letterlikes": letterlikes,
200210
"named-characters": named_characters,
201211
"operator-names": operator_names,
202212
"operator-to-precedence": operator_to_precedence,
213+
"operator-to-ascii": operator_to_ascii,
203214
"operator-to-unicode": operator_to_unicode,
204215
# unicode-operators is irregular, but this is what
205216
# mathics-pygments uses
@@ -219,12 +230,14 @@ def compile_tables(data: dict) -> dict:
219230
ALL_FIELDS = [
220231
"aliased-characters",
221232
"ascii-operators",
222-
"ascii-operator-to-name",
233+
"ascii-operator-to-character-symbol",
234+
"ascii-operator-to-symbol",
223235
"ascii-operator-to-unicode",
224236
"ascii-operator-to-wl-unicode",
225237
"letterlikes",
226238
"named-characters",
227239
"operator-names",
240+
"operator-to-ascii",
228241
"operator-to-precedence",
229242
"operator-to-unicode",
230243
"unicode-operators",

test/test_ascii.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@
1010

1111

1212
def test_ascii():
13-
ascii_operator_to_name = json_data["ascii-operator-to-name"]
13+
ascii_operator_to_character_symbol = json_data["ascii-operator-to-character-symbol"]
14+
ascii_operator_to_symbol = json_data["ascii-operator-to-symbol"]
1415
ascii_operators = json_data["ascii-operators"]
15-
operator_keys = frozenset(ascii_operator_to_name.keys())
16+
operator_keys = frozenset(ascii_operator_to_symbol.keys())
1617
# operator_to_precedence = json_data["operator-to-precedence"]
1718
for chars in json_data["ascii-operators"]:
1819
assert chars in ascii_operators
1920
assert chars in operator_keys
2021
# 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
22+
char_symbol = ascii_operator_to_character_symbol.get(chars)
23+
assert char_symbol is not None
24+
assert char_symbol.startswith(r"\[")
25+
assert char_symbol.endswith(r"]")
26+
raw_char_symbol = char_symbol[len(r"\[") : -len(r"]")]
27+
assert raw_char_symbol in yaml_data
28+
assert raw_char_symbol in ascii_operator_to_symbol.values()

0 commit comments

Comments
 (0)