|
72 | 72 | RL_COMPLETER_DELIMS_WITH_BRACE = " \t\n_~!@#%^&*()-=+{]}|;:'\",<>/?" |
73 | 73 | RL_COMPLETER_DELIMS = " \t\n_~!@#%^&*()-=+[{]}\\|;:'\",<>/?" |
74 | 74 |
|
| 75 | +wl_replace_dict = { |
| 76 | + "": "Ạ", |
| 77 | + "": "ạ", |
| 78 | + "": "Ḅ", |
| 79 | + "": "ḅ", |
| 80 | + # ... |
| 81 | + "": "→", |
| 82 | + "": "↔", |
| 83 | +} |
| 84 | + |
| 85 | +wl_replace_dict_esc = dict((re.escape(k), v) for k, v in wl_replace_dict.items()) |
| 86 | +wl_replace_pattern = re.compile("|".join(wl_replace_dict_esc.keys())) |
| 87 | + |
| 88 | +unicode_replace_dict = {v: k for k, v in wl_replace_dict.items()} |
| 89 | +unicode_replace_dict_esc = dict( |
| 90 | + (re.escape(k), v) for k, v in unicode_replace_dict.items() |
| 91 | +) |
| 92 | +unicode_replace_pattern = re.compile("|".join(unicode_replace_dict_esc.keys())) |
| 93 | + |
| 94 | + |
75 | 95 | from mathics.core.parser import LineFeeder |
76 | 96 |
|
77 | 97 |
|
| 98 | +def replace_unicode_to_wl(unicode_input: str) -> str: |
| 99 | + """WL uses some non-unicode character for various things. |
| 100 | + Replace the unicode equivalent with the WL equivalent. |
| 101 | + Formal values like FormalA are like this. |
| 102 | + """ |
| 103 | + return unicode_replace_pattern.sub( |
| 104 | + lambda m: unicode_replace_dict_esc[re.escape(m.group(0))], wl_input |
| 105 | + ) |
| 106 | + |
| 107 | + |
78 | 108 | def is_pygments_style(style): |
79 | 109 | if style not in ALL_PYGMENTS_STYLES: |
80 | 110 | print("Pygments style name '%s' not found." % style) |
@@ -221,7 +251,7 @@ def out_callback(self, out): |
221 | 251 | def read_line(self, prompt): |
222 | 252 | if self.using_readline: |
223 | 253 | return self.rl_read_line(prompt) |
224 | | - return input(prompt) |
| 254 | + return replace_unicode_to_wl(input(prompt)) |
225 | 255 |
|
226 | 256 | def print_result(self, result, output_style=""): |
227 | 257 | if result is None: |
|
0 commit comments