Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7a573c4
yeast: Order AST dump fields by schema-declared order
tausbn Jul 16, 2026
8206f6f
swift-syntax-rs: Fold local and stdlib operators
tausbn Jul 16, 2026
2e74c1d
yeast: Desugar an externally-built AST, and validate by field name
tausbn Jul 16, 2026
bbf52ce
tree-sitter-extractor: Split direct and desugaring extractors
tausbn Jul 17, 2026
79954ce
unified: Add the swift-syntax parser and unresolved operator sequence…
tausbn Jul 17, 2026
ad2ce93
unified: Port top-level, literal, and name rules to swift-syntax
tausbn Jul 16, 2026
8328fba
unified: Port operator rules to swift-syntax
tausbn Jul 17, 2026
437e482
unified: Port variable-binding rules to swift-syntax
tausbn Jul 17, 2026
191fc54
unified: Port type-expression rules to swift-syntax
tausbn Jul 17, 2026
52cdf59
unified: Port function, call, and member-access rules to swift-syntax
tausbn Jul 17, 2026
6ad1fac
unified: Port closure rules to swift-syntax
tausbn Jul 17, 2026
2de1549
unified: Port control-flow and pattern rules to swift-syntax
tausbn Jul 20, 2026
2fcbc9b
unified: Port loop rules to swift-syntax
tausbn Jul 20, 2026
4c764b5
unified: Port collection rules to swift-syntax
tausbn Jul 20, 2026
6275977
unified: Port optional and error-handling rules to swift-syntax
tausbn Jul 20, 2026
37654b4
unified: Port import rules to swift-syntax
tausbn Jul 20, 2026
8e6651a
unified: Port type-container declarations to swift-syntax
tausbn Jul 20, 2026
ec0c49a
unified: Port property accessor rules to swift-syntax
tausbn Jul 22, 2026
90ea1b5
unified: Port enum-case rules to swift-syntax
tausbn Jul 23, 2026
c4fbd74
unified: Port constructor and related declaration rules to swift-syntax
tausbn Jul 23, 2026
5c5fd5e
unified: Switch the Swift front-end to swift-syntax
tausbn Jul 23, 2026
20a2537
unified: Regenerate the raw-AST corpus section for swift-syntax
tausbn Jul 23, 2026
046c88a
unified: Regenerate the enhanced getter/setter property corpus case
tausbn Jul 23, 2026
c50bcba
swift-syntax-rs: Degrade gracefully without a Swift toolchain
tausbn Jul 23, 2026
17cbb4e
unified: Harden the external Swift parser integration
tausbn Jul 24, 2026
7721ce2
unified: Add swift_node_types.yml to the extractor's compile_data
tausbn Jul 24, 2026
e3a0822
unified: Package the swift-syntax parser in the extractor pack
tausbn Jul 24, 2026
ba26e1d
unified: Add corpus tests for nested types
tausbn Jul 27, 2026
a3d9492
Merge branch 'main' into tausbn/swift-syntax-rs-sequenced
tausbn Jul 28, 2026
a2ff35a
unified: Fix Bazel formatting errors
tausbn Jul 28, 2026
ceffe40
unified: Remove references to Swift input schema generation
tausbn Jul 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 85 additions & 26 deletions unified/extractor/src/languages/swift/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ struct SwiftContext {
/// `chained_declaration` modifier so the original grouping can be
/// recovered downstream.
is_chained: bool,
/// True while translating the parameters of a `functionType`. swift-syntax
/// models a function type's parameters with the same `tupleTypeElement`
/// kind as a tuple type's elements, so the shared `tupleTypeElement` rule
/// reads this to emit a `parameter` (function-type param) rather than a
/// `tuple_type_element` (tuple-type element). The `tupleType` /
/// `functionType` rules each set it for their direct children, so nested
/// types are translated in the correct context.
in_function_type: bool,
}

