Skip to content

Commit c4c1e6d

Browse files
committed
Residual mege changes to get this working again
1 parent 45c12c4 commit c4c1e6d

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

mathics/builtin/layout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
from mathics.builtin.makeboxes import MakeBoxes
1717
from mathics.builtin.options import options_to_rules
1818
from mathics.core.atoms import Integer, Integer1, Real, String
19-
from mathics.core.expression import Evaluation, Expression
2019
from mathics.core.convert.op import operator_to_ascii, operator_to_unicode
2120
from mathics.core.element import BaseElement
21+
from mathics.core.expression import Evaluation, Expression
2222
from mathics.core.list import ListExpression
2323
from mathics.core.symbols import Atom, Symbol
2424
from mathics.core.systemsymbols import (

mathics/builtin/makeboxes.py

+40-6
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@
55
Low level Format definitions
66
"""
77

8+
from typing import Union
9+
810
import mpmath
911

1012
from mathics.builtin.base import Builtin, Predefined
1113
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
1315
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
1518
from mathics.core.expression import Expression
1619
from mathics.core.list import ListExpression
1720
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+
)
2028
from mathics.eval.makeboxes import _boxed_string, format_element, parenthesize
2129

2230

@@ -32,6 +40,32 @@ def int_to_s_exp(expr, n):
3240
return s, exp, nonnegative
3341

3442

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+
3569
def real_to_s_exp(expr, n):
3670
if expr.is_zero:
3771
s = "0"
@@ -428,7 +462,7 @@ def eval_infix(
428462
evaluation.message("Infix", "intm", expr)
429463
return self.eval_general(expr, form, evaluation)
430464

431-
grouping = grouping.get_name()
465+
grouping = grouping
432466

433467
## FIXME: this should go into a some formatter.
434468
def format_operator(operator) -> Union[String, BaseElement]:
@@ -458,7 +492,7 @@ def format_operator(operator) -> Union[String, BaseElement]:
458492
return op
459493
return operator
460494

461-
precedence = prec.value if hasattr(prec, "value") else 0
495+
precedence = precedence.value if hasattr(precedence, "value") else 0
462496
grouping = grouping.get_name()
463497

464498
if isinstance(expr, Atom):

0 commit comments

Comments
 (0)