feat: Add comments to AST nodes
This commit introduces support for comments within the AST nodes. Comments are now parsed by the lexer and stored within the `Token` struct. These comments are then propagated through various compiler phases, including the `Node` struct, ensuring they are preserved in the Abstract Syntax Tree. This change enhances the AST's ability to retain source code information, which can be valuable for debugging and analysis.
This commit is contained in:
@@ -724,6 +724,7 @@ impl Optimizer {
|
||||
Rc::new(Node {
|
||||
identity: node.identity.clone(),
|
||||
kind: new_kind,
|
||||
comments: node.comments.clone(),
|
||||
ty: metrics,
|
||||
})
|
||||
}
|
||||
@@ -780,6 +781,7 @@ impl Optimizer {
|
||||
_ => return node_rc.clone(),
|
||||
};
|
||||
Rc::new(Node {
|
||||
comments: node.comments.clone(),
|
||||
identity: node.identity.clone(),
|
||||
kind: new_kind,
|
||||
ty: node.ty.clone(),
|
||||
|
||||
@@ -19,11 +19,13 @@ impl<'a> Folder<'a> {
|
||||
let typed_original = Rc::new(Node {
|
||||
identity: template.identity.clone(),
|
||||
kind: NodeKind::Constant(val.clone()),
|
||||
comments: template.comments.clone(),
|
||||
ty: ty.clone(),
|
||||
});
|
||||
Node {
|
||||
identity: template.identity.clone(),
|
||||
kind: NodeKind::Constant(val),
|
||||
comments: template.comments.clone(),
|
||||
ty: NodeMetrics {
|
||||
original: typed_original,
|
||||
purity: Purity::Pure,
|
||||
@@ -36,11 +38,13 @@ impl<'a> Folder<'a> {
|
||||
let typed_original = Rc::new(Node {
|
||||
identity: template.identity.clone(),
|
||||
kind: NodeKind::Nop,
|
||||
comments: template.comments.clone(),
|
||||
ty: StaticType::Void,
|
||||
});
|
||||
Node {
|
||||
identity: template.identity.clone(),
|
||||
kind: NodeKind::Nop,
|
||||
comments: template.comments.clone(),
|
||||
ty: NodeMetrics {
|
||||
original: typed_original,
|
||||
purity: Purity::Pure,
|
||||
|
||||
@@ -231,6 +231,7 @@ impl SubstitutionMap {
|
||||
Rc::new(Node {
|
||||
identity: node.identity.clone(),
|
||||
kind: new_kind,
|
||||
comments: node.comments.clone(),
|
||||
ty: metrics,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user