Skip to content

Commit

Permalink
Change InterpStringEndToken to also match string part. Fixes fsprojec…
Browse files Browse the repository at this point in the history
  • Loading branch information
suside committed Jan 9, 2021
1 parent 6a757cc commit c50b059
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/Fantomas.Tests/InterpolatedStringTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,18 @@ $"abc {
x + x
} xyz"
"""

[<Test>]
let ``backslash in interpolation, issue 1344`` () =
formatSourceString
false
"""
$"\"{bar}\" {1} {2}"
"""
config
|> prepend newline
|> should
equal
"""
$"\"{bar}\" {1} {2}"
"""
7 changes: 4 additions & 3 deletions src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ let private (|StringTextToken|_|) token =
else
None

let private (|InterpStringEndToken|_|) token =
if token.TokenInfo.TokenName = "INTERP_STRING_END" then
let private (|InterpStringEndOrPartToken|_|) token =
if token.TokenInfo.TokenName = "INTERP_STRING_END"
|| token.TokenInfo.TokenName = "INTERP_STRING_PART" then
Some token
else
None
Expand All @@ -522,7 +523,7 @@ let escapedCharacterRegex =

let rec private (|EndOfInterpolatedString|_|) tokens =
match tokens with
| StringTextToken (stToken) :: InterpStringEndToken (endToken) :: rest -> Some([ stToken ], endToken, rest)
| StringTextToken (stToken) :: InterpStringEndOrPartToken (endToken) :: rest -> Some([ stToken ], endToken, rest)
| StringTextToken (stToken) :: EndOfInterpolatedString (stringTokens, endToken, rest) ->
Some(stToken :: stringTokens, endToken, rest)
| _ -> None
Expand Down

0 comments on commit c50b059

Please sign in to comment.