Skip to content

Commit

Permalink
WIP: add support for the move type modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickpeterse committed Nov 30, 2023
1 parent aa615ed commit 6191607
Show file tree
Hide file tree
Showing 40 changed files with 755 additions and 354 deletions.
2 changes: 2 additions & 0 deletions ast/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ pub enum Type {
Ref(Box<ReferenceType>),
Mut(Box<ReferenceType>),
Uni(Box<ReferenceType>),
Owned(Box<ReferenceType>),
Closure(Box<ClosureType>),
Tuple(Box<TupleType>),
}
Expand All @@ -983,6 +984,7 @@ impl Node for Type {
Type::Ref(ref typ) => typ.location(),
Type::Mut(ref typ) => typ.location(),
Type::Uni(ref typ) => typ.location(),
Type::Owned(ref typ) => typ.location(),
Type::Closure(ref typ) => typ.location(),
Type::Tuple(ref typ) => typ.location(),
}
Expand Down
25 changes: 25 additions & 0 deletions ast/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ impl Parser {
TokenKind::Fn => Type::Closure(Box::new(self.closure_type(start)?)),
TokenKind::Ref => Type::Ref(Box::new(self.reference_type(start)?)),
TokenKind::Mut => Type::Mut(Box::new(self.reference_type(start)?)),
TokenKind::Move => {
Type::Owned(Box::new(self.reference_type(start)?))
}
TokenKind::Uni => Type::Uni(Box::new(self.reference_type(start)?)),
TokenKind::ParenOpen => {
Type::Tuple(Box::new(self.tuple_type(start)?))
Expand Down Expand Up @@ -3879,6 +3882,28 @@ mod tests {
);
}

#[test]
fn test_type_reference_with_owned_reference_type() {
let mut parser = parser("move A");
let start = parser.require().unwrap();

assert_eq!(
parser.type_reference(start).unwrap(),
Type::Owned(Box::new(ReferenceType {
type_reference: ReferrableType::Named(Box::new(TypeName {
name: Constant {
source: None,
name: "A".to_string(),
location: cols(6, 6),
},
arguments: None,
location: cols(6, 6)
})),
location: cols(1, 6)
}))
);
}

#[test]
fn test_type_reference_with_double_reference() {
let mut parser = parser("ref ref A");
Expand Down
Loading

0 comments on commit 6191607

Please sign in to comment.