1 ! Copyright (C) 2003, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays hashtables io kernel math math.parser memory
4 namespaces parser sequences strings io.styles
5 io.streams.duplex vectors words generic system combinators
6 continuations debugger definitions compiler.units accessors ;
13 [ ] listener-hook set-global
15 GENERIC: stream-read-quot ( stream -- quot/f )
17 : parse-lines-interactive ( lines -- quot/f )
18 [ parse-lines in get ] with-compilation-unit in set ;
20 : read-quot-step ( lines -- quot/f )
21 [ parse-lines-interactive ] [
22 dup error>> unexpected-eof?
23 [ 2drop f ] [ rethrow ] if
26 : read-quot-loop ( stream accum -- quot/f )
27 over stream-readln dup [
29 dup read-quot-step dup
30 [ 2nip ] [ drop read-quot-loop ] if
35 M: object stream-read-quot
36 V{ } clone read-quot-loop ;
38 M: duplex-stream stream-read-quot
39 duplex-stream-in stream-read-quot ;
41 : read-quot ( -- quot/f ) stdio get stream-read-quot ;
43 : bye ( -- ) quit-flag on ;
46 "( " in get " )" 3append
47 H{ { background { 1 0.7 0.7 1 } } } format bl flush ;
50 listener-hook get call prompt.
51 [ read-quot [ try ] [ bye ] if* ]
63 [ listen until-quit ] if ; inline
66 [ until-quit ] with-interactive-vocabs ;