diff options
author | colin <colin@cicadas.surf> | 2023-08-08 07:03:48 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-08-08 07:03:48 -0700 |
commit | 2cdb3b48802d904fe5ed85235fcd5bb3d58be15a (patch) | |
tree | f572bc736f155430feb136bb9e19044a4cefa7bd /argot.lisp | |
parent | 0ed3ee0fe326c5259effa1456ac58e0d26e38c4b (diff) |
Removed dependency on trivia
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) |