Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 14 additions & 3 deletions unified/extractor/src/languages/swift/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,20 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
(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).
rule!((dictionaryExpr) => (map_literal)),
// An empty dictionary literal, `[:]`.
rule!((dictionaryExpr content: ":") => (map_literal)),
// A non-empty dictionary literal, `[key: value]`.
rule!(
(dictionaryExpr content: (dictionaryElement)* @els)
=>
(map_literal element: {els})
),
// A key-value pair, `key: value`.
rule!(
(dictionaryElement key: @key value: @value)
=>
(key_value_pair key: {key} value: {value})
),
// A subscript access (`xs[0]`) is modelled as a call. swift-syntax does
// report a distinct `subscriptCallExpr`, so giving
// subscripts their own shape needs only a `subscript_expr` node in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
let d = ["a": 1, "b": 2]
let key = "a"
let value = 1
let d = [key: value, "b": 2]
let empty: [String: Int] = [:]

---

sourceFile
endOfFileToken: endOfFile
statements:
codeBlockItem
item:
variableDecl
attributes:
modifiers:
bindingSpecifier: let
bindings:
patternBinding
initializer:
initializerClause
equal: =
value:
stringLiteralExpr
closingQuote: "
openingQuote: "
segments:
stringSegment
content: stringSegment "a"
pattern:
identifierPattern
identifier: identifier "key"
codeBlockItem
item:
variableDecl
attributes:
modifiers:
bindingSpecifier: let
bindings:
patternBinding
initializer:
initializerClause
equal: =
value:
integerLiteralExpr
literal: integerLiteral "1"
pattern:
identifierPattern
identifier: identifier "value"
codeBlockItem
item:
variableDecl
Expand All @@ -25,15 +66,11 @@ sourceFile
colon: :
trailingComma: ,
value:
integerLiteralExpr
literal: integerLiteral "1"
declReferenceExpr
baseName: identifier "value"
key:
stringLiteralExpr
closingQuote: "
openingQuote: "
segments:
stringSegment
content: stringSegment "a"
declReferenceExpr
baseName: identifier "key"
dictionaryElement
colon: :
value:
Expand All @@ -49,14 +86,73 @@ sourceFile
pattern:
identifierPattern
identifier: identifier "d"
codeBlockItem
item:
variableDecl
attributes:
modifiers:
bindingSpecifier: let
bindings:
patternBinding
initializer:
initializerClause
equal: =
value:
dictionaryExpr
leftSquare: [
rightSquare: ]
content: :
pattern:
identifierPattern
identifier: identifier "empty"
typeAnnotation:
typeAnnotation
colon: :
type:
dictionaryType
colon: :
leftSquare: [
rightSquare: ]
value:
identifierType
name: identifier "Int"
key:
identifierType
name: identifier "String"

---

