Skip to content

Commit

Permalink
fix MakeBoxes[PrecedenceForm[...],form] (#808)
Browse files Browse the repository at this point in the history
This came up during the #766 rebase: `PrecisionForm` didn't have a
`Builtin` symbol, and the `Makeboxes` rule didn't take into account the
`form` parameter. This PR fixes these two issues.
  • Loading branch information
mmatera committed Mar 6, 2023
1 parent 182679a commit 008141b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions SYMBOLS_MANIFEST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ System`PowerMod
System`PreDecrement
System`PreIncrement
System`Precedence
System`PrecedenceForm
System`Precision
System`Prefix
System`Prepend
Expand Down
13 changes: 13 additions & 0 deletions mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ def eval(self, expr, evaluation) -> Real:
return Real(precedence)


class PrecedenceForm(Builtin):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/PrecedenceForm.html</url>
<dl>
<dt>'PrecedenceForm'[$expr$, $prec$]
<dd> format $expr$ parenthesized as it would be if it contained an operator of precedence $prec$.
</dl>
"""

summary_text = "parenthesize with a precedence"


class Prefix(BinaryOperator):
"""
<url>:WMA link:https://reference.wolfram.com/language/ref/Prefix.html</url>
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/makeboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ def eval_general(self, expr, f, evaluation):
result.append(to_boxes(String(right), evaluation))
return RowBox(*result)

def eval_outerprecedenceform(self, expr, precedence, evaluation):
def eval_outerprecedenceform(self, expr, precedence, form, evaluation):
"""MakeBoxes[PrecedenceForm[expr_, precedence_],
StandardForm|TraditionalForm|OutputForm|InputForm]"""
form:StandardForm|TraditionalForm|OutputForm|InputForm]"""

py_precedence = precedence.get_int_value()
boxes = MakeBoxes(expr)
boxes = MakeBoxes(expr, form)
return parenthesize(py_precedence, expr, boxes, True)

def eval_postprefix(self, p, expr, h, precedence, form, evaluation):
Expand Down

0 comments on commit 008141b

Please sign in to comment.