diff options
author | Eduardo Julian | 2014-11-27 02:03:19 -0400 |
---|---|---|
committer | Eduardo Julian | 2014-11-27 02:03:19 -0400 |
commit | 1a2b6841604558266f2cbf5bcf1373ea257183c9 (patch) | |
tree | da5cbb9a4c330a6790a06f0e081784807a496381 /src/lang/parser.clj | |
parent | a96bb768a5f02c2dc9c0de1e50dc14376d2e7f35 (diff) |
+ Added some very basic pattern-matching with destructuring.
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])) |