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