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:
@@ -197,11 +197,6 @@ impl Binder {
|
||||
}
|
||||
}
|
||||
|
||||
UntypedKind::Parameter(_) => {
|
||||
diag.push_error("Unexpected 'Parameter' node in general binder context. This should be handled via 'bind_pattern'.", Some(node.identity.clone()));
|
||||
self.make_node(node.identity.clone(), BoundKind::Error)
|
||||
}
|
||||
|
||||
UntypedKind::FieldAccessor(k) => {
|
||||
self.make_node(node.identity.clone(), BoundKind::FieldAccessor(*k))
|
||||
}
|
||||
@@ -230,7 +225,7 @@ impl Binder {
|
||||
|
||||
UntypedKind::Def { target, value } => {
|
||||
// Special case: Single identifier (to support recursion)
|
||||
if let UntypedKind::Parameter(ref name) = target.kind {
|
||||
if let UntypedKind::Identifier(ref name) = target.kind {
|
||||
let addr_opt = self.declare_variable(
|
||||
name,
|
||||
node.identity.clone(), // Identity of the Def node
|
||||
@@ -543,7 +538,7 @@ impl Binder {
|
||||
diag: &mut Diagnostics,
|
||||
) -> BoundNode {
|
||||
match &node.kind {
|
||||
UntypedKind::Parameter(sym) => {
|
||||
UntypedKind::Identifier(sym) => {
|
||||
if let Some(addr) = self.declare_variable(sym, node.identity.clone(), kind, diag) {
|
||||
self.make_node(
|
||||
node.identity.clone(),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user