Allow parsing of external types declared in stubs for function signatures

This commit is contained in:
evan-schott 2023-10-12 15:42:39 -07:00
parent 61f3d81d13
commit 393d9bc3d0
2 changed files with 16 additions and 5 deletions

View File

@ -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))
}

View File

@ -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.