From 5cd0bbe5ff4d571ef51645210e490e7613dcb8f2 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 19 Jul 2023 06:15:21 -0700 Subject: Add: Rule parse result transforms --- argot.lisp | 12 ++++++------ package.lisp | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/argot.lisp b/argot.lisp index 1f3d5d2..c434778 100644 --- a/argot.lisp +++ b/argot.lisp @@ -217,16 +217,16 @@ any pattern fails the whole parse fails." (defun parse-rule (nonterminal) (if-let (rule (gethash nonterminal *grammar*)) - (try-parse (result) (parse-pattern (rule-pattern rule)) - (if (rule-action rule) - (succeed (funcall (rule-action rule))) - (succeed result))) + (let ((*bindings* nil)) + (try-parse (result) (parse-pattern (rule-pattern rule)) + (if (rule-action rule) + (succeed (funcall (rule-action rule) *bindings*)) + (succeed result)))) (fail))) (defun parse (grammar rule tokens) (let ((*position* 0) (*grammar* grammar) - (*tokens* tokens) - (*bindings* nil)) + (*tokens* tokens)) (parse-rule rule))) diff --git a/package.lisp b/package.lisp index a759685..19880cb 100644 --- a/package.lisp +++ b/package.lisp @@ -3,4 +3,5 @@ (defpackage #:argot (:use #:cl) (:import-from #:trivia #:match #:ematch #:guard) - (:import-from #:alexandria #:if-let)) + (:import-from #:alexandria #:if-let) + (:export #:defgrammar #:parse)) -- cgit v1.2.3