chiark / gitweb /
src/module-parse.lisp (code): Hoist complex sub-items out of main parser.
[sod] / src / module-parse.lisp
index df058bee46bc179b69181dd2dab942d65cdc1d28..fb4903b4f8175cab052d2105bbc5692327f19301 100644 (file)
@@ -64,23 +64,25 @@ (define-pluggable-parser module code (scanner pset)
             (item ()
               (parse (or (kw)
                          (seq (#\( (names (list (:min 1) (kw))) #\))
-                           names)))))
+                           names))))
+            (constraints ()
+              (parse (seq (#\[
+                           (constraints
+                            (list ()
+                              (list (:min 1)
+                                (error (:ignore-unconsumed t) (item)
+                                  (skip-until () :id #\( #\, #\])))
+                              #\,))
+                           #\])
+                       constraints)))
+            (fragment ()
+              (parse-delimited-fragment scanner #\{ #\})))
       (parse (seq ("code"
                   (reason (must (kw)))
                   (nil (must #\:))
                   (name (must (item)))
-                  (constraints (? (seq (#\[
-                                        (constraints
-                                         (list ()
-                                           (list (:min 1)
-                                             (error (:ignore-unconsumed t)
-                                                 (item)
-                                               (skip-until ()
-                                                 :id #\( #\, #\])))
-                                           #\,))
-                                        #\])
-                                    constraints)))
-                  (fragment (parse-delimited-fragment scanner #\{ #\})))
+                  (constraints (? (constraints)))
+                  (fragment (fragment)))
               (when name
                 (add-to-module *module*
                                (make-instance 'code-fragment-item
@@ -108,9 +110,7 @@ (defun read-module (pathname &key (truename nil truep) location)
   (unless truep (setf truename (truename pathname)))
   (define-module (pathname :location location :truename truename)
     (with-open-file (f-stream pathname :direction :input)
-      (let* ((*readtable* (copy-readtable))
-            (*package* (find-package '#:sod-user))
-            (char-scanner (make-instance 'charbuf-scanner
+      (let* ((char-scanner (make-instance 'charbuf-scanner
                                          :stream f-stream
                                          :filename (namestring pathname)))
             (scanner (make-instance 'sod-token-scanner
@@ -128,13 +128,6 @@   (define-module (pathname :location location :truename truename)
              (declare (ignore consumedp))
              (unless winp (syntax-error scanner result)))))))))
 
-(define-pluggable-parser module test (scanner pset)
-  ;; `demo' string `;'
-  (declare (ignore pset))
-  (with-parser-context (token-scanner-context :scanner scanner)
-    (parse (seq ("demo" (string (must :string)) (nil (must #\;)))
-            (format t ";; DEMO ~S~%" string)))))
-
 (define-pluggable-parser module file (scanner pset)
   ;; `import' string `;'
   ;; `load' string `;'
@@ -156,6 +149,7 @@ (define-pluggable-parser module file (scanner pset)
                                                            :truename true)))
                                   (when module
                                     (module-import module)
+                                    (pushnew path (module-files *module*))
                                     (pushnew module
                                              (module-dependencies
                                               *module*))))
@@ -170,7 +164,9 @@ (define-pluggable-parser module file (scanner pset)
                   (common name "LISP" "Lisp file"
                           (lambda (path true)
                             (handler-case
-                                (load true :verbose nil :print nil)
+                                (progn
+                                  (pushnew path (module-files *module*))
+                                  (load true :verbose nil :print nil))
                               (error (error)
                                 (cerror* "Error loading Lisp file ~S: ~A"
                                          path error)))))))))))