The Lambda Lab
/
projects
/
scheme.forth.jl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
35aac98
)
Input succesfully shifted to read.
author
Tim Vaughan
<tgvaughan@gmail.com>
Mon, 4 Jul 2016 20:48:29 +0000
(22:48 +0200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Mon, 4 Jul 2016 20:49:01 +0000
(22:49 +0200)
scheme.4th
patch
|
blob
|
history
diff --git
a/scheme.4th
b/scheme.4th
index
524f3a1
..
08a72b5
100644
(file)
--- a/
scheme.4th
+++ b/
scheme.4th
@@
-19,11
+19,15
@@
create parse-str 161 allot
variable parse-str-span
: append-newline
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
: getline
- parse-str 160 expect
+ parse-str 160 expect
cr
span @ parse-str-span !
append-newline
0 parse-idx ! ;
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 ! ;
: restore-parse-idx
stored-parse-idx @ parse-idx ! ;
-
: charavailable? ( -- bool )
: charavailable? ( -- bool )
- parse-str-span @ parse-idx @ >
-;
+ parse-str-span @ parse-idx @ > ;
: nextchar ( -- char )
charavailable? false = if getline then
: nextchar ( -- char )
charavailable? false = if getline then
@@
-51,8
+53,10
@@
variable parse-str-span
: whitespace? ( -- bool )
nextchar BL =
: whitespace? ( -- bool )
nextchar BL =
- nextchar '\n' = or
-;
+ nextchar '\n' = or ;
+
+: eof? ( -- bool )
+ nextchar 4 = ;
: delim? ( -- bool )
whitespace?
: delim? ( -- bool )
whitespace?
@@
-153,6
+157,8
@@
variable parse-str-span
true
then
true
then
+ inc-parse-idx
+
boolean-type
;
boolean-type
;
@@
-171,6
+177,11
@@
variable parse-str-span
exit
then
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
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 -- )
." ; "
: 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 ----
;
\ ---- REPL ----
@@
-217,6
+228,8
@@
variable parse-str-span
cr ." Welcome to scheme.forth.jl!" cr
." Use Ctrl-D to exit." cr
cr ." Welcome to scheme.forth.jl!" cr
." Use Ctrl-D to exit." cr
+ empty-parse-str
+
begin
cr bold fg green ." > " reset-term
read
begin
cr bold fg green ." > " reset-term
read