Skip to content
Snippets Groups Projects
Commit dd05d7ce authored by Per Lindgren's avatar Per Lindgren
Browse files

a small experiment on box

parent eabfc31b
No related branches found
No related tags found
No related merge requests found
...@@ -3,3 +3,40 @@ use std::fmt; ...@@ -3,3 +3,40 @@ use std::fmt;
// ast // ast
pub type Id = String; 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);
}
#![feature(box_syntax, box_patterns)]
use lalrpop_util::lalrpop_mod; use lalrpop_util::lalrpop_mod;
lalrpop_mod!(pub parser, "/ast/parser.rs"); lalrpop_mod!(pub parser, "/ast/parser.rs");
......
...@@ -35,7 +35,7 @@ pub Statement: () = { ...@@ -35,7 +35,7 @@ pub Statement: () = {
pub ExpressionStatement: () = { pub ExpressionStatement: () = {
ExpressionWithoutBlock ";" => (), ExpressionWithoutBlock ";" => (),
ExpressionWithBlock ";"? => () ExpressionWithBlock ";" => ()
} }
pub Num: i32 = { pub Num: i32 = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment