From 5484d96e7db451eb424eb5a57fc2c229fbcab686 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 27 Feb 2024 22:48:24 -0600 Subject: [PATCH] ast: Add the "Self" type in preparation for cl-typeck --- libconlang/src/ast.rs | 1 + libconlang/src/ast/ast_impl.rs | 1 + libconlang/src/parser.rs | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/libconlang/src/ast.rs b/libconlang/src/ast.rs index 2e4029e..3e14fa5 100644 --- a/libconlang/src/ast.rs +++ b/libconlang/src/ast.rs @@ -187,6 +187,7 @@ pub struct Ty { pub enum TyKind { Never, Empty, + SelfTy, Path(Path), Tuple(TyTuple), Ref(TyRef), diff --git a/libconlang/src/ast/ast_impl.rs b/libconlang/src/ast/ast_impl.rs index ade5220..ea8818d 100644 --- a/libconlang/src/ast/ast_impl.rs +++ b/libconlang/src/ast/ast_impl.rs @@ -214,6 +214,7 @@ mod display { match &self.kind { TyKind::Never => "!".fmt(f), TyKind::Empty => "()".fmt(f), + TyKind::SelfTy => "Self".fmt(f), TyKind::Path(v) => v.fmt(f), TyKind::Tuple(v) => v.fmt(f), TyKind::Ref(v) => v.fmt(f), diff --git a/libconlang/src/parser.rs b/libconlang/src/parser.rs index 8a745f6..6f1b3ba 100644 --- a/libconlang/src/parser.rs +++ b/libconlang/src/parser.rs @@ -676,6 +676,10 @@ impl<'t> Parser<'t> { self.consume_peeked(); TyKind::Never } + Type::Keyword(Keyword::SelfTy) => { + self.consume_peeked(); + TyKind::SelfTy + } Type::Amp | Type::AmpAmp => self.tyref()?.into(), Type::LParen => self.tytuple()?.into(), Type::Keyword(Keyword::Fn) => self.tyfn()?.into(),