Skip to content

Commit

Permalink
Get box operator for scanner from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Dec 8, 2024
1 parent 7f8d8ec commit 8d4aa62
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 43 deletions.
40 changes: 19 additions & 21 deletions mathics_scanner/data/operators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6062,14 +6062,13 @@ SubscriptBox:
WolframLanguageData-corrected: 8
UnicodeCharacters.tr:
UnicodeCharacters-corrected.tr: 775
# N-tokens: {}
# L-tokens: {"\_"}
# O-tokens: {}
# usage: "expr1 \_ expr2"
operator: "\\_"
usage: "\\(x\\\_y\\)"
FullForm:
arity: Binary
affix: Infix
associativity: "unknown"
box-operator: true
meaningful: true
# comments:

Expand Down Expand Up @@ -6313,6 +6312,22 @@ Superset:
meaningful: false
# comments:

SuperscriptBox:
precedence: 590
WolframLanguageData: 21
WolframLanguageData-corrected: 21
UnicodeCharacters.tr:
UnicodeCharacters-corrected.tr: 660
operator: "\\^"
usage: "\\(x\\^_y\\)"
FullForm:
arity: Binary
affix: Infix
associativity: "unknown"
box-operator: true
meaningful: true
# comments:

SupersetEqual:
precedence: 250
WolframLanguageData:
Expand All @@ -6330,23 +6345,6 @@ SupersetEqual:
meaningful: false
# comments:

SupercriptBox:
Precedence-Function: 690
precedence: 590
WolframLanguageData: 21
WolframLanguageData-corrected: 21
UnicodeCharacters.tr:
UnicodeCharacters-corrected.tr: 660
operator: "\\^"
usage: "\\(x\\^y\\)"
FullForm:
arity: Binary
affix: Infix
associativity: right
box-operator: true
meaningful: true
# comments:

TagSet:
Precedence-Function: 670
precedence: 40
Expand Down
32 changes: 10 additions & 22 deletions mathics_scanner/tokeniser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ def init_module():
#
("LeftRowBox", r" \\\( "),
("RightRowBox", r" \\\) "),
# Box Operators which are valid only inside Box delimiters
("InterpretedBox", r" \\\! "),
("SuperscriptBox", r" \\\^ "),
("SubscriptBox", r" \\\_ "),
("OverscriptBox", r" \\\& "),
("UnderscriptBox", r" \\\+ "),
("OtherscriptBox", r" \\\% "),
("FractionBox", r" \\\/ "),
("SqrtBox", r" \\\@ "),
("RadicalBox", r" \\\@ "),
("FormBox", r" \\\` "),
#
# End Box Operators
#
("Information", r"\?\?"),
Expand Down Expand Up @@ -222,11 +210,11 @@ def init_module():
("VerticalSeparator", r" \uF432 "),
]

for table in ("no-meaning-infix-operators",):
for table in ("box-operators", "no-meaning-infix-operators"):
table_info = OPERATOR_DATA[table]
for operator_name, unicode in table_info.items():
# if any([tup[0] == operator_name for tup in tokens]):
# print(f"Please remove {operator_name}")
if any([tup[0] == operator_name for tup in tokens]):
print(f"Please remove {operator_name}")
tokens.append((operator_name, f" {unicode} "))

literal_tokens = {
Expand Down Expand Up @@ -273,17 +261,17 @@ def init_module():
"\\": [
"LeftRowBox",
"RightRowBox",
"FormBox",
"FractionBox",
"InterpretedBox",
"SuperscriptBox",
"SubscriptBox",
"OverunderscriptBox",
"OverscriptBox",
"UnderscriptBox",
"OtherscriptBox",
"FractionBox",
"SqrtBox",
"RadicalBox",
"FormBox",
"RawBackslash",
"SqrtBox",
"SubscriptBox",
"SuperscriptBox",
"UnderscriptBox",
],
"]": ["RawRightBracket"],
"^": ["UpSetDelayed", "UpSet", "Power"],
Expand Down

0 comments on commit 8d4aa62

Please sign in to comment.