From d8dd5ad710e84e8f90d8bd945dc12e40f18ed9ba Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Mon, 21 Sep 2020 20:40:04 +0200
Subject: [PATCH] move to new syntax, wip2

---
 examples/wip.rs     |  3 +++
 src/grammar.lalrpop | 40 ++++++++++++++++++++++++++--------------
 tests/test_check.rs |  5 +++++
 3 files changed, 34 insertions(+), 14 deletions(-)
 create mode 100644 examples/wip.rs

diff --git a/examples/wip.rs b/examples/wip.rs
new file mode 100644
index 0000000..4e7015b
--- /dev/null
+++ b/examples/wip.rs
@@ -0,0 +1,3 @@
+fn main() {
+    a;
+}
diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop
index c5239ea..ed7149e 100644
--- a/src/grammar.lalrpop
+++ b/src/grammar.lalrpop
@@ -149,11 +149,23 @@ Type : Type = {
 // }
 
 pub Block: Stmts = {
-    "{" <Stmt*> "}" => Stmts { stmts: <>, ret: false },
+    "{" <sts: StmtSeq*> <st: Stmt?> "}" 
+        => Stmts { stmts: sts, ret: false },
 }
 
-// pub Stmt: () = {
-//     ";" => (),
+StmtSeq: Stmt = {
+    <Stmt> ";" => <>,
+    StmtBlock => panic!(),
+}
+
+StmtBlock: Stmts = {
+    "while" Expr Block => panic!(),
+    "if" Expr Block ("else" Block)? => panic!(),
+    Block  => panic!(),
+}
+
+// Stmt: Stmt = {
+    //  ";" => Stmt::Semi,
 //     "let" "mut"? Id "=" Expr ";" => (),
 //     ExprNoBlock "=" Expr => (),
 //     "while" Expr Block => (),
@@ -166,7 +178,7 @@ pub Block: Stmts = {
 
 
 
-Stmt : Stmt = {
+Stmt: Stmt = {
     ";" => Stmt::Semi,
     //"let" <m: "mut"?> <id: Id> <t: (":" <Type>)?> <e: ("=" <Expr>)?>  => Stmt::Let(id, m.is_some(), t, e),
     // <Expr> "=" <Expr> => Stmt::Assign(<>),
@@ -238,16 +250,16 @@ MulDivOp: Op = {
 
 Term: Box<Expr> = {
     Num => Box::new(Expr::Num(<>)),
-    // "true" => Box::new(Expr::Bool(true)),
-    // "false" => Box::new(Expr::Bool(false)),
-    // <Id> <Exprs> => Box::new(Expr::Call(<>)),
-    // Id => Box::new(Expr::Id(<>)),
-    // AddSubOp Term => Box::new(Expr::Prefix(<>)),
-    // "!" <Term> => Box::new(Expr::Prefix(Op::Not, <>)),
-    // "&" <Term> => Box::new(Expr::Ref(<>)),
-    // "&" "mut" <Term> => Box::new(Expr::RefMut(<>)),
-    // "*" <Term> => Box::new(Expr::DeRef(<>)),
-    // "(" <Expr> ")"
+    "true" => Box::new(Expr::Bool(true)),
+    "false" => Box::new(Expr::Bool(false)),
+    <Id> <Exprs> => Box::new(Expr::Call(<>)),
+    Id => Box::new(Expr::Id(<>)),
+    AddSubOp Term => Box::new(Expr::Prefix(<>)),
+    "!" <Term> => Box::new(Expr::Prefix(Op::Not, <>)),
+    "&" <Term> => Box::new(Expr::Ref(<>)),
+    "&" "mut" <Term> => Box::new(Expr::RefMut(<>)),
+    "*" <Term> => Box::new(Expr::DeRef(<>)),
+    "(" <Expr> ")" => <>,
 };
 
 Num: i32 = {
diff --git a/tests/test_check.rs b/tests/test_check.rs
index 38dc8f2..7695ee4 100644
--- a/tests/test_check.rs
+++ b/tests/test_check.rs
@@ -174,3 +174,8 @@ fn check_scopes_err() {
 fn check_let_if() {
     assert!(check(&read_file::parse("examples/let_if.rs")).is_err());
 }
+
+#[test]
+fn wip() {
+    assert!(check(&read_file::parse("examples/wip.rs")).is_err());
+}
-- 
GitLab