diff --git a/Cargo.lock b/Cargo.lock index ea45669892..c8a5345bd7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1538,6 +1538,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "smallvec", "tendril", "tracing", ] diff --git a/parser/Cargo.toml b/parser/Cargo.toml index e16765ebcf..e96457c567 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -23,6 +23,9 @@ name = "leo_ast" path = "benches/leo_ast.rs" harness = false +[dependencies] +smallvec = "1.8" + [dependencies.leo-ast] path = "../ast" version = "1.5.3" diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 79c6e020d0..137e171ac3 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -403,7 +403,7 @@ impl ParserContext<'_> { /// circuit initialization expression. pub fn parse_circuit_expression(&mut self, identifier: Identifier) -> Result { let (members, _, span) = self.parse_list(Token::LeftCurly, Token::RightCurly, Token::Comma, |p| { - Ok(Some(CircuitImpliedVariableDefinition { + Ok(Some(CircuitVariableInitializer { identifier: p.expect_ident()?, expression: p.eat(Token::Colon).map(|_| p.parse_expression()).transpose()?, })) diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 7902ed5807..4e740a3fba 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -559,19 +559,12 @@ impl ParserContext<'_> { /// const definition statement and assignment. /// pub fn parse_type_alias(&mut self) -> Result<(Identifier, Alias)> { - self.expect(Token::Type)?; + let start = self.expect(Token::Type)?; let name = self.expect_ident()?; self.expect(Token::Assign)?; - let (type_, _) = self.parse_type()?; - self.expect(Token::Semicolon)?; + let (represents, _) = self.parse_type()?; + let span = start + self.expect(Token::Semicolon)?; - Ok(( - name.clone(), - Alias { - represents: type_, - span: name.span.clone(), - name, - }, - )) + Ok((name.clone(), Alias { represents, span, name })) } } diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index 9c73c00a21..37470530ce 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -17,6 +17,8 @@ use super::*; use leo_errors::{ParserError, Result}; +use smallvec::smallvec; + pub(crate) const TYPE_TOKENS: &[Token] = &[ Token::I8, Token::I16, @@ -58,7 +60,7 @@ impl ParserContext<'_> { /// Returns an [`ArrayDimensions`] AST node if the next tokens represent dimensions for an array type. pub fn parse_array_dimensions(&mut self) -> Result { Ok(if let Some(dim) = self.parse_array_dimension() { - dim + ArrayDimensions(smallvec![dim]) } else { let mut had_item_err = false; let (dims, _, span) = self.parse_paren_comma_list(|p| { @@ -74,16 +76,16 @@ impl ParserContext<'_> { if dims.is_empty() && !had_item_err { self.emit_err(ParserError::array_tuple_dimensions_empty(&span)); } - ArrayDimensions::Multi(dims) + ArrayDimensions(dims.into()) }) } /// Parses a basic array dimension, i.e., an integer or `_`. - fn parse_array_dimension(&mut self) -> Option { + fn parse_array_dimension(&mut self) -> Option { if let Some((int, _)) = self.eat_int() { - Some(ArrayDimensions::Number(int)) + Some(Dimension::Number(int)) } else if self.eat(Token::Underscore).is_some() { - Some(ArrayDimensions::Unspecified) + Some(Dimension::Unspecified) } else { None }