Skip to content

Commit cd87f17

Browse files
committed
Add strict-wl-output option: no quotes in string
1 parent c14b9e0 commit cd87f17

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

mathics/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def read_line(self, prompt):
110110
return self.rl_read_line(prompt)
111111
return input(prompt)
112112

113-
def print_result(self, result, no_out_prompt=False):
113+
def print_result(self, result, no_out_prompt=False, strict_wl_output=False):
114114
if result is None:
115115
# FIXME decide what to do here
116116
return
@@ -125,7 +125,7 @@ def print_result(self, result, no_out_prompt=False):
125125
return
126126

127127
out_str = str(result.result)
128-
if eval_type == "System`String":
128+
if eval_type == "System`String" and not strict_wl_output:
129129
out_str = '"' + out_str.replace('"', r'\"') + '"'
130130
if eval_type == "System`Graph":
131131
out_str = "-Graph-"
@@ -286,6 +286,12 @@ def main() -> int:
286286
"--version", "-v", action="version", version="%(prog)s " + __version__
287287
)
288288

289+
argparser.add_argument(
290+
"--strict-wl-output",
291+
help="Most WL-output compatible (at the expense of useability).",
292+
action="store_true",
293+
)
294+
289295
args, script_args = argparser.parse_known_args()
290296

291297
quit_command = "CTRL-BREAK" if sys.platform == "win32" else "CONTROL-D"
@@ -331,7 +337,7 @@ def main() -> int:
331337
for expr in args.execute:
332338
evaluation = Evaluation(shell.definitions, output=TerminalOutput(shell))
333339
result = evaluation.parse_evaluate(expr, timeout=settings.TIMEOUT)
334-
shell.print_result(result, no_out_prompt=True)
340+
shell.print_result(result, no_out_prompt=True, strict_wl_output=args.strict_wl_output)
335341
if evaluation.exc_result == Symbol("Null"):
336342
exit_rc = 0
337343
elif evaluation.exc_result == Symbol("$Aborted"):
@@ -385,7 +391,7 @@ def main() -> int:
385391
print(query)
386392
result = evaluation.evaluate(query, timeout=settings.TIMEOUT)
387393
if result is not None:
388-
shell.print_result(result)
394+
shell.print_result(result, strict_wl_output=args.strict_wl_output)
389395
except (KeyboardInterrupt):
390396
print("\nKeyboardInterrupt")
391397
except EOFError:

0 commit comments

Comments
 (0)