From: Tim Vaughan Date: Mon, 4 Jul 2016 20:48:29 +0000 (+0200) Subject: Input succesfully shifted to read. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=7f58e8a0232663cd99ea18fd249d1e590ceb6fff;p=scheme.forth.jl.git Input succesfully shifted to read. --- diff --git a/scheme.4th b/scheme.4th index 524f3a1..08a72b5 100644 --- a/scheme.4th +++ b/scheme.4th @@ -19,11 +19,15 @@ create parse-str 161 allot variable parse-str-span : append-newline - 1 parse-str-span +! - '\n' parse-str parse-str-span @ + ! ; + '\n' parse-str parse-str-span @ + ! + 1 parse-str-span +! ; + +: empty-parse-str + 0 parse-str-span ! + 0 parse-idx ! ; : getline - parse-str 160 expect + parse-str 160 expect cr span @ parse-str-span ! append-newline 0 parse-idx ! ; @@ -40,10 +44,8 @@ variable parse-str-span : restore-parse-idx stored-parse-idx @ parse-idx ! ; - : charavailable? ( -- bool ) - parse-str-span @ parse-idx @ > -; + parse-str-span @ parse-idx @ > ; : nextchar ( -- char ) charavailable? false = if getline then @@ -51,8 +53,10 @@ variable parse-str-span : whitespace? ( -- bool ) nextchar BL = - nextchar '\n' = or -; + nextchar '\n' = or ; + +: eof? ( -- bool ) + nextchar 4 = ; : delim? ( -- bool ) whitespace? @@ -153,6 +157,8 @@ variable parse-str-span true then + inc-parse-idx + boolean-type ; @@ -171,6 +177,11 @@ variable parse-str-span exit then + eof? if + bold fg blue ." Moriturus te saluto." reset-term ." ok" cr + quit + then + bold fg red ." Error parsing string starting at character '" nextchar emit ." '. Aborting." reset-term cr @@ -207,8 +218,8 @@ variable parse-str-span : print ( obj -- ) ." ; " - number-type istype? if ." => " printnum exit then - boolean-type istype? if ." => " printbool exit then + number-type istype? if printnum exit then + boolean-type istype? if printbool exit then ; \ ---- REPL ---- @@ -217,6 +228,8 @@ variable parse-str-span cr ." Welcome to scheme.forth.jl!" cr ." Use Ctrl-D to exit." cr + empty-parse-str + begin cr bold fg green ." > " reset-term read