Refactor UntypedKind::Parameter to Identifier

The `Parameter` kind in `UntypedKind` was only used for identifiers that
were being declared or referenced. This commit renames it to
`Identifier` and updates all the necessary code to reflect this change.
This simplifies the AST and makes it more consistent.

Additionally, a new macro `repeat` has been added to
`src/ast/system.myc`.
This commit is contained in:
Michael Schimmel
2026-03-09 11:08:30 +01:00
parent cb4507b2da
commit fa23a4c125
12 changed files with 34 additions and 105 deletions
+3 -12
View File
@@ -344,7 +344,7 @@ impl<E: MacroEvaluator> MacroExpander<E> {
fn extract_param_names(&self, node: &Node<UntypedKind>) -> Result<Vec<Rc<str>>, String> {
match &node.kind {
UntypedKind::Parameter(sym) => Ok(vec![sym.name.clone()]),
UntypedKind::Identifier(sym) => Ok(vec![sym.name.clone()]),
UntypedKind::Tuple { elements } => {
let mut names = Vec::new();
for el in elements {
@@ -372,15 +372,6 @@ impl<E: MacroEvaluator> MacroExpander<E> {
})
}
UntypedKind::Parameter(mut sym) => {
sym.context = Some(state.expansion_id.clone());
Ok(Node {
identity: node.identity,
kind: UntypedKind::Parameter(sym),
ty: (),
})
}
UntypedKind::Placeholder(inner) => {
// Break out of template for substitution/evaluation
if let UntypedKind::Identifier(ref sym) = inner.kind
@@ -654,11 +645,11 @@ mod tests {
} = &exprs[1].kind
{
if let UntypedKind::Def { target, .. } = &result.kind {
if let UntypedKind::Parameter(sym) = &target.kind {
if let UntypedKind::Identifier(sym) = &target.kind {
assert_eq!(sym.context, Some(call.identity.clone()));
assert_eq!(sym.name.as_ref(), "y");
} else {
panic!("Expected Parameter target, got {:?}", target.kind);
panic!("Expected Identifier target, got {:?}", target.kind);
}
} else {
panic!("Expected Def result, got {:?}", result.kind);