dotnet / dotnet/fsharp

Detect escaped characters in SynConst.String

Open
#11,137 0 comments 0 reactions 0 assignees View on GitHub
Area-LangService-API Feature Request
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Given the following code:
```fsharp
// regular string with \n
"\n"
// regular string with newline
"
"
```

The untyped tree does not tell if the string contained an actual newline or an escaped one:
```fsharp
ImplFile
(ParsedImplFileInput
("tmp.fsx", true, QualifiedNameOfFile Tmp$fsx, [], [],
[SynModuleOrNamespace
([Tmp], false, AnonModule,
[DoExpr
(DebugPointAtBinding tmp.fsx (2,0--2,4) IsSynthetic=false,
Const
(String ("
", tmp.fsx (2,0--2,4) IsSynthetic=false),
tmp.fsx (2,0--2,4) IsSynthetic=false),
tmp.fsx (2,0--2,4) IsSynthetic=false);
DoExpr
(DebugPointAtBinding tmp.fsx (4,0--5,1) IsSynthetic=false,
Const
(String ("
", tmp.fsx (4,0--5,1) IsSynthetic=false),
tmp.fsx (4,0--5,1) IsSynthetic=false),
tmp.fsx (4,0--5,1) IsSynthetic=false)], PreXmlDocEmpty, [], None,
tmp.fsx (2,0--5,1) IsSynthetic=false)], (true, true)))
```

**Describe the solution you'd like**
It would be interesting that the original written string was still present in the untyped tree and only optimized in the Typed tree.

**Describe alternatives you've considered**
The difference can be detected by processing the F# tokens.

**Additional context**
This request also applies for chars and interpolated strings.
For example `'\u0000'`, leads to
```fsharp
ImplFile
(ParsedImplFileInput
("tmp.fsx", true, QualifiedNameOfFile Tmp$fsx, [], [],
[SynModuleOrNamespace
([Tmp], false, AnonModule,
[DoExpr
(DebugPointAtBinding tmp.fsx (1,0--1,8) IsSynthetic=false,
Const (Char '\000', tmp.fsx (1,0--1,8) IsSynthetic=false),
tmp.fsx (1,0--1,8) IsSynthetic=false)], PreXmlDocEmpty, [], None,
tmp.fsx (1,0--1,8) IsSynthetic=false)], (true, true)))
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.