diff options
author | Eduardo Julian | 2017-05-19 23:54:16 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-05-19 23:54:16 -0400 |
commit | b81f241bd90092f52a47f64f4dc8297cc4f82f56 (patch) | |
tree | a07f20ec91597ca98e66833e14c42accf6b169f7 /new-luxc/source/luxc/analyser.lux | |
parent | a73037f8ab46e31196b1257d7621ceeacb1cad38 (diff) |
- WIP: Added pattern-matching (case) analysis.
Diffstat (limited to 'new-luxc/source/luxc/analyser.lux')
-rw-r--r-- | new-luxc/source/luxc/analyser.lux | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/new-luxc/source/luxc/analyser.lux b/new-luxc/source/luxc/analyser.lux index eba8ae62a..d8f5abe9b 100644 --- a/new-luxc/source/luxc/analyser.lux +++ b/new-luxc/source/luxc/analyser.lux @@ -19,9 +19,23 @@ ["&&;" reference] ["&&;" type] ["&&;" struct] - ## ["&&;" case] + ["&&;" case] ["&&;" proc])) +(def: (to-branches raw) + (-> (List Code) (Lux (List [Code Code]))) + (case raw + (^ (list)) + (:: Monad<Lux> wrap (list)) + + (^ (list& patternH bodyH inputT)) + (do Monad<Lux> + [outputT (to-branches inputT)] + (wrap (list& [patternH bodyH] outputT))) + + _ + (&;fail "Uneven expressions for pattern-matching."))) + (def: #export (analyser eval) (-> &;Eval &;Analyser) (: (-> Code (Lux la;Analysis)) @@ -67,10 +81,12 @@ [_ (#;Tuple args)]))) (&&proc;analyse-proc analyse proc args) - ## (^ (#;Form (list& [_ (#;Symbol ["" "_lux_case"])] - ## input - ## branches))) - ## (&&case;analyse-case analyse proc branches) + (^ (#;Form (list& [_ (#;Symbol ["" "_lux_case"])] + input + branches))) + (do Monad<Lux> + [paired (to-branches branches)] + (&&case;analyse-case analyse input paired)) (^ (#;Form (list [_ (#;Nat tag)] value))) |