From 4c764b52dc177cbf5565d3fb8f86e4c8f5518cb5 Mon Sep 17 00:00:00 2001 From: Taus Date: Mon, 20 Jul 2026 12:11:54 +0000 Subject: [PATCH] unified: Port collection rules to swift-syntax Retarget collection literals and subscripts to the swift-syntax AST, output unchanged: `arrayExpr` -> `array_literal` (each `arrayElement` unwraps to its expression); `dictionaryExpr` -> an opaque `map_literal` leaf (its source span, matching the tree-sitter path); and `subscriptCallExpr` (`xs[0]`) -> `call_expr`, mirroring the tree-sitter grammar's treatment of a subscript as a call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../extractor/src/languages/swift/swift.rs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index e0c2f66e210..2068cca7a64 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -845,20 +845,24 @@ fn translation_rules() -> Vec> { (labeled_stmt label: (identifier #{lbl}) stmt: {stmt}) ), // ---- Collections ---- - // Array literal - rule!((array_literal element: _* @elems) => (array_literal element: {elems})), - // Empty array literal - rule!((array_literal) => (array_literal)), - // Dictionary literal — zip keys and values into key_value_pairs + // An array literal (`[1, 2, 3]`). Each `arrayElement` unwraps to its + // contained expression. rule!( - (dictionary_literal key: _* @keys value: _* @vals) + (arrayExpr elements: _* @els) => - (map_literal element: {keys.into_iter().zip(vals).map(|(k, v)| - tree!((key_value_pair key: {k} value: {v})) - )}) + (array_literal element: {els}) + ), + rule!((arrayElement expression: @e) => expr { e }), + // A dictionary literal (`["a": 1]`) is kept as an opaque `map_literal` + // leaf (its source span), matching the tree-sitter path. + rule!((dictionaryExpr) => (map_literal)), + // A subscript access (`xs[0]`) is modelled as a call, exactly as the + // tree-sitter grammar does (it parses `xs[0]` like `xs(0)`). + rule!( + (subscriptCallExpr calledExpression: @callee arguments: _* @args) + => + (call_expr callee: {callee} argument: {args}) ), - rule!((dictionary_literal element: _* @elems) => (map_literal element: {elems})), - rule!((dictionary_literal_item key: @k value: @v) => (key_value_pair key: {k} value: {v})), // ---- Optionals and errors ---- // Optional chaining — unwrap the marker rule!((optional_chain_marker expr: @inner) => expr { inner }),