From dd05d7ce2a95bca816f41b504f1752b3994a6592 Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Tue, 15 Sep 2020 15:25:53 +0200
Subject: [PATCH] a small experiment on box

---
 src/ast/ast.rs         | 37 +++++++++++++++++++++++++++++++++++++
 src/ast/main.rs        |  2 ++
 src/ast/parser.lalrpop |  2 +-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/ast/ast.rs b/src/ast/ast.rs
index b750a43..65e3c6b 100644
--- a/src/ast/ast.rs
+++ b/src/ast/ast.rs
@@ -3,3 +3,40 @@ use std::fmt;
 // ast
 
 pub type Id = String;
+
+#[derive(Debug, PartialEq, Clone)]
+pub enum Type {
+    Unit,           // (), // maybe just a special case of tuple, see todo
+    Never,          // !
+    Named(Id),      // `abc`, "ABC", "aB0", etc.
+    Bool,           // bool
+    I32,            // i32
+    Ref(Box<Type>), // & mut? Type    -- used in parser
+    Mut(Box<Type>), // mut Type
+}
+
+fn check(t: Type) {
+    use Type::*;
+    match t {
+        Ref(t) => match &*t {
+            Mut(t) => (),
+            _ => (),
+        },
+        _ => (),
+    }
+}
+
+fn check2(t: Type) {
+    use Type::*;
+    match t {
+        Ref(box Mut(t)) => (),
+        _ => (),
+    }
+}
+
+#[test]
+fn f_test() {
+    use Type::*;
+    let t = Ref(Box::new(Mut(Box::new(I32))));
+    println!("{:?}", t);
+}
diff --git a/src/ast/main.rs b/src/ast/main.rs
index 0eb05e3..e9debaa 100644
--- a/src/ast/main.rs
+++ b/src/ast/main.rs
@@ -1,3 +1,5 @@
+#![feature(box_syntax, box_patterns)]
+
 use lalrpop_util::lalrpop_mod;
 
 lalrpop_mod!(pub parser, "/ast/parser.rs");
diff --git a/src/ast/parser.lalrpop b/src/ast/parser.lalrpop
index 95085a6..955bffe 100644
--- a/src/ast/parser.lalrpop
+++ b/src/ast/parser.lalrpop
@@ -35,7 +35,7 @@ pub Statement: () = {
 
 pub ExpressionStatement: () = {
     ExpressionWithoutBlock ";" => (),
-    ExpressionWithBlock ";"? => ()
+    ExpressionWithBlock ";" => ()
 }
 
 pub Num: i32 = {
-- 
GitLab