mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 19:51:52 +03:00
Make StructVariableInitializer an AST node
This commit is contained in:
parent
6808d90545
commit
9125c84cd1
@ -27,10 +27,14 @@ pub struct StructVariableInitializer {
|
||||
/// The expression to initialize the field with.
|
||||
/// When `None`, a binding, in scope, with the name will be used instead.
|
||||
pub expression: Option<Expression>,
|
||||
/// The span of the node.
|
||||
pub span: Span,
|
||||
/// The ID of the node.
|
||||
pub id: NodeID,
|
||||
}
|
||||
|
||||
crate::simple_node_impl!(StructVariableInitializer);
|
||||
|
||||
impl fmt::Display for StructVariableInitializer {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if let Some(expr) = &self.expression {
|
||||
|
@ -571,14 +571,16 @@ impl ParserContext<'_> {
|
||||
self.expect_identifier()?
|
||||
};
|
||||
|
||||
let expression = if self.eat(&Token::Colon) {
|
||||
let (expression, span) = if self.eat(&Token::Colon) {
|
||||
// Parse individual struct variable declarations.
|
||||
Some(self.parse_expression()?)
|
||||
let expression = self.parse_expression()?;
|
||||
let span = identifier.span + expression.span();
|
||||
(Some(expression), span)
|
||||
} else {
|
||||
None
|
||||
(None, identifier.span)
|
||||
};
|
||||
|
||||
Ok(StructVariableInitializer { identifier, expression, id: NodeID::default() })
|
||||
Ok(StructVariableInitializer { identifier, expression, id: NodeID::default(), span })
|
||||
}
|
||||
|
||||
/// Returns an [`Expression`] AST node if the next tokens represent a
|
||||
|
Loading…
Reference in New Issue
Block a user