impl SwiftContext {
Expand Down Expand Up @@ -920,32 +928,83 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
rule!((parameter_modifier) @m => (modifier #{m})),
rule!((inheritance_modifier) @m => (modifier #{m})),
rule!((property_behavior_modifier) @m => (modifier #{m})),
// Type annotations — unwrap
rule!((type_annotation type: @inner) => type_expr { inner }),
// user_type is split into simple_user_type parts.
// Keep a conservative textual fallback to avoid dropping type information.
rule!((user_type) @ty => (named_type_expr name: (identifier #{ty}))),
// Tuple type → tuple_type_expr
rule!((tuple_type element: _* @elems) => (tuple_type_expr element: {elems})),
rule!((tuple_type_item name: @name type: @ty) => (tuple_type_element name: (identifier #{name}) type: {ty})),
rule!((tuple_type_item type: @ty) => (tuple_type_element type: {ty})),
// Array type `[T]` → generic_type_expr with Array base
rule!((array_type element: @e) => (generic_type_expr
base: (named_type_expr name: (identifier "Array"))
type_argument: {e})),
// Dictionary type `[K: V]` → generic_type_expr with Dictionary base
rule!((dictionary_type key: @k value: @v) => (generic_type_expr
base: (named_type_expr name: (identifier "Dictionary"))
type_argument: {k}
type_argument: {v})),
// Optional type `T?` → generic_type_expr with Optional base
rule!((optional_type wrapped: @w) => (generic_type_expr
base: (named_type_expr name: (identifier "Optional"))
type_argument: {w})),
// Function type `(Params) -> Ret` → function_type_expr.
rule!((function_type parameter: _* @ps return_type: @ret) => (function_type_expr parameter: {ps} return_type: {ret})),
rule!((function_type_parameter name: @name type: @ty) => (parameter external_name: (identifier #{name}) type: {ty})),
rule!((function_type_parameter type: @ty) => (parameter type: {ty})),
// Type expressions. A generic type applied with explicit arguments
// (`Set<Int>`) is represented opaquely, using the whole source text as
// the name (PARITY(tree-sitter): the generic arguments are not
// structured `type_argument`s). Matched before the plain `identifierType`
// rule, which would otherwise drop the arguments.
rule!(
(identifierType genericArgumentClause: (genericArgumentClause)) @@ty
=>
(named_type_expr name: (identifier #{ty}))
),
// A named type (`Int`). `identifierType.name` is the type-name token.
rule!((identifierType name: @@n) => (named_type_expr name: (identifier #{n}))),
// A qualified type (`Outer.Inner`, `NSString.CompareOptions`). swift-syntax
// nests these as `memberType` nodes; like the old tree-sitter `user_type`
// rule, we keep the whole dotted path as the opaque `named_type_expr` name.
Comment thread
jketema marked this conversation as resolved.
rule!((memberType) @ty => (named_type_expr name: (identifier #{ty}))),
// Sugared types desugar to `generic_type_expr`: `T?` -> Optional<T>,
// `[T]` -> Array<T>, `[K: V]` -> Dictionary<K, V>.
rule!(
(optionalType wrappedType: @w)
=>
(generic_type_expr base: (named_type_expr name: (identifier "Optional")) type_argument: {w})
),
rule!(
(arrayType element: @e)
=>
(generic_type_expr base: (named_type_expr name: (identifier "Array")) type_argument: {e})
),
rule!(
(dictionaryType key: @k value: @v)
=>
(generic_type_expr base: (named_type_expr name: (identifier "Dictionary")) type_argument: {k} type_argument: {v})
),
// A tuple type (`(Int, String)`) or function type (`(Int) -> Bool`).
// Both hold their contents as `tupleTypeElement`s, but a tuple element
// maps to `tuple_type_element` while a function parameter maps to
// `parameter`. Each container sets `ctx.in_function_type` for its direct
// children (and translates them explicitly, so a nested type is
// translated in the right context) and the shared `tupleTypeElement`
// rule below reads it. An element's label (`firstName`) is optional.
rule!(
(tupleType elements: _* @@elems)
=>
tuple_type_expr {
ctx.in_function_type = false;
let mut out = Vec::new();
for e in elems {
out.extend(ctx.translate(e)?);
}
tree!((tuple_type_expr element: {out}))
}
),
rule!(
(functionType parameters: _* @@params returnClause: (returnClause type: @ret))
=>
function_type_expr {
ctx.in_function_type = true;
let mut out = Vec::new();
for p in params {
out.extend(ctx.translate(p)?);
}
ctx.in_function_type = false;
Comment thread
jketema marked this conversation as resolved.
Outdated
tree!((function_type_expr parameter: {out} return_type: {ret}))
}
),
rule!(
(tupleTypeElement firstName: _? @@name type: @ty)
=>
tuple_type_element {
let name = name.map(|n| tree!((identifier #{n})));
if ctx.in_function_type {
tree!((parameter external_name: {name} type: {ty}))
} else {
tree!((tuple_type_element name: {name} type: {ty}))
}
}
),
// Selector expression: `#selector(inner)` -- not yet supported
rule!(
(selector_expression _ @inner)
Expand Down