diff options
Diffstat (limited to 'docgen.lisp')
-rw-r--r-- | docgen.lisp | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/docgen.lisp b/docgen.lisp index cc19133..cb43edc 100644 --- a/docgen.lisp +++ b/docgen.lisp @@ -23,34 +23,39 @@ (defun write-one-or-more-doc (arg) (write-pattern-doc arg) - (princ "+")) + (princ "+")) (defun write-alternatives-doc (args) + (princ "(") (loop :for (a . more) :on args :do (write-pattern-doc a) (when more - (princ " | ")))) + (princ " | "))) + (princ ")")) (defun write-grammar-pattern-doc (grammar-name) (princ "{") (princ grammar-name) (princ "}")) (defun write-pattern-doc (pattern ) - (if (atom pattern) - (princ pattern) - (destructuring-bind (op . args) pattern - (case op - ((:seq :seq=) (write-sequence-doc args )) - ((:? :?=) (write-optional-doc (first args))) - ((:* :*=) (write-kleene-doc (first args))) - ((:+ :+=) (write-one-or-more-doc (first args))) - ((:or :or=) (write-alternatives-doc args)) + (cond ((nonterminal? pattern) + (princ pattern)) + ((atom pattern) + (princ "'") (princ pattern) (princ "'")) + (t + (destructuring-bind (op . args) pattern + (case op + ((:seq :seq=) (write-sequence-doc args )) + ((:? :?=) (write-optional-doc (first args))) + ((:* :*=) (write-kleene-doc (first args))) + ((:+ :+=) (write-one-or-more-doc (first args))) + ((:or :or=) (write-alternatives-doc args)) - (:= (princ (first args))) - (:@ (write-pattern-doc (second args))) - (:{} (write-grammar-pattern-doc (first args))) - - (:item (princ "::TOKEN::")) - (:eof (princ "::EOF::")))))) + (:= (princ (first args))) + (:@ (write-pattern-doc (second args))) + (:{} (write-grammar-pattern-doc (first args))) + + (:item (princ "::TOKEN::")) + (:eof (princ "::EOF::"))))))) |