diff options
author | colin <colin@cicadas.surf> | 2023-08-14 21:09:59 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-08-14 21:09:59 -0700 |
commit | b2e591f163383494eea0bbc29bfe9d2f4b393523 (patch) | |
tree | 18b74a07c54400cb66d48e6d55daee4253066640 | |
parent | cba3deaf6b2c02f8c942512d854f4cf042defd2f (diff) |
updating docgen
-rw-r--r-- | argot.lisp | 9 | ||||
-rw-r--r-- | docgen.lisp | 40 |
2 files changed, 29 insertions, 20 deletions
@@ -134,7 +134,6 @@ and it returns VAR in that case." (princ "ADDITIONAL NOTES:") (terpri) (loop :for (lhs _p _v _c _a note) :in parsed-rules - ;:for lhs-name := (symbol-name lhs) :when note :do (format *standard-output* "~15a ~a~%" lhs @@ -142,10 +141,10 @@ and it returns VAR in that case." (princ "------------------------------------------") (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 "token Any ole token") (terpri) + (princ "eof Explicitly match the end of the input") (terpri) + (princ "{LANGUAGE} Parse a sublist of tokens with LANGUAGE") (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 "<RULE> A nonterminal symbol - naming a parse rule") (terpri) diff --git a/docgen.lisp b/docgen.lisp index 49b0d34..1414ab3 100644 --- a/docgen.lisp +++ b/docgen.lisp @@ -2,13 +2,17 @@ (in-package #:argot) +(defun rule-name-string (rulename) + (let ((str (symbol-name rulename))) + (nstring-downcase (subseq str 1 (1- (length str)))))) + (defun write-rule-doc (lhs pattern) - (format *standard-output* "~15s ::= " lhs) + (format *standard-output* "~15a ::= " (rule-name-string lhs)) (write-pattern-doc pattern)) -(defun write-sequence-doc (args ) +(defun write-sequence-doc (args) (loop :for (a . more) :on args - :do (write-pattern-doc a ) + :do (write-pattern-doc a) (when more (princ " " )))) @@ -36,26 +40,32 @@ (defun write-grammar-pattern-doc (grammar-name) (princ "{") (princ grammar-name) (princ "}")) +(defun write-literal (object) + (format *standard-output* "'~a'" (write-to-string object))) + (defun write-pattern-doc (pattern) (cond ((nonterminal? pattern) - (princ pattern)) + (format *standard-output* "~a" (rule-name-string pattern))) ((atom pattern) - (princ "'") (princ pattern) (princ "'")) + (write-literal pattern)) (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))) + (:seq (write-sequence-doc args)) + (:seq= (write-sequence-doc args )) + (:? (write-optional-doc (first args))) + (:?= (write-optional-doc (first args) )) + (:* (write-kleene-doc (first args))) + (:*= (write-kleene-doc (first args) )) + (:+ (write-one-or-more-doc (first args))) + (:+= (write-one-or-more-doc (first args) )) + (:or (write-alternatives-doc args)) + (:or= (write-alternatives-doc args )) + (:= (print-literal (first args))) (:@ (write-pattern-doc (second args))) (:{} (write-grammar-pattern-doc (first args))) - - (:item (princ "::TOKEN::")) - (:eof (princ "::EOF::"))))))) + (:item (princ "token")) + (:eof (princ "eof"))))))) |