Skip to content

Commit

Permalink
Cross check named-characters.yml vs. operators.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Aug 29, 2024
1 parent 85fbbad commit e8e7d47
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 49 deletions.
6 changes: 3 additions & 3 deletions mathics_scanner/data/OperatorTable.csv
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ NumberBase,None,-10,670,760,,1,,-10,{},"{""^^""}",{},"{{""n"", ""^^"", ""digits"
NumberMagnitude,None,-10,670,760,,1,,-10,{},"{""*^""}",{},"{{""number"", ""*^"", ""magnitude""}}","{""number"", ""*^"", ""magnitude""}",number*^magnitude,Binary,Infix,Non,True,"Gives mantissa*base^magnitude, where base^^mantissa=number and magnitude is a decimal number expressed without ^^, `, or ``. Only allowed in a number literal, and only after any ` or ``."
NumberPrecisionPostfix,None,-10,670,760,,1,,-10,{},"{""`""}",{},"{{""number"", ""`""}}","{""number"", ""`""}",number`,Unary,Postfix,Left,True,"Specifies the precision of number to be $MachinePrecision. Any magnitude must come after `."""
NumberPrecision,None,-10,670,760,,1,,-10,{},"{""`""}",{},"{{""number"", ""`"", ""s""}}","{""number"", ""`"", ""s""}",number`s,Binary,Infix,Non,True,"Specifies the precision of number, where s is a positive decimal expressed without using ^^ or `. Any magnitude must come after `."""
NumberAccuracy,None,-10,670,760,,1,,-10,{},"{""``""}",{},"{{""number"", ""``"", ""s""}}","{""number"", ""``"", ""s""}",number``s,Binary,Infix,Non,True,"Specifies the accuracy (in number of digits to the right of decimal) of number, where s is a positive decimal expressed without using ^^ or `. A magnitude must come after ``."
RawBackquote,None,-10,670,760,,1,,-10,{},"{""``""}",{},"{{""number"", ""``"", ""s""}}","{""number"", ""``"", ""s""}",number``s,Binary,Infix,Non,True,"Specifies the accuracy (in number of digits to the right of decimal) of number, where s is a positive decimal expressed without using ^^ or `. A magnitude must come after ``."
ContextPathSeparator,None,-10,670,760,,1,,-10,{},"{""`""}",{},"{{""symb1"", ""`"", ""symb2""}}","{""symb1"", ""`"", ""symb2""}",symb1`symb2,,,Non,True,"Functions as a decimal point: either contextpath1 or contextpath2 may be empty, but not both at the same time."
MessageName,MessageName,1060,750,750,2,2,,850,{},"{""::""}",{},"{{""expr"", ""::"", ""string""}}","{""MessageName"", ""["", ""expr"", "","", """", ""string"", """", ""]""}","MessageName[expr, ""string""]",Binary,Infix,Non,True,
SlotNumber,Slot,1050,740,740,3,3,,840,"{""#""}",{},{},"{{""#"", ""n""}}","{""Slot"", ""["", ""n"", ""]""}",Slot[n],Unary,Prefix,Non,True,
Expand Down Expand Up @@ -74,7 +74,7 @@ RightComposition,RightComposition,850,624,650,13,13,,740,{},"{""/*""}",{},"{{""e
FunctionApplyPrefix,Prefix,840,640,640,,14,730,730,{},"{""@"", """"}",{},"{{""expr1"", ""@"", ""expr2""}, {""expr1"", """", ""expr2""}}","{""expr1"", ""["", ""expr2"", ""]""}",expr1[expr2],Binary,Infix,Right,True,Operator Notations includes usages with invisible unicode characters.
FunctionApplyInfix,Infix,830,630,630,,15,,720,{},"{""~""}",{},"{{""expr1"", ""~"", ""expr2"", ""~"", ""expr3""}}","{""expr2"", ""["", ""expr1"", "","", ""expr3"", ""]""}","expr2[expr1, expr3]",Ternary,Infix,Left,True,"Infix[f[x,y]] will display as x~f~y. Precedence identifies Infix with this operator, and Precedence[Infix]==30 which is almost correct."
Apply,Apply,820,620,626,16,16,,710,{},"{""@@""}",{},"{{""expr1"", ""@@"", ""expr2""}}","{""Apply"", ""["", ""expr1"", "","", ""expr2"", ""]""}","Apply[expr1, expr2]",Binary,Infix,Right,True,
ApplyFirstLevel,Apply,810,620,625,16,16,,710,{},"{""@@@""}",{},"{{""expr1"", ""@@@"", ""expr2""}}","{""Apply"", ""["", ""expr1"", "","", ""expr2"", ""{"", ""1"", ""}"", ""]""}","Apply[expr1, expr2, List[1]]",Binary,Infix,Right,True,
MapApply,MapApply,810,620,625,16,16,,710,{},"{""@@@""}",{},"{{""expr1"", ""@@@"", ""expr2""}}","{""Apply"", ""["", ""expr1"", "","", ""expr2"", ""{"", ""1"", ""}"", ""]""}","MapApply[expr1, expr2, List[1]]",Binary,Infix,Right,True,
Map,Map,800,620,620,16,16,,710,{},"{""/@""}",{},"{{""expr1"", ""/@"", ""expr2""}}","{""Map"", ""["", ""expr1"", "","", ""expr2"", ""]""}","Map[expr1, expr2]",Binary,Infix,Right,True,
MapAll,MapAll,800,620,620,16,16,,710,{},"{""//@""}",{},"{{""expr1"", ""//@"", ""expr2""}}","{""MapAll"", ""["", ""expr1"", "","", ""expr2"", ""]""}","MapAll[expr1, expr2]",Binary,Infix,Right,True,
Factorial,Factorial,790,610,610,17,17,,700,{},"{""!""}",{},"{{""expr"", ""!""}}","{""Factorial"", ""["", ""expr"", ""]""}",Factorial[expr],Unary,Postfix,Left,True,
Expand Down Expand Up @@ -400,4 +400,4 @@ PutAppend,PutAppend,40,30,30,76,76,,180,{},"{"">>>""}",{},"{{""expr"", "">>>"",
CompoundExpression,CompoundExpression,30,10,10,77,77,,170,{},"{"";""}",{},"{{""expr1"", "";"", ""expr2""}}","{""CompoundExpression"", ""["", ""expr1"", "","", ""expr2"", ""]""}","CompoundExpression[expr1, expr2]",Binary,Infix,None,True,
CompoundExpressionNull,CompoundExpression,30,10,10,77,77,,170,{},"{"";""}",{},"{{""expr1"", "";"", ""expr2"", "";""}}","{""CompoundExpression"", ""["", ""expr1"", "","", ""expr2"", ""]""}","CompoundExpression[expr1, expr2, Null]",Unary,Postfix,Left,True,
FormBox,FormBox,20,670,5,78,78,,160,{},"{""\\`""}",{},"{{""expr1"", ""\\`"", ""expr2""}}","{""FormBox"", ""["", ""expr2"", "","", ""expr1"", ""]""}",,Binary,Infix,"Missing[""Unknown""]",True,
ImplicitSequence,Comma,10,670,755,,79,1,1,{},"{"""", "",""}",{},"{{""expr1"", """", ""expr2""}, {""expr1"", "","", ""expr2""}}","{""AngleBracket"", ""["", ""expr"", "","", ""…"", ""]""}","expr1, expr2",Binary,Infix,None,True,Operator Notations includes usages with invisible unicode characters.
ImplicitSequence,Comma,10,670,755,,79,1,1,{},"{"""", "",""}",{},"{{""expr1"", """", ""expr2""}, {""expr1"", "","", ""expr2""}}","{""AngleBracket"", ""["", ""expr"", "","", ""…"", ""]""}","expr1, expr2",Binary,Infix,None,True,Operator Notations includes usages with invisible unicode characters.
10 changes: 8 additions & 2 deletions mathics_scanner/data/named-characters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ AHat:
wl-unicode-name: LATIN SMALL LETTER A WITH CIRCUMFLEX

# See also RawVerticalBar.
Alternative:
Alternatives:
ascii: "|"
has-unicode-inverse: false
is-letter-like: false
operator-name: Alternative
operator-name: Alternatives

Apply:
ascii: "@@"
Expand Down Expand Up @@ -5622,6 +5622,12 @@ MapAll:
is-letter-like: false
operator-name: MapAll

MapApply:
ascii: "@@@"
has-unicode-inverse: false
is-letter-like: false
operator-name: MapApply

Mars:
has-unicode-inverse: false
is-letter-like: false
Expand Down
84 changes: 42 additions & 42 deletions mathics_scanner/data/operators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,6 @@ Apply:
meaningful: true
# comments:

ApplyFirstLevel:
name: Apply
actual-precedence: 810
Precedence-Function: 620
precedence: 625
WolframLanguageData: 16
WolframLanguageData-corrected: 16
UnicodeCharacters.tr:
UnicodeCharacters-corrected.tr: 710
# N-tokens: {}
# L-tokens: {"@@@"}
# O-tokens: {}
# usage: {{"expr1", "@@@", "expr2"}}
# parse: {"Apply", "[", "expr1", ",", "expr2", "{", "1", "}", "]"}
FullForm: Apply[expr1, expr2, List[1]]
arity: Binary
affix: Infix
associativity: Right
meaningful: true
# comments:

Association:
name: Association
actual-precedence: -10
Expand Down Expand Up @@ -3583,6 +3562,27 @@ MapAll:
meaningful: true
# comments:

MapApply:
name: MapApply
actual-precedence: 810
Precedence-Function: 620
precedence: 625
WolframLanguageData: 16
WolframLanguageData-corrected: 16
UnicodeCharacters.tr:
UnicodeCharacters-corrected.tr: 710
# N-tokens: {}
# L-tokens: {"@@@"}
# O-tokens: {}
# usage: {{"expr1", "@@@", "expr2"}}
# parse: {"Apply", "[", "expr1", ",", "expr2", "{", "1", "}", "]"}
FullForm: MapApply[expr1, expr2, List[1]]
arity: Binary
affix: Infix
associativity: Right
meaningful: true
# comments:

MaxLimit:
name: MaxLimit
actual-precedence: 410
Expand Down Expand Up @@ -4985,27 +4985,6 @@ NotVerticalBar:
meaningful: false
# comments:

NumberAccuracy:
name: None
actual-precedence: -10
Precedence-Function: 670
precedence: 760
WolframLanguageData:
WolframLanguageData-corrected: 1
UnicodeCharacters.tr:
UnicodeCharacters-corrected.tr: -10
# N-tokens: {}
# L-tokens: {"``"}
# O-tokens: {}
# usage: {{"number", "``", "s"}}
# parse: {"number", "``", "s"}
FullForm: number``s
arity: Binary
affix: Infix
associativity: Non
meaningful: true
# comments: Specifies the accuracy (in number of digits to the right of decimal) of number, where s is a positive decimal expressed without using ^^ or `. A magnitude must come after ``.

NumberBase:
name: None
actual-precedence: -10
Expand Down Expand Up @@ -5826,6 +5805,27 @@ RadicalBox:
meaningful: true
# comments:

RawBackquote:
name: None
actual-precedence: -10
Precedence-Function: 670
precedence: 760
WolframLanguageData:
WolframLanguageData-corrected: 1
UnicodeCharacters.tr:
UnicodeCharacters-corrected.tr: -10
# N-tokens: {}
# L-tokens: {"``"}
# O-tokens: {}
# usage: {{"number", "``", "s"}}
# parse: {"number", "``", "s"}
FullForm: number``s
arity: Binary
affix: Infix
associativity: Non
meaningful: true
# comments: Specifies the accuracy (in number of digits to the right of decimal) of number, where s is a positive decimal expressed without using ^^ or `. A magnitude must come after ``.

Repeated:
name: Repeated
actual-precedence: 200
Expand Down
22 changes: 20 additions & 2 deletions mathics_scanner/generate/operator_csv_to_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

import csv
import os.path as osp
from pathlib import Path
from typing import Dict

my_dir = osp.dirname(__file__)
csv_file = osp.join(my_dir, "..", "data", "OperatorTable.csv")
DATA_DIR = Path(osp.normpath(osp.dirname(__file__)), "..", "data")
csv_file = DATA_DIR / "OperatorTable.csv"

yaml_fields = (
"name",
Expand Down Expand Up @@ -79,6 +80,14 @@
# if count > 5:
# break

# Commented code for checking character_data versus
# Operator data

# import yaml

# with open(DATA_DIR / "named-characters.yml", "r") as i:
# # Load the YAML data.
# character_data = yaml.load(i, Loader=yaml.FullLoader)

for name in sorted(operators.keys()):
print(f"\n{name}:")
Expand All @@ -105,5 +114,14 @@
field = "Precedence-Function"
elif field == "Precedence-corrected":
field = "precedence"
# Commented code checking character data versus operator data
# character_dict = character_data.get(name)
# if character_dict is None:
# print(f"Woah! do not see {name} in character YAML")
# else:
# character_precedence = character_dict.get("precedence")
# if character_precedence is not None:
# if character_precedence != value:
# print(f"Woah! mismatched character {name} {character_precedence}, {value}")

print(f" {field}: {value}")

0 comments on commit e8e7d47

Please sign in to comment.