Skip to content

Commit 09e12e8

Browse files
committed
Use replace_wl_with_unicode and replace_unicode_with_wl from mathics
1 parent b3bb5b0 commit 09e12e8

File tree

2 files changed

+3
-44
lines changed

2 files changed

+3
-44
lines changed

mathicsscript/__main__.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
from mathicsscript.termshell import (
1212
ShellEscapeException,
1313
TerminalShell,
14-
wl_replace_dict_esc,
15-
wl_replace_pattern,
1614
)
1715

1816
from mathicsscript.format import format_output
1917

18+
from mathics import replace_wl_with_unicode
2019
from mathics.core.parser import FileLineFeeder
2120
from mathics.core.definitions import Definitions
2221
from mathics.core.expression import Symbol, SymbolTrue, SymbolFalse
@@ -33,16 +32,6 @@
3332
from mathicsscript.version import __version__
3433

3534

36-
def replace_wl_to_unicode(wl_input: str) -> str:
37-
"""WL uses some non-unicode character for various things.
38-
Replace them with the unicode equivalent.
39-
Two known items are directed arrow and undirected arrow.
40-
"""
41-
return wl_replace_pattern.sub(
42-
lambda m: wl_replace_dict_esc[re.escape(m.group(0))], wl_input
43-
)
44-
45-
4635
def ensure_settings():
4736
home = Path.home()
4837
base_config_dir = home / ".config"
@@ -339,7 +328,7 @@ def main(
339328
current_pos = GNU_readline.get_current_history_length()
340329
for pos in range(last_pos, current_pos - 1):
341330
GNU_readline.remove_history_item(pos)
342-
wl_input = replace_wl_to_unicode(source_code.rstrip())
331+
wl_input = replace_wl_with_unicode(source_code.rstrip())
343332
GNU_readline.add_history(wl_input)
344333

345334
if query is None:

mathicsscript/termshell.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,10 @@
7373
RL_COMPLETER_DELIMS_WITH_BRACE = " \t\n_~!@#%^&*()-=+{]}|;:'\",<>/?"
7474
RL_COMPLETER_DELIMS = " \t\n_~!@#%^&*()-=+[{]}\\|;:'\",<>/?"
7575

76-
wl_replace_dict = {
77-
"": "Ạ",
78-
"": "ạ",
79-
"": "Ḅ",
80-
"": "ḅ",
81-
# ...
82-
"": "→",
83-
"": "↔",
84-
"": "𝑑",
85-
}
86-
87-
wl_replace_dict_esc = dict((re.escape(k), v) for k, v in wl_replace_dict.items())
88-
wl_replace_pattern = re.compile("|".join(wl_replace_dict_esc.keys()))
89-
90-
unicode_replace_dict = {v: k for k, v in wl_replace_dict.items()}
91-
unicode_replace_dict_esc = dict(
92-
(re.escape(k), v) for k, v in unicode_replace_dict.items()
93-
)
94-
unicode_replace_pattern = re.compile("|".join(unicode_replace_dict_esc.keys()))
95-
9676

9777
from mathics.core.parser import LineFeeder
9878

9979

100-
def replace_unicode_to_wl(unicode_input: str) -> str:
101-
"""WL uses some non-unicode character for various things.
102-
Replace the unicode equivalent with the WL equivalent.
103-
Formal values like FormalA are like this.
104-
"""
105-
return unicode_replace_pattern.sub(
106-
lambda m: unicode_replace_dict_esc[re.escape(m.group(0))], unicode_input
107-
)
108-
109-
11080
def is_pygments_style(style):
11181
if style not in ALL_PYGMENTS_STYLES:
11282
print("Pygments style name '%s' not found." % style)
@@ -278,7 +248,7 @@ def read_line(self, prompt):
278248
line = input(prompt)
279249
if line.startswith("!") and self.lineno == 0:
280250
raise ShellEscapeException(line)
281-
return replace_unicode_to_wl(line)
251+
return replace_unicode_with_wl(line)
282252

283253
def print_result(self, result, output_style=""):
284254
if result is None:

0 commit comments

Comments
 (0)