1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 21:57:38 +03:00
mal/impls/jq/step1_read_print.jq

43 lines
721 B
Plaintext
Raw Permalink Normal View History

2020-01-05 14:02:39 +03:00
include "reader";
include "printer";
2020-01-05 17:03:09 +03:00
include "utils";
2020-01-05 14:02:39 +03:00
def read_line:
. as $in
| label $top
| _readline;
2020-01-05 14:02:39 +03:00
def READ:
read_str | read_form | .value;
2020-01-05 14:02:39 +03:00
def EVAL:
.;
2020-01-05 14:02:39 +03:00
def PRINT:
2020-01-05 17:03:09 +03:00
pr_str;
2020-01-05 14:02:39 +03:00
def rep:
2020-01-05 17:03:09 +03:00
READ | EVAL |
if . != null then
PRINT
else
null
end;
2020-01-05 14:02:39 +03:00
def repl_:
("user> " | _print) |
2020-01-05 17:03:09 +03:00
(read_line | rep);
2020-01-05 14:02:39 +03:00
def repl:
2020-01-05 17:03:09 +03:00
{continue: true} | while(
.continue;
try {value: repl_, continue: true}
catch
if is_jqmal_error then
{value: "Error: \(.)", continue: true}
else
{value: ., continue: false}
end) | if .value then .value|_display else empty end;
2020-01-05 14:02:39 +03:00
repl