-
-
Notifications
You must be signed in to change notification settings - Fork 65
Add FormBox #1641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FormBox #1641
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,13 +11,19 @@ | |
|
|
||
| from mathics.builtin.box.layout import GridBox, PaneBox, RowBox, to_boxes | ||
| from mathics.builtin.makeboxes import MakeBoxes | ||
| from mathics.core.atoms import Real, String | ||
| from mathics.core.atoms import Integer, Real, String | ||
| from mathics.core.builtin import Builtin, Operator, PostfixOperator, PrefixOperator | ||
| from mathics.core.expression import Evaluation, Expression | ||
| from mathics.core.list import ListExpression | ||
| from mathics.core.systemsymbols import SymbolMakeBoxes, SymbolSubscriptBox | ||
| from mathics.core.symbols import Symbol | ||
| from mathics.core.systemsymbols import ( | ||
| SymbolMakeBoxes, | ||
| SymbolPostfix, | ||
| SymbolPrefix, | ||
| SymbolSubscriptBox, | ||
| ) | ||
| from mathics.eval.lists import list_boxes | ||
| from mathics.format.box import format_element | ||
| from mathics.format.box import eval_infix, eval_postprefix, format_element, parenthesize | ||
|
|
||
|
|
||
| class Center(Builtin): | ||
|
|
@@ -172,8 +178,20 @@ class Infix(Builtin): | |
| = a + b - c | ||
| """ | ||
|
|
||
| rules = { | ||
| ( | ||
| "MakeBoxes[Infix[head_[elements___]], " | ||
| " f:StandardForm|TraditionalForm]" | ||
| ): ('MakeBoxes[Infix[head[elements], StringForm["~`1`~", head]], f]'), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is that "~" again. Sigh.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mmatera This PR does a lot more than just add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems it was mixed with another branch. All that I put in this PR should have be inside #1642
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we rebase this or somehow reduce the extraneous changes that are not part of adding
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to close this and start again in the right order. |
||
| } | ||
| summary_text = "infix form" | ||
|
|
||
| def eval_makeboxes_infix( | ||
| self, expr, operator, precedence: Integer, grouping, form: Symbol, evaluation | ||
| ): | ||
| """MakeBoxes[Infix[expr_, operator_, precedence_:None, grouping_:None], form:StandardForm|TraditionalForm]""" | ||
| return eval_infix(self, expr, operator, precedence, grouping, form, evaluation) | ||
|
|
||
|
|
||
| class Left(Builtin): | ||
| """ | ||
|
|
@@ -278,6 +296,13 @@ class Postfix(PostfixOperator): | |
| operator_display = None | ||
| summary_text = "postfix form" | ||
|
|
||
| def eval_makeboxes_postfix(self, expr, h, precedence, form, evaluation): | ||
| """MakeBoxes[Postfix[expr_, h_, precedence_:None], | ||
| form:StandardForm|TraditionalForm]""" | ||
| return eval_postprefix( | ||
| self, SymbolPostfix, expr, h, precedence, form, evaluation | ||
| ) | ||
|
|
||
|
|
||
| class Precedence(Builtin): | ||
| """ | ||
|
|
@@ -332,8 +357,20 @@ class PrecedenceForm(Builtin): | |
| <dt>'PrecedenceForm'[$expr$, $prec$] | ||
| <dd> format $expr$ parenthesized as it would be if it contained an operator of precedence $prec$. | ||
| </dl> | ||
|
|
||
| >> PrecedenceForm[x/y, 12] - z | ||
| = -z + (x / y) | ||
|
|
||
| """ | ||
|
|
||
| def eval_outerprecedenceform(self, expr, precedence, form, evaluation): | ||
| """MakeBoxes[PrecedenceForm[expr_, precedence_], | ||
| form:StandardForm|TraditionalForm]""" | ||
|
|
||
| py_precedence = precedence.get_int_value() | ||
| boxes = format_element(expr, evaluation, form) | ||
| return parenthesize(py_precedence, expr, boxes, True) | ||
|
|
||
| summary_text = "parenthesize with a precedence" | ||
|
|
||
|
|
||
|
|
@@ -370,6 +407,13 @@ class Prefix(PrefixOperator): | |
| operator_display = None | ||
| summary_text = "prefix form" | ||
|
|
||
| def eval_makeboxes_prefix(self, expr, h, precedence, form, evaluation): | ||
| """MakeBoxes[Prefix[expr_, h_, precedence_:None], | ||
| form:StandardForm|TraditionalForm]""" | ||
| return eval_postprefix( | ||
| self, SymbolPrefix, expr, h, precedence, form, evaluation | ||
| ) | ||
|
|
||
|
|
||
| class Right(Builtin): | ||
| """ | ||
|
|
@@ -456,7 +500,12 @@ class Style(Builtin): | |
|
|
||
| summary_text = "wrapper for styles and style options to apply" | ||
| options = {"ImageSizeMultipliers": "Automatic"} | ||
|
|
||
| rules = { | ||
| "MakeBoxes[Style[expr_, OptionsPattern[Style]], f_]": ( | ||
| "StyleBox[MakeBoxes[expr, f], " | ||
| "ImageSizeMultipliers -> OptionValue[ImageSizeMultipliers]]" | ||
| ), | ||
| } | ||
| rules = { | ||
| "MakeBoxes[Style[expr_, OptionsPattern[Style]], f_]": ( | ||
| "StyleBox[MakeBoxes[expr, f], " | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I notice here and elsewhere in this file is that the parameter in the documentation is called
boxes, notboxed. I think that is just a little clearer.