|
13 | 13 | from mathics.core.evaluation import Evaluation
|
14 | 14 | from mathics.core.expression import Expression
|
15 | 15 | from mathics.core.symbols import Atom, Symbol, SymbolFullForm, SymbolMakeBoxes
|
16 |
| -from mathics.core.systemsymbols import SymbolStandardForm |
| 16 | +from mathics.core.systemsymbols import SymbolOutputForm, SymbolStandardForm |
17 | 17 | from mathics.eval.makeboxes.formatvalues import do_format
|
18 | 18 | from mathics.eval.makeboxes.precedence import parenthesize
|
19 | 19 |
|
@@ -126,8 +126,21 @@ def int_to_string_shorter_repr(value: int, form: Symbol, max_digits=640):
|
126 | 126 | return String(value_str)
|
127 | 127 |
|
128 | 128 |
|
| 129 | +def eval_makeboxes_outputform(expr, evaluation, form): |
| 130 | + """ |
| 131 | + Build a 2D text representation of the expression. |
| 132 | + """ |
| 133 | + from mathics.builtin.box.layout import InterpretationBox, PaneBox |
| 134 | + from mathics.format.outputform import expression_to_outputform_text |
| 135 | + |
| 136 | + text_outputform = str(expression_to_outputform_text(expr, evaluation, form)) |
| 137 | + elem1 = PaneBox(String(text_outputform)) |
| 138 | + elem2 = Expression(SymbolOutputForm, expr) |
| 139 | + return InterpretationBox(elem1, elem2) |
| 140 | + |
| 141 | + |
129 | 142 | def eval_fullform_makeboxes(
|
130 |
| - self, expr, evaluation: Evaluation, form=SymbolStandardForm |
| 143 | + expr, evaluation: Evaluation, form=SymbolStandardForm |
131 | 144 | ) -> Optional[BaseElement]:
|
132 | 145 | """
|
133 | 146 | This function takes the definitions provided by the evaluation
|
@@ -220,9 +233,27 @@ def format_element(
|
220 | 233 | Applies formats associated to the expression, and then calls Makeboxes
|
221 | 234 | """
|
222 | 235 | evaluation.is_boxing = True
|
| 236 | + while element.get_head() is form: |
| 237 | + element = element.elements[0] |
| 238 | + |
| 239 | + if element.has_form("FullForm", 1): |
| 240 | + return eval_fullform_makeboxes(element.elements[0], evaluation) |
| 241 | + |
| 242 | + # In order to work like in WMA, `format_element` |
| 243 | + # should evaluate `MakeBoxes[element//form, StandardForm]` |
| 244 | + # Then, MakeBoxes[expr_, StandardForm], for any expr, |
| 245 | + # should apply Format[...] rules, and then |
| 246 | + # MakeBoxes[...] rules. These rules should be stored |
| 247 | + # as FormatValues[...] |
| 248 | + # As a first step in that direction, let's mimic this behaviour |
| 249 | + # just for the case of OutputForm: |
| 250 | + if element.has_form("OutputForm", 1): |
| 251 | + return eval_makeboxes_outputform(element.elements[0], evaluation, form) |
| 252 | + |
223 | 253 | expr = do_format(element, evaluation, form)
|
224 | 254 | if expr is None:
|
225 | 255 | return None
|
| 256 | + |
226 | 257 | result = Expression(SymbolMakeBoxes, expr, form)
|
227 | 258 | result_box = result.evaluate(evaluation)
|
228 | 259 | if isinstance(result_box, String):
|
|
0 commit comments