diff --git a/mathics/core/parser/__init__.py b/mathics/core/parser/__init__.py index cdc9ffc6f..cb8178d4e 100644 --- a/mathics/core/parser/__init__.py +++ b/mathics/core/parser/__init__.py @@ -18,7 +18,7 @@ MathicsMultiLineFeeder, MathicsSingleLineFeeder, ) -from mathics.core.parser.operators import all_operator_names +from mathics.core.parser.operators import all_operator_names, operator_precedences from mathics.core.parser.util import parse, parse_builtin_rule __all__ = [ @@ -29,6 +29,7 @@ "MathicsSingleLineFeeder", "all_operator_names", "is_symbol_name", + "operator_precedences", "parse", "parse_builtin_rule", ] diff --git a/mathics/eval/makeboxes/makeboxes.py b/mathics/eval/makeboxes/makeboxes.py index 8cf465cc5..6c4fb232c 100644 --- a/mathics/eval/makeboxes/makeboxes.py +++ b/mathics/eval/makeboxes/makeboxes.py @@ -142,7 +142,7 @@ def eval_makeboxes_outputform(expr, evaluation, form, **kwargs): Build a 2D representation of the expression using only keyboard characters. """ from mathics.builtin.box.layout import PaneBox - from mathics.format.outputform import expression_to_outputform_text + from mathics.form.outputform import expression_to_outputform_text text_outputform = str( expression_to_outputform_text(expr, evaluation, form, **kwargs) diff --git a/mathics/form/__init__.py b/mathics/form/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/mathics/format/outputform.py b/mathics/form/outputform.py similarity index 97% rename from mathics/format/outputform.py rename to mathics/form/outputform.py index a5a45bc15..2fc82ccee 100644 --- a/mathics/format/outputform.py +++ b/mathics/form/outputform.py @@ -1,12 +1,11 @@ """ -This module builts the string associated to the OutputForm. - -OutputForm produce a pretty-print-like output, suitable for CLI -and text terminals. +This module implements the "OutputForm" textual representation of expressions. +OutputForm is two-dimensional keyboard-character-only output, suitable for CLI +and text terminals. """ -from typing import Callable, Dict, List, Union +from typing import Callable, Dict, Final, List, Union from mathics.core.atoms import ( Integer, @@ -22,7 +21,7 @@ from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression from mathics.core.list import ListExpression -from mathics.core.parser.operators import OPERATOR_DATA +from mathics.core.parser.operators import OPERATOR_DATA, box_operators from mathics.core.symbols import Atom, Symbol, SymbolTimes from mathics.core.systemsymbols import ( SymbolBlank, @@ -46,11 +45,15 @@ SymbolPrefix = Symbol("System`Prefix") -PRECEDENCES = OPERATOR_DATA.get("operator-precedences") -PRECEDENCE_DEFAULT = PRECEDENCES.get("FunctionApply") -PRECEDENCE_PLUS = PRECEDENCES.get("Plus") -PRECEDENCE_TIMES = PRECEDENCES.get("Times") -PRECEDENCE_POWER = PRECEDENCES.get("Power") +PRECEDENCES: Final = OPERATOR_DATA.get("operator-precedences") +PRECEDENCE_DEFAULT: Final = PRECEDENCES.get("FunctionApply") +PRECEDENCE_PLUS: Final = PRECEDENCES.get("Plus") +PRECEDENCE_TIMES: Final = PRECEDENCES.get("Times") +PRECEDENCE_POWER: Final = PRECEDENCES.get("Power") + +# When new mathics-scanner tables are updagted: +# BOX_GROUP_PRECEDENCE: Final = box_operators["BoxGroup"] +BOX_GROUP_PRECEDENCE: Final = PRECEDENCE_DEFAULT EXPR_TO_OUTPUTFORM_TEXT_MAP: Dict[str, Callable] = {} @@ -328,7 +331,8 @@ def infix_expression_to_outputform_text( raise _WrongFormattedExpression group = None - precedence = PRECEDENCE_DEFAULT + precedence = BOX_GROUP_PRECEDENCE + # Processing the first argument: head = expr.get_head() target = expr.elements[0] @@ -606,7 +610,8 @@ def pre_pos_fix_expression_to_outputform_text( raise _WrongFormattedExpression group = None - precedence = PRECEDENCE_DEFAULT + precedence = BOX_GROUP_PRECEDENCE + # Processing the first argument: head = expr.get_head() target = expr.elements[0]