From: Tim Vaughan Date: Mon, 4 Jul 2016 22:15:56 +0000 (+0200) Subject: Draft character atom implementation. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=scheme.forth.jl.git;a=commitdiff_plain;h=26a971100b29dee243a42096d52d69ca518905ea Draft character atom implementation. --- diff --git a/scheme.4th b/scheme.4th index 0bbfbf5..ea02cd5 100644 --- a/scheme.4th +++ b/scheme.4th @@ -18,7 +18,6 @@ variable stored-parse-idx create parse-str 161 allot variable parse-str-span - create parse-idx-stack 10 allot variable parse-idx-sp parse-idx-stack parse-idx-sp ! @@ -204,6 +203,19 @@ parse-idx-stack parse-idx-sp ! boolean-type ; +: readchar ( -- char-atom ) + inc-parse-idx + inc-parse-idx + + S" newline" str-equiv? if '\n' character-type exit then + S" space" str-equiv? if bl character-type exit then + S" tab" str-equiv? if 9 character-type exit then + + nextchar character-type + + inc-parse-idx +; + \ Parse a scheme expression : read ( -- obj ) @@ -219,6 +231,11 @@ parse-idx-stack parse-idx-sp ! exit then + character? if + readchar + exit + then + eof? if bold fg blue ." Moriturus te saluto." reset-term ." ok" cr quit @@ -258,10 +275,20 @@ parse-idx-stack parse-idx-sp ! then ; +: printchar ( charobj -- ) + drop + case + 9 of ." #\tab" endof + bl of ." #\space" endof + '\n' of ." #\newline" endof + endcase +; + : print ( obj -- ) ." ; " number-type istype? if printnum exit then boolean-type istype? if printbool exit then + character-type istype? if printchar exit then ; \ ---- REPL ----