@@ -1028,50 +1028,73 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
10281028 // (swift-syntax represents `#selector`/`#keyPath` and other macro
10291029 // expansions uniformly as a `macroExpansionExpr`).
10301030 rule!( ( macroExpansionExpr) => ( unsupported_node) ) ,
1031- // PARITY(tree-sitter): a nominal type's `inheritanceClause` (`: Base,
1032- // Proto`) is not emitted as a `base_type` — the tree-sitter path drops
1033- // it (no corpus target has a `base_type`). swift-syntax exposes it
1034- // cleanly, so emitting `base_type` is a correctness improvement to make
1035- // once tree-sitter is retired. Each declaration keyword gets its own
1036- // rule; the bodies are identical but for the keyword.
1031+ // A nominal type's `inheritanceClause` (`: Base, Proto`) becomes a list
1032+ // of `base_type`s, one per inherited type. The tree-sitter path dropped
1033+ // it (no corpus target had a `base_type`) and the mapping matched that
1034+ // for parity; swift-syntax exposes it cleanly. Each declaration keyword
1035+ // gets its own rule; the bodies are identical but for the keyword.
10371036 // Class declaration with body containing members
10381037 rule!(
1039- ( classDecl classKeyword: @kind modifiers: _* @mods name: @name memberBlock: ( memberBlock members: _* @members) )
1038+ ( classDecl
1039+ classKeyword: @kind
1040+ modifiers: _* @mods
1041+ name: @name
1042+ inheritanceClause: ( inheritanceClause inheritedTypes: ( inheritedType type : @bases) * ) ?
1043+ memberBlock: ( memberBlock members: _* @members) )
10401044 =>
10411045 ( class_like_declaration
10421046 modifier: ( modifier #{ kind} )
10431047 modifier: { mods}
10441048 name: ( identifier #{ name} )
1049+ base_type: { bases. into_iter( ) . map( |ty| tree!( ( base_type type : { ty} ) ) ) }
10451050 member: { members} )
10461051 ) ,
10471052 // Enum class declaration: same as a regular class but with an enum body.
10481053 rule!(
1049- ( enumDecl enumKeyword: @kind modifiers: _* @mods name: @name memberBlock: ( memberBlock members: _* @members) )
1054+ ( enumDecl
1055+ enumKeyword: @kind
1056+ modifiers: _* @mods
1057+ name: @name
1058+ inheritanceClause: ( inheritanceClause inheritedTypes: ( inheritedType type : @bases) * ) ?
1059+ memberBlock: ( memberBlock members: _* @members) )
10501060 =>
10511061 ( class_like_declaration
10521062 modifier: ( modifier #{ kind} )
10531063 modifier: { mods}
10541064 name: ( identifier #{ name} )
1065+ base_type: { bases. into_iter( ) . map( |ty| tree!( ( base_type type : { ty} ) ) ) }
10551066 member: { members} )
10561067 ) ,
10571068 // A `struct` declaration.
10581069 rule!(
1059- ( structDecl structKeyword: @kind modifiers: _* @mods name: @name memberBlock: ( memberBlock members: _* @members) )
1070+ ( structDecl
1071+ structKeyword: @kind
1072+ modifiers: _* @mods
1073+ name: @name
1074+ inheritanceClause: ( inheritanceClause inheritedTypes: ( inheritedType type : @bases) * ) ?
1075+ memberBlock: ( memberBlock members: _* @members) )
10601076 =>
10611077 ( class_like_declaration
10621078 modifier: ( modifier #{ kind} )
10631079 modifier: { mods}
10641080 name: ( identifier #{ name} )
1081+ base_type: { bases. into_iter( ) . map( |ty| tree!( ( base_type type : { ty} ) ) ) }
10651082 member: { members} )
10661083 ) ,
10671084 // Protocol declaration
10681085 rule!(
1069- ( protocolDecl protocolKeyword: @kind modifiers: _* @mods name: @name memberBlock: ( memberBlock members: _* @members) )
1086+ ( protocolDecl
1087+ protocolKeyword: @kind
1088+ modifiers: _* @mods
1089+ name: @name
1090+ inheritanceClause: ( inheritanceClause inheritedTypes: ( inheritedType type : @bases) * ) ?
1091+ memberBlock: ( memberBlock members: _* @members) )
10701092 =>
10711093 ( class_like_declaration
10721094 modifier: ( modifier #{ kind} )
10731095 modifier: { mods}
10741096 name: ( identifier #{ name} )
1097+ base_type: { bases. into_iter( ) . map( |ty| tree!( ( base_type type : { ty} ) ) ) }
10751098 member: { members} )
10761099 ) ,
10771100 // An `extension Foo { … }` is likewise a `class_like_declaration`, named
@@ -1080,12 +1103,18 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
10801103 // a `memberType`) name the declaration just like simple ones, matching the
10811104 // old tree-sitter `user_type` behaviour.
10821105 rule!(
1083- ( extensionDecl extensionKeyword: @kind modifiers: _* @mods extendedType: @@name memberBlock: ( memberBlock members: _* @members) )
1106+ ( extensionDecl
1107+ extensionKeyword: @kind
1108+ modifiers: _* @mods
1109+ extendedType: @@name
1110+ inheritanceClause: ( inheritanceClause inheritedTypes: ( inheritedType type : @bases) * ) ?
1111+ memberBlock: ( memberBlock members: _* @members) )
10841112 =>
10851113 ( class_like_declaration
10861114 modifier: ( modifier #{ kind} )
10871115 modifier: { mods}
10881116 name: ( identifier #{ name} )
1117+ base_type: { bases. into_iter( ) . map( |ty| tree!( ( base_type type : { ty} ) ) ) }
10891118 member: { members} )
10901119 ) ,
10911120 // A member of a type declaration unwraps to the contained declaration.
0 commit comments