chiark / gitweb /
src/module-parse.lisp: Catch errors during class-item construction.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 26 Mar 2017 14:16:18 +0000 (15:16 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 8 Jun 2018 18:58:28 +0000 (19:58 +0100)
These aren't worth failing the whole class construction over, but they
do mean that the individual class-item shouldn't be recorded.

This approach seems generally easier than reporting continuable errors
and then indicating failure in some other way, particularly in the case
of slots with initializers.

src/module-parse.lisp

index 028ad8774303a34c1d84dbdac7a25fa6bcbaa640..15bfe87161fc113df1256ada44388f9a4fa86142 100644 (file)
@@ -317,8 +317,10 @@ (defun parse-class-body (scanner pset name supers)
                 (parse (seq ((body (or (seq ("extern" #\;) nil)
                                        (parse-delimited-fragment
                                         scanner #\{ #\}))))
-                         (make-sod-method class sub-nick name type
-                                          body sub-pset scanner))))
+                         (restart-case
+                             (make-sod-method class sub-nick name type
+                                              body sub-pset scanner)
+                           (continue () :report "Continue")))))
 
               (parse-initializer ()
                 ;; initializer ::= `=' c-fragment
@@ -335,14 +337,17 @@ (defun parse-class-body (scanner pset name supers)
                 ;;
                 ;; init-declarator ::= declarator [initializer]
                 (flet ((make-it (name type init)
-                         (make-sod-slot class name type
-                                        sub-pset scanner)
-                         (when init
-                           (make-sod-instance-initializer class
-                                                          nick name
-                                                          init
-                                                          sub-pset
-                                                          scanner))))
+                         (restart-case
+                             (progn
+                               (make-sod-slot class name type
+                                              sub-pset scanner)
+                               (when init
+                                 (make-sod-instance-initializer class
+                                                                nick name
+                                                                init
+                                                                sub-pset
+                                                                scanner)))
+                           (continue () :report "Continue"))))
                   (parse (and (seq ((init (? (parse-initializer))))
                                 (make-it name type init))
                               (skip-many ()
@@ -363,9 +368,11 @@ (defun parse-class-body (scanner pset name supers)
                   (parse (and (skip-many ()
                                 (seq ((name-a :id) #\. (name-b :id)
                                       (init (funcall parse-init)))
-                                  (funcall constructor class
-                                           name-a name-b init
-                                           sub-pset scanner))
+                                  (restart-case
+                                      (funcall constructor class
+                                               name-a name-b init
+                                               sub-pset scanner)
+                                    (continue () :report "Continue")))
                                 #\,)
                               #\;))))