X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/sod/blobdiff_plain/65eebc3b1882c74ea1e3e6eefbb1aecb10802b61..7605e373dc975bf8e69f57d9e0ce99a2d9d774c7:/src/module-parse.lisp diff --git a/src/module-parse.lisp b/src/module-parse.lisp index 197e3e4..014e7e3 100644 --- a/src/module-parse.lisp +++ b/src/module-parse.lisp @@ -36,14 +36,17 @@ (define-pluggable-parser module typename (scanner pset) (with-parser-context (token-scanner-context :scanner scanner) (parse (and "typename" (skip-many () - (seq ((id :id)) - (if (gethash id *module-type-map*) - (cerror* "Type `~A' already defined" id) - (add-to-module *module* - (make-instance 'type-item - :name id)))) + (error () + (seq ((id :id)) + (if (or (gethash id *module-type-map*) + (find-simple-c-type id)) + (cerror* "Type `~A' already defined" id) + (add-to-module *module* + (make-instance 'type-item + :name id)))) + (skip-until () #\, #\;)) #\,) - #\;)))) + (must #\;))))) ;;; Fragments. @@ -63,23 +66,28 @@ (define-pluggable-parser module code (scanner pset) (seq (#\( (names (list (:min 1) (kw))) #\)) names))))) (parse (seq ("code" - (reason (kw)) - #\: - (name (item)) + (reason (must (kw))) + (nil (must #\:)) + (name (must (item))) (constraints (? (seq (#\[ - (constraints (list (:min 1) - (list (:min 1) - (item)) - #\,)) + (constraints + (list () + (list (:min 1) + (error (:ignore-unconsumed t) + (item) + (skip-until () + :id #\( #\, #\]))) + #\,)) #\]) constraints))) (fragment (parse-delimited-fragment scanner #\{ #\}))) - (add-to-module *module* - (make-instance 'code-fragment-item - :fragment fragment - :constraints constraints - :reason reason - :name name))))))) + (when name + (add-to-module *module* + (make-instance 'code-fragment-item + :fragment fragment + :constraints constraints + :reason reason + :name name)))))))) ;;; External files. @@ -103,7 +111,8 @@ (define-module (pathname :location location :truename truename) (let* ((*readtable* (copy-readtable)) (*package* (find-package '#:sod-user)) (char-scanner (make-instance 'charbuf-scanner - :stream f-stream)) + :stream f-stream + :filename (namestring pathname))) (scanner (make-instance 'sod-token-scanner :char-scanner char-scanner))) (with-default-error-location (scanner) @@ -112,7 +121,9 @@ (define-module (pathname :location location :truename truename) (parse (skip-many () (seq ((pset (parse-property-set scanner)) (nil (error () - (plug module scanner pset)))) + (plug module scanner pset) + (skip-until (:keep-end nil) + #\; #\})))) (check-unused-properties pset)))) (declare (ignore consumedp)) (unless winp (syntax-error scanner result))))))))) @@ -121,7 +132,7 @@ (define-pluggable-parser module test (scanner pset) ;; `demo' string `;' (declare (ignore pset)) (with-parser-context (token-scanner-context :scanner scanner) - (parse (seq ("demo" (string :string) #\;) + (parse (seq ("demo" (string (must :string)) (nil (must #\;))) (format t ";; DEMO ~S~%" string))))) (define-pluggable-parser module file (scanner pset) @@ -175,7 +186,7 @@ (define-pluggable-parser module set (scanner pset) :location (p-location prop)) (setf (p-seenp prop) t)) pset)) - (parse (skip-many (:min 0) + (parse (skip-many (:min (if pset 0 1)) (error (:ignore-unconsumed t) (parse-property scanner module-pset) (skip-until () #\, #\;))