top_level source="⟨body⟩"
body:
block source="⟨stmt⟩"
block source="⟨stmt⟩\n⟨stmt⟩\n⟨stmt⟩\n⟨stmt⟩"
stmt:
variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩"
modifier: modifier "let" source="let"
pattern: identifier "key" source="key"
value: string_literal "\"a\"" source="\"a\""
variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩"
modifier: modifier "let" source="let"
pattern: identifier "value" source="value"
value: int_literal "1" source="1"
variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩"
modifier: modifier "let" source="let"
pattern: identifier "d" source="d"
value: map_literal "[\"a\": 1, \"b\": 2]" source="[\"a\": 1, \"b\": 2]"
value:
map_literal source="[⟨element⟩, ⟨element⟩]"
element:
key_value_pair source="⟨key⟩: ⟨value⟩"
key: identifier "key" source="key"
value: identifier "value" source="value"
key_value_pair source="⟨key⟩: ⟨value⟩"
key: string_literal "\"b\"" source="\"b\""
value: int_literal "2" source="2"
variable_declaration source="⟨modifier⟩ ⟨pattern⟩: ⟨type⟩ = ⟨value⟩"
modifier: modifier "let" source="let"
pattern: identifier "empty" source="empty"
type:
generic_type_expr source="[⟨type_argument⟩: ⟨type_argument⟩]"
base: identifier "Dictionary" source=""
type_argument:
identifier "String" source="String"
identifier "Int" source="Int"
value: map_literal "[:]" source="[:]"
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
let d = ["a": 1, "b": 2]
let key = "a"
let value = 1
let d = [key: value, "b": 2]
let empty: [String: Int] = [:]
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ top_level source="⟨body⟩"
value: identifier "offset" source="offset"
array_literal source="[⟨element⟩]"
element: identifier "value" source="value"
map_literal "[key: value]" source="[key: value]"
map_literal source="[⟨element⟩]"
element:
key_value_pair source="⟨key⟩: ⟨value⟩"
key: identifier "key" source="key"
value: identifier "value" source="value"
call_expr source="⟨argument⟩?"
callee:
member_access_expr source=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
| 413 | cfg.swift:413:5:413:9 | field | 'field -> 0 -^ ... = ...' |
| 417 | cfg.swift:417:1:419:1 | func dictionaryLiteral | 'func dictionaryLiteral' |
| 417 | cfg.swift:417:24:417:24 | x | 'x -> y -> Block' |
| 418 | cfg.swift:418:10:418:25 | MapLiteral | 'MapLiteral -^ ReturnExpr' |
| 418 | cfg.swift:418:11:418:13 | "x" | '"x" -> x -^ KeyValuePair -> "y" -> y -^ KeyValuePair -^ MapLiteral -^ ReturnExpr' |
| 421 | cfg.swift:421:1:444:1 | func localDeclarations | 'func localDeclarations' |
| 421 | cfg.swift:421:33:444:1 | Block | 'Block' |
| 422 | cfg.swift:422:3:427:3 | class MyLocalClass | 'class MyLocalClass -V MyLocalClass' |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,10 @@ inferType
| key_paths.swift:204:22:204:23 | 30 | | {EXTERNAL LOCATION} | Int |
| key_paths.swift:205:15:205:17 | arr | | {EXTERNAL LOCATION} | Array |
| key_paths.swift:205:15:205:17 | arr | Element | {EXTERNAL LOCATION} | Int |
| key_paths.swift:208:15:208:17 | "x" | | {EXTERNAL LOCATION} | String |
| key_paths.swift:208:20:208:20 | 1 | | {EXTERNAL LOCATION} | Int |
| key_paths.swift:208:23:208:25 | "y" | | {EXTERNAL LOCATION} | String |
| key_paths.swift:208:28:208:28 | 2 | | {EXTERNAL LOCATION} | Int |
| lub.swift:12:7:12:7 | b | | lub.swift:5:1:7:1 | B |
| lub.swift:12:11:12:13 | B(...) | | lub.swift:5:1:7:1 | B |
| lub.swift:14:7:14:7 | x | | lub.swift:5:1:7:1 | B |
Expand Down Expand Up @@ -2094,6 +2098,8 @@ inferType
| overload_resolution.swift:428:7:428:10 | dict | | {EXTERNAL LOCATION} | Dictionary |
| overload_resolution.swift:428:7:428:10 | dict | Key | {EXTERNAL LOCATION} | String |
| overload_resolution.swift:428:7:428:10 | dict | Value | {EXTERNAL LOCATION} | Int |
| overload_resolution.swift:428:30:428:32 | "a" | | {EXTERNAL LOCATION} | String |
| overload_resolution.swift:428:35:428:35 | 1 | | {EXTERNAL LOCATION} | Int |
| overload_resolution.swift:432:14:432:18 | index | | {EXTERNAL LOCATION} | Int |
| overload_resolution.swift:433:12:433:15 | data | | {EXTERNAL LOCATION} | Array |
| overload_resolution.swift:433:12:433:15 | data | Element | {EXTERNAL LOCATION} | Int |
Expand Down
Loading