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:
2026-03-25 18:36:53 +01:00
parent b436e09840
commit ee89d2330d
16 changed files with 180 additions and 24 deletions
+2
View File
@@ -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(),
+4
View File
@@ -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,
})
}