kowainik / tomland

🏝 Bidirectional TOML serialization
https://kowainik.github.io/posts/2019-01-14-tomland
Mozilla Public License 2.0
121 stars 39 forks source link

[Parser] Multiline string #353

Closed dariodsa closed 3 years ago

dariodsa commented 3 years ago

Hi, I am working on an issue #334 and I during testing of my code I step upon on some TOML example.

*Toml> Toml.encode (Toml.text "a") "\n"
"a = \"\\n\"\n"

This string is a multiline string and it should be followed and ended with triple quotes so I think that this shouldn't be parsed in TOML object. I don't am I missing anything with this example.

chshersh commented 3 years ago

@dariodsa The string you see is actually the result of applying Show instance to Text. If you print it to terminal, the TOML will look like this:

ghci> putStrLn "a = \"\\n\"\n"
a = "\n"

The TOML spec allows using escaped sequences in ordinary strings, including the \n symbol:

I think there exist multiple ways to format a string, but implementing those ways would complicate the logic significantly, so I think it's okay to have the single working version of encoding of strings 🙂