Skip to content

Commit

Permalink
Residual mege changes to get this working again
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Jan 7, 2023
1 parent 45c12c4 commit 632b83a
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions mathics/builtin/makeboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@
Low level Format definitions
"""

from typing import Union

import mpmath

from mathics.builtin.base import Builtin, Predefined
from mathics.builtin.box.layout import RowBox, to_boxes
from mathics.core.atoms import Integer, Real, String
from mathics.core.atoms import Integer, Integer1, Real, String
from mathics.core.attributes import A_HOLD_ALL_COMPLETE, A_READ_PROTECTED
from mathics.core.element import BoxElementMixin
from mathics.core.convert.op import operator_to_ascii, operator_to_unicode
from mathics.core.element import BaseElement, BoxElementMixin
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.number import dps
from mathics.core.symbols import Atom
from mathics.core.systemsymbols import SymbolRowBox
from mathics.core.symbols import Atom, Symbol
from mathics.core.systemsymbols import (
SymbolInputForm,
SymbolNone,
SymbolOutputForm,
SymbolRowBox,
)
from mathics.eval.makeboxes import _boxed_string, format_element, parenthesize


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


# FIXME: op should be a string, so remove the Union.
def make_boxes_infix(
elements, op: Union[String, list], precedence: int, grouping, form: Symbol
):
result = []
for index, element in enumerate(elements):
if index > 0:
if isinstance(op, list):
result.append(op[index - 1])
else:
result.append(op)
parenthesized = False
if grouping == "System`NonAssociative":
parenthesized = True
elif grouping == "System`Left" and index > 0:
parenthesized = True
elif grouping == "System`Right" and index == 0:
parenthesized = True

element_boxes = MakeBoxes(element, form)
element = parenthesize(precedence, element, element_boxes, parenthesized)

result.append(element)
return Expression(SymbolRowBox, ListExpression(*result))


def real_to_s_exp(expr, n):
if expr.is_zero:
s = "0"
Expand Down Expand Up @@ -428,7 +462,7 @@ def eval_infix(
evaluation.message("Infix", "intm", expr)
return self.eval_general(expr, form, evaluation)

grouping = grouping.get_name()
grouping = grouping

## FIXME: this should go into a some formatter.
def format_operator(operator) -> Union[String, BaseElement]:
Expand Down Expand Up @@ -458,7 +492,7 @@ def format_operator(operator) -> Union[String, BaseElement]:
return op
return operator

precedence = prec.value if hasattr(prec, "value") else 0
precedence = precedence.value if hasattr(precedence, "value") else 0
grouping = grouping.get_name()

if isinstance(expr, Atom):
Expand Down

0 comments on commit 632b83a

Please sign in to comment.