diff --git a/src/ast/ast.rs b/src/ast/ast.rs index b750a433c98bf8dc9558be9c8da21b57e43e62d2..65e3c6bd51117f6440af5ac612b0502d0b1b43b1 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 0eb05e3ce7421141a341870832239739c2d5d1cd..e9debaa4c6bea0a5327b359c34f8cdacec0a4596 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 95085a640661cfeea82d7a4aed6ad15be0f0f0c0..955bffe9b299d0844d4890628bcb9e67038b0145 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 = {