From 393d9bc3d0609d1d2b2dc891aae4f1142287c2d0 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:42:39 -0700 Subject: [PATCH] Allow parsing of external types declared in stubs for function signatures --- compiler/parser/src/parser/file.rs | 10 +++++----- compiler/parser/src/parser/type_.rs | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index 3282df4132..edbee517bf 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -319,9 +319,9 @@ impl ParserContext<'_> { let external = self.expect_identifier()?; let mut span = name.span + external.span; - // Parse `.leo/`. + // Parse `.leo/` or `.aleo/`. self.eat(&Token::Dot); - self.eat(&Token::Leo); + self.eat_any(&[Token::Leo, Token::Aleo]); self.eat(&Token::Div); // Parse record name. @@ -366,9 +366,9 @@ impl ParserContext<'_> { let external = self.expect_identifier()?; let mut span = external.span; - // Parse `.leo/`. + // Parse `.leo/` or `.aleo/`. self.eat(&Token::Dot); - self.eat(&Token::Leo); + self.eat_any(&[Token::Leo, Token::Aleo]); self.eat(&Token::Div); // Parse record name. @@ -391,7 +391,7 @@ impl ParserContext<'_> { } } - fn peek_is_external(&self) -> bool { + pub fn peek_is_external(&self) -> bool { matches!((&self.token.token, self.look_ahead(1, |t| &t.token)), (Token::Identifier(_), Token::Dot)) } diff --git a/compiler/parser/src/parser/type_.rs b/compiler/parser/src/parser/type_.rs index 9c06ecfff7..560baa9531 100644 --- a/compiler/parser/src/parser/type_.rs +++ b/compiler/parser/src/parser/type_.rs @@ -79,6 +79,17 @@ impl ParserContext<'_> { /// Also returns the span of the parsed token. pub fn parse_type(&mut self) -> Result<(Type, Span)> { if let Some(ident) = self.eat_identifier() { + // Check if using external type + let file_type = self.look_ahead(1, |t| &t.token); + if &self.token.token == &Token::Dot && (file_type == &Token::Leo || file_type == &Token::Aleo) { + return Err(ParserError::external_type_cannot_be_used_inside_function( + ident, + file_type, + self.token.span, + ) + .into()); + } + Ok((Type::Identifier(ident), ident.span)) } else if self.token.token == Token::LeftSquare { // Parse the left bracket.