diff options
Diffstat (limited to '')
-rw-r--r-- | src/lang/parser.clj | 12 |
1 files changed, 12 insertions, 0 deletions
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])) |