From e8dfcee463d771c21c513dea4af30c5c51a2525e Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 29 Jul 2023 09:19:39 -0700 Subject: more of the same --- argot.lisp | 10 +++++----- examples/calc.lisp | 38 +++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/argot.lisp b/argot.lisp index 99da9bd..4c1dfdc 100644 --- a/argot.lisp +++ b/argot.lisp @@ -72,23 +72,23 @@ and it returns VAR in that case." (defun parse-rule-def (ruledef) (handler-case (ematch ruledef - ((guard (list lhs :-> pattern) + ((guard (list lhs :match pattern) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) nil nil)) - ((guard (list lhs :-> pattern :if check) + ((guard (list lhs :match pattern :if check) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) check nil)) - ((guard (list lhs :-> pattern :then action) + ((guard (list lhs :match pattern :then action) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) nil action)) - ((guard (list lhs :-> pattern :then action :if check) + ((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 :-> pattern :if check :then 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 () diff --git a/examples/calc.lisp b/examples/calc.lisp index 7b2f9ef..4d8766a 100644 --- a/examples/calc.lisp +++ b/examples/calc.lisp @@ -6,21 +6,29 @@ (in-package #:argot.examples.calc) (deflanguage calc (:documentation "A calculator language") - ( :-> (:or - (:seq (:eof)) - (:seq (:eof)) - (:seq (:eof)) - (:seq (:eof))) - :then car) - ( :-> (:or )) - ( :-> (:item) - :if listp - :then (argot:parse calc )) - ( :-> (:item) :if numberp) - ( :-> (:seq (:@ lhs ) - (:@ rhs (:+ (:seq (:or= + - / * ^ %) )))) - :then (expand-binop lhs rhs)) - ( :-> (:seq (:or= sin cos tan -) ))) + ( + :match (:or + (:seq (:eof)) + (:seq (:eof)) + (:seq (:eof)) + (:seq (:eof))) + :then car) + ( + :match (:or )) + ( + :match (:item) + :if listp + :then (argot:parse calc )) + ( + :match (:item) + :if numberp) + ( + :match (:seq + (:@ lhs ) + (:@ rhs (:+ (:seq (:or= + - / * ^ %) )))) + :then (expand-binop lhs rhs)) + ( + :match (:seq (:or= sin cos tan -) ))) (defun lassoc? (op) -- cgit v1.2.3