From 1a2b6841604558266f2cbf5bcf1373ea257183c9 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 27 Nov 2014 02:03:19 -0400 Subject: + Added some very basic pattern-matching with destructuring. --- src/lang/parser.clj | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/lang/parser.clj') diff --git a/src/lang/parser.clj b/src/lang/parser.clj index 985a17861..53f60941d 100644 --- a/src/lang/parser.clj +++ b/src/lang/parser.clj @@ -57,6 +57,17 @@ =else (apply-m parse-form (list ?else))] (return [::if =test =then =else]))) +(defparser ^:private parse-case + [::&lexer/list ([[::&lexer/ident "case"] ?variant & cases] :seq)] + (exec [=variant (apply-m parse-form (list ?variant)) + =branches (do (assert (even? (count cases))) + (map-m (fn [[destruct expr]] + (exec [=destruct (apply-m parse-form (list destruct)) + =expr (apply-m parse-form (list expr))] + (return [::case-branch =destruct =expr]))) + (partition 2 cases)))] + (return [::case =variant =branches]))) + (defparser ^:private parse-tagged [::&lexer/list ([[::&lexer/tag ?tag] ?data] :seq)] (exec [=data (apply-m parse-form (list ?data))] @@ -76,6 +87,7 @@ parse-def parse-defdata parse-if + parse-case parse-tagged parse-fn-call])) -- cgit v1.2.3