5
5
Low level Format definitions
6
6
"""
7
7
8
+ from typing import Union
9
+
8
10
import mpmath
9
11
10
12
from mathics .builtin .base import Builtin , Predefined
11
13
from mathics .builtin .box .layout import RowBox , to_boxes
12
- from mathics .core .atoms import Integer , Real , String
14
+ from mathics .core .atoms import Integer , Integer1 , Real , String
13
15
from mathics .core .attributes import A_HOLD_ALL_COMPLETE , A_READ_PROTECTED
14
- from mathics .core .element import BoxElementMixin
16
+ from mathics .core .convert .op import operator_to_ascii , operator_to_unicode
17
+ from mathics .core .element import BaseElement , BoxElementMixin
15
18
from mathics .core .expression import Expression
16
19
from mathics .core .list import ListExpression
17
20
from mathics .core .number import dps
18
- from mathics .core .symbols import Atom
19
- from mathics .core .systemsymbols import SymbolRowBox
21
+ from mathics .core .symbols import Atom , Symbol
22
+ from mathics .core .systemsymbols import (
23
+ SymbolInputForm ,
24
+ SymbolNone ,
25
+ SymbolOutputForm ,
26
+ SymbolRowBox ,
27
+ )
20
28
from mathics .eval .makeboxes import _boxed_string , format_element , parenthesize
21
29
22
30
@@ -32,6 +40,32 @@ def int_to_s_exp(expr, n):
32
40
return s , exp , nonnegative
33
41
34
42
43
+ # FIXME: op should be a string, so remove the Union.
44
+ def make_boxes_infix (
45
+ elements , op : Union [String , list ], precedence : int , grouping , form : Symbol
46
+ ):
47
+ result = []
48
+ for index , element in enumerate (elements ):
49
+ if index > 0 :
50
+ if isinstance (op , list ):
51
+ result .append (op [index - 1 ])
52
+ else :
53
+ result .append (op )
54
+ parenthesized = False
55
+ if grouping == "System`NonAssociative" :
56
+ parenthesized = True
57
+ elif grouping == "System`Left" and index > 0 :
58
+ parenthesized = True
59
+ elif grouping == "System`Right" and index == 0 :
60
+ parenthesized = True
61
+
62
+ element_boxes = MakeBoxes (element , form )
63
+ element = parenthesize (precedence , element , element_boxes , parenthesized )
64
+
65
+ result .append (element )
66
+ return Expression (SymbolRowBox , ListExpression (* result ))
67
+
68
+
35
69
def real_to_s_exp (expr , n ):
36
70
if expr .is_zero :
37
71
s = "0"
@@ -428,7 +462,7 @@ def eval_infix(
428
462
evaluation .message ("Infix" , "intm" , expr )
429
463
return self .eval_general (expr , form , evaluation )
430
464
431
- grouping = grouping . get_name ()
465
+ grouping = grouping
432
466
433
467
## FIXME: this should go into a some formatter.
434
468
def format_operator (operator ) -> Union [String , BaseElement ]:
@@ -458,7 +492,7 @@ def format_operator(operator) -> Union[String, BaseElement]:
458
492
return op
459
493
return operator
460
494
461
- precedence = prec .value if hasattr (prec , "value" ) else 0
495
+ precedence = precedence .value if hasattr (precedence , "value" ) else 0
462
496
grouping = grouping .get_name ()
463
497
464
498
if isinstance (expr , Atom ):
0 commit comments