@@ -179,18 +179,50 @@ def int_to_string_shorter_repr(value: int, form: Symbol, max_digits=640):
179179 return String (value_str )
180180
181181
182- def eval_fullform_makeboxes (
183- self , expr , evaluation : Evaluation , form = SymbolStandardForm
184- ) -> Optional [BaseElement ]:
182+ def eval_fullform_makeboxes (expr , evaluation ) -> Optional [BaseElement ]:
185183 """
186184 This function takes the definitions provided by the evaluation
187185 object, and produces a boxed form for expr.
188186
189187 Basically: MakeBoxes[expr // FullForm]
190188 """
189+ from mathics .builtin .box .layout import RowBox
190+
191+ comma = String (", " )
191192 # This is going to be reimplemented.
192- expr = Expression (SymbolFullForm , expr )
193- return Expression (SymbolMakeBoxes , expr , form ).evaluate (evaluation )
193+ if isinstance (expr , Symbol ):
194+ return String (evaluation .definitions .shorten_name (expr .name ))
195+ if isinstance (expr , (Integer , Real , String )):
196+ return expr .make_boxes ("System`FullForm" )
197+ if isinstance (expr , Rational ):
198+ return eval_fullform_makeboxes (
199+ Expression (SymbolRational , expr .numerator (), expr .denominator ()), evaluation
200+ )
201+ if isinstance (expr , Complex ):
202+ return eval_fullform_makeboxes (
203+ Expression (SymbolComplex , expr .real , expr .imag ), evaluation
204+ )
205+ if isinstance (expr , Atom ):
206+ return String (str (expr ))
207+ if isinstance (expr , Expression ):
208+ head = expr .get_head ()
209+ if head is SymbolList :
210+ start_str , end_str , comma = String ("{" ), String ("}" ), String ("," )
211+ elems_list = [start_str ]
212+ else :
213+ start_str , end_str , comma = String ("[" ), String ("]" ), String (", " )
214+ elems_list = [eval_fullform_makeboxes (head , evaluation ), start_str ]
215+ elements = expr .elements
216+ if elements :
217+ first_elem , * rest_elems = elements
218+ elems_list .append (eval_fullform_makeboxes (first_elem , evaluation ))
219+ for elem in rest_elems :
220+ elems_list .append (comma )
221+ elems_list .append (eval_fullform_makeboxes (elem , evaluation ))
222+ elems_list .append (end_str )
223+ return RowBox (* elems_list )
224+ if hasattr (expr , "to_expression" ):
225+ return eval_fullform_makeboxes (expr .to_expression (), evaluation )
194226
195227
196228def eval_makeboxes (
@@ -206,7 +238,7 @@ def eval_makeboxes(
206238 return Expression (SymbolMakeBoxes , expr , form ).evaluate (evaluation )
207239
208240
209- def make_output_form (expr , evaluation , form ):
241+ def makeboxes_outputform (expr , evaluation , form ):
210242 """
211243 Build a 2D text representation of the expression.
212244 """
@@ -225,11 +257,23 @@ def format_element(
225257 """
226258 Applies formats associated to the expression, and then calls Makeboxes
227259 """
260+ # Strip repeated form
228261 while element .get_head () is form :
229262 element = element .elements [0 ]
230263
264+ if element .has_form ("FullForm" , 1 ):
265+ return eval_fullform_makeboxes (element .elements [0 ], evaluation )
266+
267+ # In order to work like in WMA, `format_element`
268+ # should evaluate `MakeBoxes[element//form, StandardForm]`
269+ # Then, MakeBoxes[expr_, StandardForm], for any expr,
270+ # should apply Format[...] rules, and then
271+ # MakeBoxes[...] rules. These rules should be stored
272+ # as FormatValues[...]
273+ # As a first step in that direction, let's mimic this behaviour
274+ # just for the case of OutputForm:
231275 if element .has_form ("OutputForm" , 1 ):
232- return make_output_form (element .elements [0 ], evaluation , form )
276+ return makeboxes_output_form (element .elements [0 ], evaluation , form )
233277
234278 expr = do_format (element , evaluation , form )
235279 if expr is None :
0 commit comments