diff --git a/huia-compiler/src/lib.rs b/huia-compiler/src/lib.rs index e69de29..5b6c825 100644 --- a/huia-compiler/src/lib.rs +++ b/huia-compiler/src/lib.rs @@ -0,0 +1 @@ +mod ir; diff --git a/huia-parser/src/ast/mod.rs b/huia-parser/src/ast/mod.rs index 09a8736..e8d5d23 100644 --- a/huia-parser/src/ast/mod.rs +++ b/huia-parser/src/ast/mod.rs @@ -7,7 +7,7 @@ mod integer; mod local; mod string; mod term; -mod typename; +mod ty; mod unary; pub use atom::Atom; @@ -19,7 +19,7 @@ pub use integer::Integer; pub use local::Local; pub use string::String; pub use term::{NodeType, Term}; -pub use typename::Type; +pub use ty::Ty; pub use unary::Unary; use crate::input_location::InputLocation; diff --git a/huia-parser/src/ast/term.rs b/huia-parser/src/ast/term.rs index a2e230f..3ee7652 100644 --- a/huia-parser/src/ast/term.rs +++ b/huia-parser/src/ast/term.rs @@ -23,7 +23,7 @@ pub enum NodeType { Binary, Boolean, Call, - Type, + Ty, Constructor, Declaration, Definition, @@ -43,8 +43,8 @@ enum Inner { Binary(Binary, Box, Box), Boolean(Boolean), Call(Identifier, Vec), - Type(Type), - Constructor(Type, Vec<(Identifier, Term)>), + Ty(Ty), + Constructor(Ty, Vec<(Identifier, Term)>), Declaration(Identifier, Box), Definition( Identifier, @@ -91,7 +91,7 @@ impl Term { Inner::Boolean(_) => NodeType::Boolean, Inner::Binary(_, _, _) => NodeType::Binary, Inner::Call(_, _) => NodeType::Call, - Inner::Type(_) => NodeType::Type, + Inner::Ty(_) => NodeType::Ty, Inner::Constructor(_, _) => NodeType::Constructor, Inner::Definition(_, _, _, _, _) => NodeType::Definition, Inner::Declaration(_, _) => NodeType::Declaration, @@ -140,16 +140,16 @@ impl Term { } } - pub fn typename(&self) -> Option<&Type> { + pub fn ty(&self) -> Option<&Ty> { match self.inner { - Inner::Type(ref node) => Some(node), + Inner::Ty(ref node) => Some(node), _ => None, } } - pub fn constructor(&self) -> Option<(&Type, &Vec<(Identifier, Term)>)> { + pub fn constructor(&self) -> Option<(&Ty, &Vec<(Identifier, Term)>)> { match self.inner { - Inner::Constructor(ref typename, ref properties) => Some((typename, properties)), + Inner::Constructor(ref ty, ref properties) => Some((ty, properties)), _ => None, } } @@ -282,11 +282,11 @@ impl<'a> From> for Term { } Rule::typename => Term { location: InputLocation::from(pair.clone()), - inner: Inner::Type(Type::from(pair)), + inner: Inner::Ty(Ty::from(pair)), }, Rule::constructor => { let mut inner = pair.clone().into_inner(); - let typename = Type::from(inner.next().unwrap()); + let ty = Ty::from(inner.next().unwrap()); let mut properties = Vec::new(); for property in inner { @@ -303,7 +303,7 @@ impl<'a> From> for Term { Term { location: InputLocation::from(pair), - inner: Inner::Constructor(typename, properties), + inner: Inner::Constructor(ty, properties), } } Rule::declaration => { @@ -570,8 +570,8 @@ mod test { #[test] fn test_typename() { let terms = Term::input("Marty").unwrap(); - assert_eq!(terms[0].node_type(), NodeType::Type); - let term = terms[0].typename().unwrap().clone(); + assert_eq!(terms[0].node_type(), NodeType::Ty); + let term = terms[0].ty().unwrap().clone(); assert_eq!(term.value(), "Marty"); } @@ -579,16 +579,16 @@ mod test { fn test_constructor_empty() { let terms = Term::input("Character {}").unwrap(); assert_eq!(terms[0].node_type(), NodeType::Constructor); - let (typename, properties) = terms[0].constructor().unwrap(); - assert_eq!(typename.value_ref(), "Character"); + let (ty, properties) = terms[0].constructor().unwrap(); + assert_eq!(ty.value_ref(), "Character"); assert_eq!(properties.len(), 0); } #[test] fn test_constructor() { let terms = Term::input("Character { name: \"Marty McFly\" }").unwrap(); - let (typename, properties) = terms[0].constructor().unwrap(); - assert_eq!(typename.value_ref(), "Character"); + let (ty, properties) = terms[0].constructor().unwrap(); + assert_eq!(ty.value_ref(), "Character"); assert_eq!(properties.len(), 1); let (key, value) = &properties[0]; assert_eq!(key.value_ref(), "name"); @@ -602,12 +602,12 @@ mod test { let (deftype, defname, args, body, _reqs) = terms[0].definition().unwrap(); assert_eq!(deftype.value_ref(), "type"); - assert_eq!(defname.typename().unwrap().value_ref(), "Delorean"); + assert_eq!(defname.ty().unwrap().value_ref(), "Delorean"); let (argname, argvalue) = &args[0]; assert_eq!(argname.value_ref(), "speed"); - assert_eq!(argvalue.typename().unwrap().value_ref(), "Integer"); + assert_eq!(argvalue.ty().unwrap().value_ref(), "Integer"); let (argname, argvalues) = &body[0]; assert_eq!(argname.value_ref(), "do"); @@ -621,7 +621,7 @@ mod test { let terms = Term::input("type Delorean").unwrap(); let (deftype, defname, args, body, _reqs) = terms[0].definition().unwrap(); assert_eq!(deftype.value_ref(), "type"); - assert_eq!(defname.typename().unwrap().value_ref(), "Delorean"); + assert_eq!(defname.ty().unwrap().value_ref(), "Delorean"); assert_eq!(args.len(), 0); assert_eq!(body.len(), 0); } @@ -654,7 +654,7 @@ mod test { assert_eq!(defname.atom().unwrap().value_ref(), "example"); assert_eq!(args.len(), 2); assert_eq!(body.len(), 1); - assert_eq!(reqs.unwrap().typename().unwrap().value_ref(), "Integer"); + assert_eq!(reqs.unwrap().ty().unwrap().value_ref(), "Integer"); } #[test] @@ -662,15 +662,15 @@ mod test { let terms = Term::input("trait Integer: Add + Subtract").unwrap(); let (deftype, defname, args, body, reqs_option) = terms[0].definition().unwrap(); assert_eq!(deftype.value_ref(), "trait"); - assert_eq!(defname.typename().unwrap().value_ref(), "Integer"); + assert_eq!(defname.ty().unwrap().value_ref(), "Integer"); assert_eq!(args.len(), 0); assert_eq!(body.len(), 0); let reqs = reqs_option.unwrap(); let (op, lhs, rhs) = reqs.binary().unwrap(); assert_eq!(op.value_ref(), &binary::Operator::Plus); - assert_eq!(lhs.typename().unwrap().value_ref(), "Add"); - assert_eq!(rhs.typename().unwrap().value_ref(), "Subtract"); + assert_eq!(lhs.ty().unwrap().value_ref(), "Add"); + assert_eq!(rhs.ty().unwrap().value_ref(), "Subtract"); } #[test] @@ -791,7 +791,7 @@ mod test { let terms = Term::input("My.Greeter.hello()").unwrap(); let (method_name, receiver, arguments) = terms[0].method_call().unwrap(); assert_eq!(method_name.value_ref(), "hello"); - assert_eq!(receiver.typename().unwrap().value_ref(), "My.Greeter"); + assert_eq!(receiver.ty().unwrap().value_ref(), "My.Greeter"); assert_eq!(arguments.len(), 0); } diff --git a/huia-parser/src/ast/typename.rs b/huia-parser/src/ast/ty.rs similarity index 82% rename from huia-parser/src/ast/typename.rs rename to huia-parser/src/ast/ty.rs index f9d4688..4caacde 100644 --- a/huia-parser/src/ast/typename.rs +++ b/huia-parser/src/ast/ty.rs @@ -4,18 +4,18 @@ use crate::input_location::InputLocation; use pest::iterators::Pair; #[derive(Debug, Clone)] -pub struct Type { +pub struct Ty { value: String, location: InputLocation, } -impl Type { +impl Ty { pub fn value(&self) -> &str { &self.value } } -impl Value for Type { +impl Value for Ty { type Item = String; fn value(self) -> Self::Item { @@ -27,23 +27,23 @@ impl Value for Type { } } -impl Location for Type { +impl Location for Ty { fn location(&self) -> &InputLocation { &self.location } } -impl<'a> From> for Type { +impl<'a> From> for Ty { fn from(pair: Pair<'a, Rule>) -> Self { match pair.as_rule() { Rule::typename => { let value = pair.clone().into_span().as_str().to_string(); - Type { + Ty { value: value, location: InputLocation::from(pair.into_span()), } } - _ => unreachable!("Expected pair to be a Type"), + _ => unreachable!("Expected pair to be a Ty"), } } } @@ -60,7 +60,7 @@ mod test { .unwrap() .next() .unwrap(); - let r#type = Type::from(pair); + let r#type = Ty::from(pair); assert_eq!(r#type.value(), "Marty.McFly"); } }