Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\t in string replaced by ASCII 9 #1695

Closed
3 tasks
stanciuadrian opened this issue May 5, 2021 · 4 comments · Fixed by #1697
Closed
3 tasks

\t in string replaced by ASCII 9 #1695

stanciuadrian opened this issue May 5, 2021 · 4 comments · Fixed by #1697

Comments

@stanciuadrian
Copy link
Contributor

stanciuadrian commented May 5, 2021

Issue created from fantomas-online

Code

printfn "Hello\tWorld"

Result

printfn "Hello	World"

Problem description

The string is not recognized as trivia so the string from the AST is printed back out (thx @nojaf for quick analysis).
Thus, the \t in the string is replaced by ASCII 9 (TAB).

via ionide/ionide-vscode-fsharp#1534

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas Master at 05/01/2021 14:37:19 - d8e76d4

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

Edit: credits

@nojaf
Copy link
Contributor

nojaf commented May 5, 2021

I believe extending this regex with t with resolve the problem:

let escapedCharacterRegex =
System.Text.RegularExpressions.Regex("(\\\\(a|b|f|n|r|u|v|x|'|\\\"|\\\\))+")

Are you interested in submitting a PR?

@stanciuadrian
Copy link
Contributor Author

Yes.

@nojaf
Copy link
Contributor

nojaf commented May 5, 2021

Great, please read our Contribution Guidelines. You can add you unit test to SynConstTests.fs.
Thank you for your investment.

@stanciuadrian
Copy link
Contributor Author

I went with idiomatic TDD on this one.
After updating the hex escape in string literal should be preserved, 1508 test by adding a \t to the input string the test passed.

So it seems the current code (with no change to escapedCharacterRegex) works fine when formatting "\a\t" but fails with "\t".

Updating escapedCharacterRegex as suggested fixes the issue but there may be a lurking bug around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants