From 24b48551dc07fcbac70dc24a82bc010f5db28c92 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 9 Oct 2019 02:32:41 -0700 Subject: [PATCH] More playing around with syntax for if --- TODO.md | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 953dfef..8bd0d73 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ # TODO items ## General code cleanup --experiment with storing metadata via ItemIds on AST nodes (cf. https://rust-lang.github.io/rustc-guide/hir.html, https://github.com/rust-lang/rust/blob/master/src/librustc/hir/mod.rs ) +DONE -experiment with storing metadata via ItemIds on AST nodes (cf. https://rust-lang.github.io/rustc-guide/hir.html, https://github.com/rust-lang/rust/blob/master/src/librustc/hir/mod.rs ) -implement and test open/use statements -implement field access - standardize on an error type that isn't String @@ -76,10 +76,43 @@ ex. -consult http://gluon-lang.org/book/embedding-api.html +## Trying if-syntax again -## Playing around with conditional syntax ideas +//simple if expr +if x == 10 then "a" else "z" + +//complex if expr +if x == 10 then { + let a = 1 + let b = 2 + a + b +} else { + 55 +} + +// different comparison ops +if x { + == 1 then "a" + .isPrime() then "b" + else "c" +} + +/* for now disallow `if x == { 1 then ... }`, b/c hard to parse + +//simple pattern-matching +if x is Person("Ivan", age) then age else 0 + +//match-block equivalent +if x { + is Person("Ivan", _) then "Ivan" + is Person(_, age) if age > 13 then "barmitzvah'd" + else "foo" + } + + + +## (OLD) Playing around with conditional syntax ideas -- - if/match playground