From 2cdb3b48802d904fe5ed85235fcd5bb3d58be15a Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 8 Aug 2023 07:03:48 -0700 Subject: Removed dependency on trivia --- argot.lisp | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'argot.lisp') diff --git a/argot.lisp b/argot.lisp index 1eb7fc5..f79e2ed 100644 --- a/argot.lisp +++ b/argot.lisp @@ -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) -- cgit v1.2.3