Skip to content

Commit

Permalink
collapse one more level of indirection for string interpolation nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Smirnov <[email protected]>
  • Loading branch information
Denys Smirnov authored and dennwc committed Feb 5, 2019
1 parent 4b674c5 commit 7fb8508
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 360 deletions.
17 changes: 17 additions & 0 deletions driver/normalizer/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,23 @@ var Normalizers = []Mapping{
},
)),

// Collapse one more AST level if the string token is inside InterpolatedStringText.
MapSemantic("InterpolatedStringText", uast.String{}, MapObj(
Obj{
"TextToken": Obj{
uast.KeyType: String(uast.TypeOf(uast.String{})),
uast.KeyPos: Any(),
"Format": String(""),
"Value": Var("val"),
},
"IsMissing": Bool(false),
"IsStructuredTrivia": Bool(false),
},
Obj{
"Value": Var("val"),
},
)),

MapSemantic("TrueLiteralExpression", uast.Bool{}, MapObj(
Obj{
"Token": Obj{
Expand Down
46 changes: 6 additions & 40 deletions fixtures/issue_18.cs.sem.uast
Original file line number Diff line number Diff line change
Expand Up @@ -2112,8 +2112,7 @@
},
},
Contents: [
{ '@type': "csharp:InterpolatedStringText",
'@role': [Incomplete, Literal, String],
{ '@type': "uast:String",
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 2124,
Expand All @@ -2126,24 +2125,8 @@
col: 28,
},
},
IsMissing: false,
IsStructuredTrivia: false,
TextToken: { '@type': "uast:String",
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 2124,
line: 52,
col: 25,
},
end: { '@type': "uast:Position",
offset: 2127,
line: 52,
col: 28,
},
},
Format: "",
Value: "\"[",
},
Format: "",
Value: "\"[",
},
{ '@type': "csharp:Interpolation",
'@role': [Expression, Incomplete, Value],
Expand Down Expand Up @@ -2221,8 +2204,7 @@
ValueText: "{",
},
},
{ '@type': "csharp:InterpolatedStringText",
'@role': [Incomplete, Literal, String],
{ '@type': "uast:String",
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 2133,
Expand All @@ -2235,24 +2217,8 @@
col: 37,
},
},
IsMissing: false,
IsStructuredTrivia: false,
TextToken: { '@type': "uast:String",
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 2133,
line: 52,
col: 34,
},
end: { '@type': "uast:Position",
offset: 2136,
line: 52,
col: 37,
},
},
Format: "",
Value: "]\"",
},
Format: "",
Value: "]\"",
},
],
IsMissing: false,
Expand Down
Loading

0 comments on commit 7fb8508

Please sign in to comment.