Skip to content
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

Added calls to replace_wl_with_plain_text in boxes_to_text and boxes_to_xml for String and Symbol #1136

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mathics/builtin/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Implies(BinaryOperator):
If an expression does not evaluate to 'True' or 'False', 'Implies'
returns a result in symbolic form:
>> Implies[a, Implies[b, Implies[True, c]]]
= a \uF523 b \uF523 c
= a b c
"""

operator = "\uF523"
Expand Down Expand Up @@ -171,7 +171,7 @@ class Equivalent(BinaryOperator):
If all expressions do not evaluate to 'True' or 'False', 'Equivalent'
returns a result in symbolic form:
>> Equivalent[a, b, c]
= a \u29E6 b \u29E6 c
= a b c
Otherwise, 'Equivalent' returns a result in DNF
>> Equivalent[a, b, True, c]
= a && b && c
Expand Down
8 changes: 7 additions & 1 deletion mathics/core/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ def display(self, data, metadata):

class Evaluation(object):
def __init__(
self, definitions=None, output=None, format="text", catch_interrupt=True
self,
definitions=None,
output=None,
format="text",
catch_interrupt=True,
use_unicode=True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worng. This is a property of formatting, not evaluation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rocky I agree, but I don't know where to place it.

) -> None:
from mathics.core.definitions import Definitions
from mathics.core.expression import Symbol
Expand All @@ -242,6 +247,7 @@ def __init__(
self.stopped = False
self.out = []
self.output = output if output else Output()
self.use_unicode = use_unicode
self.listeners = {}
self.options = None
self.predetermined_out = None
Expand Down
18 changes: 16 additions & 2 deletions mathics/core/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any
from itertools import chain
from bisect import bisect_left
from mathics_scanner.characters import replace_wl_with_plain_text
from functools import lru_cache


Expand Down Expand Up @@ -1906,7 +1907,16 @@ def do_copy(self) -> "Symbol":
return Symbol(self.name)

def boxes_to_text(self, **options) -> str:
return str(self.name)
name = str(self.name)

if "evaluation" in options:
e = options["evaluation"]
return replace_wl_with_plain_text(name, use_unicode=e.use_unicode)
else:
return name

def boxes_to_xml(self, **options) -> str:
return replace_wl_with_plain_text(str(self.name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this depend on the option passed to the Evaluation object?


def atom_to_boxes(self, f, evaluation) -> "String":
return String(evaluation.definitions.shorten_name(self.name))
Expand Down Expand Up @@ -2725,6 +2735,10 @@ def boxes_to_text(self, show_string_characters=False, **options) -> str:
):
value = value[1:-1]

if "evaluation" in options:
e = options["evaluation"]
value = replace_wl_with_plain_text(value, e.use_unicode)

return value

def boxes_to_xml(self, show_string_characters=False, **options) -> str:
Expand All @@ -2742,7 +2756,7 @@ def boxes_to_xml(self, show_string_characters=False, **options) -> str:
text = self.value

def render(format, string):
encoded_text = encode_mathml(string)
encoded_text = encode_mathml(replace_wl_with_plain_text(string))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same that in Symbol

return format % encoded_text

if text.startswith('"') and text.endswith('"'):
Expand Down