merge upstream changes from ast and staging

This commit is contained in:
gluax 2022-01-28 15:06:00 -08:00
parent ea95e64a2b
commit e8ffe7ff9d
5 changed files with 16 additions and 17 deletions

1
Cargo.lock generated
View File

@ -1538,6 +1538,7 @@ dependencies = [
"serde",
"serde_json",
"serde_yaml",
"smallvec",
"tendril",
"tracing",
]

View File

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

View File

@ -403,7 +403,7 @@ impl ParserContext<'_> {
/// circuit initialization expression.
pub fn parse_circuit_expression(&mut self, identifier: Identifier) -> Result<Expression> {
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()?,
}))

View File

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

View File

@ -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<ArrayDimensions> {
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<ArrayDimensions> {
fn parse_array_dimension(&mut self) -> Option<Dimension> {
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
}