aboutsummaryrefslogtreecommitdiff
path: root/argot.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'argot.lisp')
-rw-r--r--argot.lisp41
1 files changed, 26 insertions, 15 deletions
diff --git a/argot.lisp b/argot.lisp
index 2218dd5..f394e2a 100644
--- a/argot.lisp
+++ b/argot.lisp
@@ -118,21 +118,32 @@ and it returns VAR in that case."
:lhs ',lhs
:pattern ',pattern
,@(expand-functional-argument :check lhs bindings check vars)
- ,@(expand-functional-argument :action lhs bindings action vars)))))
- `(progn
- (defvar ,name nil)
- (setf ,name (make-instance 'grammar
- :documentation ,documentation
- :start-rule ',(first (first ruledefs))))
- ,@(loop
- :for ruledef :in ruledefs
- :for (lhs pattern vars check action) := (handler-case (parse-rule-def ruledef)
- (invalid-rule-def (e) (invoke-debugger e)))
- :for bindings := (collect-let-bindings lhs vars)
- :collect (rule-includer name lhs pattern check action bindings vars))
-
- (defmacro ,name (&body tokens)
- (argot:parse ,name tokens))))))
+ ,@(expand-functional-argument :action lhs bindings action vars)))))
+ (let* ((parsed-rules
+ (loop :for ruledef :in ruledefs
+ :collect (handler-case (parse-rule-def ruledef)
+ (invalid-rule-def (e) (invoke-debugger e)))))
+ (rule-adder-forms
+ (loop :for (lhs pattern vars check action) :in parsed-rules
+ :for bindings := (collect-let-bindings lhs vars)
+ :collect (rule-includer name lhs pattern check action bindings vars)))
+ (docstring
+ (with-output-to-string (*standard-output*)
+ (princ documentation)
+ (terpri) (terpri)
+ (loop :for (lhs pattern . more) :in parsed-rules
+ :do (write-rule-doc lhs pattern)
+ (terpri)))))
+ `(progn
+ (defvar ,name nil)
+ (setf ,name (make-instance 'grammar
+ :documentation ,documentation
+ :start-rule ',(first (first ruledefs))))
+ ,@rule-adder-forms
+
+ (defmacro ,name (&body tokens)
+ ,docstring
+ (argot:parse ,name tokens)))))))