eatspaces now eats comments
[scheme.forth.jl.git] / scheme.4th
index 1953cf9..72897be 100644 (file)
@@ -296,6 +296,17 @@ global-env setobj
     then
 ;
 
+: arg-type-error
+            bold fg red ." Incorrect argument type." reset-term cr
+            abort
+;
+
+: ensure-arg-type ( arg type -- arg )
+    istype? false = if
+        arg-type-error
+    then
+;
+
 include scheme-primitives.4th
 
 \ }}}
@@ -366,12 +377,27 @@ parse-idx-stack parse-idx-sp !
     nextchar [char] ) = or
 ;
 
+: commentstart? ( -- bool )
+    nextchar [char] ; = ;
+
 : eatspaces
+
+    false \ Indicates whether or not we're eating a comment
+
     begin
-        whitespace?
+        dup whitespace? or commentstart? or
     while
+        dup nextchar '\n' = and if
+            invert \ Stop eating comment
+        else
+            dup false = commentstart? and if   
+                invert \ Begin eating comment
+            then
+        then
+
         inc-parse-idx
     repeat
+    drop
 ;
 
 : digit? ( -- bool )
@@ -382,8 +408,11 @@ parse-idx-stack parse-idx-sp !
 : minus? ( -- bool )
     nextchar [char] - = ;
 
+: plus? ( -- bool )
+    nextchar [char] + = ;
+
 : fixnum? ( -- bool )
-    minus? if
+    minus? plus? or if
         inc-parse-idx
 
         delim? if
@@ -482,8 +511,11 @@ parse-idx-stack parse-idx-sp !
     nextchar [char] " = ;
 
 : readnum ( -- num-atom )
-    minus? dup if
+    plus? minus? or if
+        minus?
         inc-parse-idx
+    else
+        false
     then
 
     0