From b0213128f7c0cde618c0c3ca958c6b79f2de4b72 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 2 Aug 2023 21:30:20 -0700 Subject: Improved docgen --- argot.lisp | 12 +++++++++++- docgen.lisp | 39 ++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/argot.lisp b/argot.lisp index f394e2a..1eb7fc5 100644 --- a/argot.lisp +++ b/argot.lisp @@ -133,7 +133,17 @@ and it returns VAR in that case." (terpri) (terpri) (loop :for (lhs pattern . more) :in parsed-rules :do (write-rule-doc lhs pattern) - (terpri))))) + (terpri)) + (terpri) + (princ "KEY: ") (terpri) + (princ "::TOKEN:: Any ole token") (terpri) + (princ "::EOF:: Explicitly match the end of the input") (terpri) + (princ "{GRAMMAR} Parse a sublist of tokens with GRAMMAR") (terpri) + (princ "(a|b|..) One of the alternavites a b ...") (terpri) + (princ "PATTERN+ One or more PATTERN") (terpri) + (princ "PATTERN* Zero or more PATTERN") (terpri) + (princ " A nonterminal symbol - naming a parse rule") (terpri) + (princ "[OPT] Zero or one of OPT")))) `(progn (defvar ,name nil) (setf ,name (make-instance 'grammar 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::"))))))) -- cgit v1.2.3