From e8e7d47b0afc7bd779f2d542783eb500b1d8c76d Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 29 Aug 2024 11:53:28 -0400 Subject: [PATCH] Cross check named-characters.yml vs. operators.yml --- mathics_scanner/data/OperatorTable.csv | 6 +- mathics_scanner/data/named-characters.yml | 10 ++- mathics_scanner/data/operators.yml | 84 +++++++++---------- .../generate/operator_csv_to_yml.py | 22 ++++- 4 files changed, 73 insertions(+), 49 deletions(-) diff --git a/mathics_scanner/data/OperatorTable.csv b/mathics_scanner/data/OperatorTable.csv index abb5c27..b8d7d03 100644 --- a/mathics_scanner/data/OperatorTable.csv +++ b/mathics_scanner/data/OperatorTable.csv @@ -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, @@ -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, @@ -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. diff --git a/mathics_scanner/data/named-characters.yml b/mathics_scanner/data/named-characters.yml index 162780f..17fda43 100644 --- a/mathics_scanner/data/named-characters.yml +++ b/mathics_scanner/data/named-characters.yml @@ -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: "@@" @@ -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 diff --git a/mathics_scanner/data/operators.yml b/mathics_scanner/data/operators.yml index ab508b6..5ae920b 100644 --- a/mathics_scanner/data/operators.yml +++ b/mathics_scanner/data/operators.yml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/mathics_scanner/generate/operator_csv_to_yml.py b/mathics_scanner/generate/operator_csv_to_yml.py index 554e430..1c69938 100755 --- a/mathics_scanner/generate/operator_csv_to_yml.py +++ b/mathics_scanner/generate/operator_csv_to_yml.py @@ -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", @@ -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}:") @@ -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}")