diff options
-rw-r--r-- | README.org | 14 | ||||
-rw-r--r-- | argot.lisp | 19 | ||||
-rw-r--r-- | examples/calc.lisp | 4 | ||||
-rw-r--r-- | grammars.lisp | 2 |
4 files changed, 23 insertions, 16 deletions
@@ -21,10 +21,12 @@ In ~/examples/calc.lisp~ you see the following ~deflanguage~: (<expr> :match (:or <subexpr> <value> <unop> <binop>)) (<subexpr> - :match (:{} calc)) + :match (:{} calc) + :doc "A subexpression, like (1 + 2 / cos(1.5))") (<value> :match (:item) - :if numberp) + :if numberp + :doc "A Number") (<binop> :match (:seq (:@ lhs <expr>) @@ -75,7 +77,11 @@ Function: <VALUE> ::= ::TOKEN:: <BINOP> ::= <EXPR> ('+' | '-' | '/' | '*' | '^' | '%') <EXPR>+ <UNOP> ::= ('SIN' | 'COS' | 'TAN' | '-') <EXPR> - +------------------------------------------ +ADDITIONAL NOTES: +<SUBEXPR> A subexpression, like (1 + 2 / cos(1.5)) +<VALUE> A Number +------------------------------------------ KEY: ::TOKEN:: Any ole token ::EOF:: Explicitly match the end of the input @@ -213,3 +219,5 @@ clause, it can be either a function designator or an arbitrary expression. When ~<rule3>~ succeeds, it returns a list of two values. +*** Additional Docstrings + @@ -68,10 +68,10 @@ and it returns VAR in that case." (let ((pattern (getf options :match)) (check (getf options :if)) (action (getf options :then)) - (doc (getf options :doc))) + (note (getf options :note))) (unless (and (nonterminal? lhs) (pattern? pattern)) (error 'invalid-rule-def :rule ruledef)) - (list lhs pattern (collect-vars pattern) check action doc)))) + (list lhs pattern (collect-vars pattern) check action note)))) (defun function-form-p (s) @@ -104,13 +104,13 @@ and it returns VAR in that case." (let ,bindings (declare (ignorable ,lhs ,@vars)) ,action)))))) - (rule-includer (name lhs pattern &optional check action bindings vars doc) + (rule-includer (name lhs pattern &optional check action bindings vars note) `(include-rule (get ',name 'argot::grammar-property) (make-rule :lhs ',lhs :pattern ',pattern - :doc ,doc + :note ,note ,@(expand-functional-argument :check lhs bindings check vars) ,@(expand-functional-argument :action lhs bindings action vars))))) (let* ((parsed-rules @@ -118,9 +118,9 @@ and it returns VAR in that case." :collect (handler-case (parse-rule-def ruledef) (invalid-rule-def (e) (invoke-debugger e))))) (rule-adder-forms - (loop :for (lhs pattern vars check action doc) :in parsed-rules + (loop :for (lhs pattern vars check action note) :in parsed-rules :for bindings := (collect-let-bindings lhs vars) - :collect (rule-includer name lhs pattern check action bindings vars doc))) + :collect (rule-includer name lhs pattern check action bindings vars note))) (docstring (with-output-to-string (*standard-output*) (princ documentation) @@ -133,13 +133,12 @@ and it returns VAR in that case." (terpri) (princ "ADDITIONAL NOTES:") (terpri) - (loop :for (lhs _p _v _c _a doc) :in parsed-rules + (loop :for (lhs _p _v _c _a note) :in parsed-rules ;:for lhs-name := (symbol-name lhs) - :when doc + :when note :do (format *standard-output* "~15a ~a~%" lhs - ;(subseq lhs-name 1 (1- (length lhs-name))) - doc)) + note)) (princ "------------------------------------------") (terpri) (princ "KEY: ") (terpri) diff --git a/examples/calc.lisp b/examples/calc.lisp index 0a25a6b..fc9e854 100644 --- a/examples/calc.lisp +++ b/examples/calc.lisp @@ -17,11 +17,11 @@ :match (:or <subexpr> <value> <unop> <binop>)) (<subexpr> :match (:{} calc) - :doc "A subexpression, like (1 + 2 / cos(1.5))") + :note "A subexpression, like (1 + 2 / cos(1.5))") (<value> :match (:item) :if numberp - :doc "A Number") + :note "A Number") (<binop> :match (:seq (:@ lhs <expr>) diff --git a/grammars.lisp b/grammars.lisp index c9a1c55..54505b7 100644 --- a/grammars.lisp +++ b/grammars.lisp @@ -4,7 +4,7 @@ ;;; GRAMMAR & RULES -(defstruct rule lhs pattern action check doc) +(defstruct rule lhs pattern action check note) (defclass grammar () ((rules |