Use the parser state, not the value produced, to determine success.
authorTaylor R Campbell <campbell@mumble.net>
Fri, 7 Dec 2018 17:11:07 +0000 (17:11 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Fri, 7 Dec 2018 17:17:29 +0000 (17:17 +0000)
src/runtime/numpar.scm

index dd27fa0f18a331222ccb5a966ea93ef9bc9ea89b..d1d2a258cdc07ea36eb5a77264c8f19845241449 100644 (file)
@@ -132,7 +132,12 @@ USA.
                                   #f sign comp))
               ((i? char)
                (and (fix:= start end)
-                    (make-rectangular 0 (if (eq? #\- sign) -1 1))))
+                    (let ((v (if (eq? #\- sign) -1 1)))
+                      (case comp
+                        ((real) (make-rectangular 0 v))
+                        ((imag) v)
+                        ((angle) #f)
+                        (else (error "Invalid complex state:" comp))))))
               (else #f)))))
 
 (define (parse-integer string start end integer exactness radix sign comp)
@@ -313,22 +318,29 @@ USA.
        (cond ((i? char)
               (and sign
                    (fix:= start+1 end)
-                   (make-rectangular 0 real)))
+                   (case comp
+                     ((real) (make-rectangular 0 real))
+                     ((imag) real)
+                     ((angle) #f)
+                     (else (error "Invalid complex state:" comp)))))
              ((not (eq? comp 'real))
               #f)
              ((sign? char)
               (let ((imaginary
                      (parse-top-level string start end exactness radix
                                       'imag)))
-                (and (complex? imaginary)
-                     (= 0 (real-part imaginary))
-                     (make-rectangular real (imag-part imaginary)))))
+                (and imaginary
+                     (begin
+                       (assert (real? imaginary))
+                       (make-rectangular real imaginary)))))
              ((char=? #\@ char)
               (let ((angle
                      (parse-top-level string start+1 end exactness radix
                                       'angle)))
-                (and (real? angle)
-                     (make-polar real angle))))
+                (and angle
+                     (begin
+                       (assert (real? angle))
+                       (make-polar real angle)))))
              (else #f)))
       (and (not (eq? comp 'imag)) real)))