diff options
-rw-r--r-- | parser.c | 24 | ||||
-rw-r--r-- | txr.1 | 25 |
2 files changed, 48 insertions, 1 deletions
@@ -504,6 +504,25 @@ static val repl_intr(val signo, val async_p) uw_throw(error_s, lit("intr")); } +static val read_eval_ret_last(val env, val in_stream, val out_stream) +{ + val lineno = one; + + for (;; lineno = succ(lineno)) { + val form = lisp_parse(in_stream, out_stream, colon_k, + lit("paste"), lineno); + val parser = get_parser(in_stream); + val value = eval_intrinsic(form, nil); + + if (parser_eof(parser)) { + prinl(value, out_stream); + break; + } + } + + return t; +} + val repl(val bindings, val in_stream, val out_stream) { val ifd = stream_get_prop(in_stream, fd_k); @@ -513,6 +532,7 @@ val repl(val bindings, val in_stream, val out_stream) char *prompt_u8 = 0; val repl_env = make_env(bindings, nil, nil); val quit_k = intern(lit("quit"), keyword_package); + val read_k = intern(lit("read"), keyword_package); val counter_sym = intern(lit("*n"), user_package); val var_counter_sym = intern(lit("*v"), user_package); val result_hash_sym = intern(lit("*r"), user_package); @@ -575,7 +595,9 @@ val repl(val bindings, val in_stream, val out_stream) if (form == quit_k) { done = t; } else { - val value = eval_intrinsic(form, repl_env); + val value = if3(form != read_k, + eval_intrinsic(form, repl_env), + read_eval_ret_last(repl_env, in_stream, out_stream)); reg_varl(var_sym, value); sethash(result_hash, var_counter, value); prinl(value, out_stream); @@ -33584,6 +33584,31 @@ is that arrow keys (and other special command keys) are represented, by a VT100-compatible terminal or terminal emulator, as special sequences of bytes beginning with ESC (known as "escape sequences"). +.SS* Reading Forms Directly from the Terminal + +The listener is currently line oriented. There is, however, support for +accepting input which may span multiple lines and come in a large +quantity. + +If the +.code :read +keyword is entered into the listener, it will temporarily suspend +interactive editing and allow the \*(TL parser to read +directly from standard input. The reading stops when an error occurs, +or EOF is indicated by entering Ctrl-D. + +In direct parsing mode, each expression which is read is evaluated, but its +value is not printed. However, the value of the last form evaluated is returned +to the interactive listener, which prints the value and accepts it as if +it as the result value of the +.code :read +command. + +Note that none of the material read from the terminal is entered into the +interactive history. Only the +.code :read +command which triggers this parsing mode appears in the history. + .SH* DEBUGGER \*(TX has a simple, crude, built-in debugger. The debugger is invoked by adding the |