aboutsummaryrefslogtreecommitdiff
path: root/argot.lisp
diff options
context:
space:
mode:
authorcolin <colin@cicadas.surf>2023-07-19 06:15:21 -0700
committercolin <colin@cicadas.surf>2023-07-19 06:15:21 -0700
commit5cd0bbe5ff4d571ef51645210e490e7613dcb8f2 (patch)
tree6b9eb2f97d278359ce336a41aaa67902683f344a /argot.lisp
parenta2f6e93519695cc145539049af60d3e41ec52fad (diff)
Add: Rule parse result transforms
Diffstat (limited to 'argot.lisp')
-rw-r--r--argot.lisp12
1 files changed, 6 insertions, 6 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)))