If an item cannot be converted to an input-stream in a recursive parse,
authorTony Garnock-Jones <tonyg@kcbbs.gen.nz>
Sat, 17 Jan 2009 23:12:07 +0000
changeset 28 0a56ed00bf44
parent 27 9302cafa2868
child 29 7b6adad58777
If an item cannot be converted to an input-stream in a recursive parse,
fail rather than invoking error.
ometa.scm
--- a/ometa.scm	Sat Jan 17 22:28:25 2009 +1300
+++ b/ometa.scm	Sat Jan 17 23:12:07 2009 +0000
@@ -140,13 +140,17 @@
 
 (define input-stream-constructors '())
 
-(define (->input-stream x)
+(define (->input-stream-or-false x)
   (let search ((ctors input-stream-constructors))
     (cond
-     ((null? ctors) (error "Could not construct input stream" x))
+     ((null? ctors) #f)
      (((caar ctors) x) ((cdar ctors) x))
      (else (search (cdr ctors))))))
 
+(define (->input-stream x)
+  (or (->input-stream-or-false x)
+      (error "Could not construct input stream" x)))
+
 (define (input-stream-split-at-most input i k)
   (let loop ((acc '())
 	     (i i)
@@ -385,10 +389,14 @@
 			    (kf (make-parse-error pos0 `(expected ,item0)))))))))))
       ((nest)
        (input (lambda (pos item tail)
-		(e (cadr exp) env (->input-stream item)
-		   (lambda (sv new-env next err)
-		     (ks sv new-env tail err))
-		   kf))
+		(let ((stream (->input-stream-or-false item)))
+		  (if stream
+		      (e (cadr exp) env stream
+			 (lambda (sv new-env next err)
+			   (ks sv new-env tail err))
+			 kf)
+		      (kf (make-parse-error (input-stream-position input)
+					    `(expected sequence-for-nesting))))))
 	      (lambda (pos)
 		(kf (make-parse-error (input-stream-position input)
 				      `(expected sequence-for-nesting))))))