diff options
Diffstat (limited to 'argot.lisp')
-rw-r--r-- | argot.lisp | 35 |
1 files changed, 12 insertions, 23 deletions
@@ -57,29 +57,18 @@ and it returns VAR in that case." (collect-vars (cdr pat)))))) (defun parse-rule-def (ruledef) - (handler-case - (ematch ruledef - ((guard (list lhs :match pattern) - (and (nonterminal? lhs) (pattern? pattern))) - (list lhs pattern (collect-vars pattern) nil nil)) - - ((guard (list lhs :match pattern :if check) - (and (nonterminal? lhs) (pattern? pattern))) - (list lhs pattern (collect-vars pattern) check nil)) - - ((guard (list lhs :match pattern :then action) - (and (nonterminal? lhs) (pattern? pattern))) - (list lhs pattern (collect-vars pattern) nil action)) - - ((guard (list lhs :match pattern :then action :if check) - (and (nonterminal? lhs) (pattern? pattern))) - (list lhs pattern (collect-vars pattern) check action)) - - ((guard (list lhs :match pattern :if check :then action) - (and (nonterminal? lhs) (pattern? pattern))) - (list lhs pattern (collect-vars pattern) check action))) - (trivia::match-error () - (error 'invalid-rule-def :rule ruledef)))) + (unless (consp ruledef) + (error 'invalid-rule-def :rule ruledef)) + + (destructuring-bind (lhs . options) ruledef + (let ((pattern (getf options :match)) + (check (getf options :if)) + (action (getf options :then)) + (doc (getf options :doc))) + (unless (and (nonterminal? lhs) (pattern? pattern)) + (error 'invalid-rule-def :rule ruledef)) + (list lhs pattern (collect-vars pattern) check action doc)))) + (defun function-form-p (s) (or (functionp s) |