X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/e05aabbb81cddec46b3d9da802f632c3b20c67d1..2c6153373f927d948a74b283ebb16330af8ee49a:/src/module-parse.lisp?ds=sidebyside diff --git a/src/module-parse.lisp b/src/module-parse.lisp index 311206d..8344281 100644 --- a/src/module-parse.lisp +++ b/src/module-parse.lisp @@ -52,6 +52,7 @@ (define-pluggable-parser module code (scanner pset) ;; `code' id `:' item-name [constraints] `{' c-fragment `}' + ;; `code' id `:' constraints `;' ;; ;; constraints ::= `[' list[constraint] `]' ;; constraint ::= item-name+ @@ -64,30 +65,37 @@ (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 #\{ #\}))) - (when name - (add-to-module *module* - (make-instance 'code-fragment-item - :fragment fragment - :constraints constraints - :reason reason - :name name)))))))) + (item (or (seq ((constraints (constraints)) + (nil (must #\;))) + (make-instance 'code-fragment-item + :reason reason + :constraints constraints)) + (seq ((name (must (item))) + (constraints (? (constraints))) + (fragment (fragment))) + (and name + (make-instance 'code-fragment-item + :reason reason + :constraints constraints + :name name + :fragment fragment)))))) + (when item (add-to-module *module* item))))))) ;;; External files. @@ -108,9 +116,7 @@ (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 +134,6 @@ (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 `;'