Skip to content

Commit 4b674c5

Browse files
Denys Smirnovdennwc
authored andcommitted
convert string interpolation tokens to uast:String; addresses #21
Signed-off-by: Denys Smirnov <denys@sourced.tech>
1 parent a121bf2 commit 4b674c5

4 files changed

Lines changed: 59 additions & 133 deletions

File tree

driver/normalizer/normalizer.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,27 @@ var Normalizers = []Mapping{
486486
},
487487
)),
488488

489+
// A string literal part of the interpolation expression.
490+
MapSemantic("InterpolatedStringTextToken", uast.String{}, MapObj(
491+
Obj{
492+
// trivia == whitespace; can safely drop it
493+
"LeadingTrivia": Arr(),
494+
"TrailingTrivia": Arr(),
495+
496+
"IsMissing": Bool(false),
497+
498+
// contains escaped value, we don't need it in canonical UAST
499+
"Text": Any(),
500+
501+
// both values are the same
502+
"Value": Var("val"),
503+
"ValueText": Var("val"),
504+
},
505+
Obj{
506+
"Value": Var("val"),
507+
},
508+
)),
509+
489510
MapSemantic("TrueLiteralExpression", uast.Bool{}, MapObj(
490511
Obj{
491512
"Token": Obj{

fixtures/issue_18.cs.sem.uast

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,8 +2128,7 @@
21282128
},
21292129
IsMissing: false,
21302130
IsStructuredTrivia: false,
2131-
TextToken: { '@type': "csharp:InterpolatedStringTextToken",
2132-
'@role': [Incomplete, String],
2131+
TextToken: { '@type': "uast:String",
21332132
'@pos': { '@type': "uast:Positions",
21342133
start: { '@type': "uast:Position",
21352134
offset: 2124,
@@ -2142,12 +2141,8 @@
21422141
col: 28,
21432142
},
21442143
},
2145-
IsMissing: false,
2146-
LeadingTrivia: [],
2147-
Text: "\\\"[",
2148-
TrailingTrivia: [],
2144+
Format: "",
21492145
Value: "\"[",
2150-
ValueText: "\"[",
21512146
},
21522147
},
21532148
{ '@type': "csharp:Interpolation",
@@ -2242,8 +2237,7 @@
22422237
},
22432238
IsMissing: false,
22442239
IsStructuredTrivia: false,
2245-
TextToken: { '@type': "csharp:InterpolatedStringTextToken",
2246-
'@role': [Incomplete, String],
2240+
TextToken: { '@type': "uast:String",
22472241
'@pos': { '@type': "uast:Positions",
22482242
start: { '@type': "uast:Position",
22492243
offset: 2133,
@@ -2256,12 +2250,8 @@
22562250
col: 37,
22572251
},
22582252
},
2259-
IsMissing: false,
2260-
LeadingTrivia: [],
2261-
Text: "]\\\"",
2262-
TrailingTrivia: [],
2253+
Format: "",
22632254
Value: "]\"",
2264-
ValueText: "]\"",
22652255
},
22662256
},
22672257
],

0 commit comments

Comments
 (0)