mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-20 16:11:35 +03:00
merge upstream changes from ast and staging
This commit is contained in:
parent
ea95e64a2b
commit
e8ffe7ff9d
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1538,6 +1538,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
|
"smallvec",
|
||||||
"tendril",
|
"tendril",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
@ -23,6 +23,9 @@ name = "leo_ast"
|
|||||||
path = "benches/leo_ast.rs"
|
path = "benches/leo_ast.rs"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
smallvec = "1.8"
|
||||||
|
|
||||||
[dependencies.leo-ast]
|
[dependencies.leo-ast]
|
||||||
path = "../ast"
|
path = "../ast"
|
||||||
version = "1.5.3"
|
version = "1.5.3"
|
||||||
|
@ -403,7 +403,7 @@ impl ParserContext<'_> {
|
|||||||
/// circuit initialization expression.
|
/// circuit initialization expression.
|
||||||
pub fn parse_circuit_expression(&mut self, identifier: Identifier) -> Result<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| {
|
let (members, _, span) = self.parse_list(Token::LeftCurly, Token::RightCurly, Token::Comma, |p| {
|
||||||
Ok(Some(CircuitImpliedVariableDefinition {
|
Ok(Some(CircuitVariableInitializer {
|
||||||
identifier: p.expect_ident()?,
|
identifier: p.expect_ident()?,
|
||||||
expression: p.eat(Token::Colon).map(|_| p.parse_expression()).transpose()?,
|
expression: p.eat(Token::Colon).map(|_| p.parse_expression()).transpose()?,
|
||||||
}))
|
}))
|
||||||
|
@ -559,19 +559,12 @@ impl ParserContext<'_> {
|
|||||||
/// const definition statement and assignment.
|
/// const definition statement and assignment.
|
||||||
///
|
///
|
||||||
pub fn parse_type_alias(&mut self) -> Result<(Identifier, Alias)> {
|
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()?;
|
let name = self.expect_ident()?;
|
||||||
self.expect(Token::Assign)?;
|
self.expect(Token::Assign)?;
|
||||||
let (type_, _) = self.parse_type()?;
|
let (represents, _) = self.parse_type()?;
|
||||||
self.expect(Token::Semicolon)?;
|
let span = start + self.expect(Token::Semicolon)?;
|
||||||
|
|
||||||
Ok((
|
Ok((name.clone(), Alias { represents, span, name }))
|
||||||
name.clone(),
|
|
||||||
Alias {
|
|
||||||
represents: type_,
|
|
||||||
span: name.span.clone(),
|
|
||||||
name,
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use leo_errors::{ParserError, Result};
|
use leo_errors::{ParserError, Result};
|
||||||
|
|
||||||
|
use smallvec::smallvec;
|
||||||
|
|
||||||
pub(crate) const TYPE_TOKENS: &[Token] = &[
|
pub(crate) const TYPE_TOKENS: &[Token] = &[
|
||||||
Token::I8,
|
Token::I8,
|
||||||
Token::I16,
|
Token::I16,
|
||||||
@ -58,7 +60,7 @@ impl ParserContext<'_> {
|
|||||||
/// Returns an [`ArrayDimensions`] AST node if the next tokens represent dimensions for an array type.
|
/// Returns an [`ArrayDimensions`] AST node if the next tokens represent dimensions for an array type.
|
||||||
pub fn parse_array_dimensions(&mut self) -> Result<ArrayDimensions> {
|
pub fn parse_array_dimensions(&mut self) -> Result<ArrayDimensions> {
|
||||||
Ok(if let Some(dim) = self.parse_array_dimension() {
|
Ok(if let Some(dim) = self.parse_array_dimension() {
|
||||||
dim
|
ArrayDimensions(smallvec![dim])
|
||||||
} else {
|
} else {
|
||||||
let mut had_item_err = false;
|
let mut had_item_err = false;
|
||||||
let (dims, _, span) = self.parse_paren_comma_list(|p| {
|
let (dims, _, span) = self.parse_paren_comma_list(|p| {
|
||||||
@ -74,16 +76,16 @@ impl ParserContext<'_> {
|
|||||||
if dims.is_empty() && !had_item_err {
|
if dims.is_empty() && !had_item_err {
|
||||||
self.emit_err(ParserError::array_tuple_dimensions_empty(&span));
|
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 `_`.
|
/// 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() {
|
if let Some((int, _)) = self.eat_int() {
|
||||||
Some(ArrayDimensions::Number(int))
|
Some(Dimension::Number(int))
|
||||||
} else if self.eat(Token::Underscore).is_some() {
|
} else if self.eat(Token::Underscore).is_some() {
|
||||||
Some(ArrayDimensions::Unspecified)
|
Some(Dimension::Unspecified)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user