akuleshov7 / ktoml

Kotlin Multiplatform parser and compile-time serializer/deserializer for TOML format (Native, JS, JVM) based on KxS

Home Page:https://akuleshov7.github.io/ktoml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

prettyPrint() for TomlNode is not working with multiline literal strings

akuleshov7 opened this issue · comments

val string = """
             mls = '''
                 1
                 2
                 3
             '''
"""
val parsedToml = Toml.tomlParser.parseString(string)
parsedToml.prettyPrint()

Will fail with:

com.akuleshov7.ktoml.exceptions.TomlWritingException: Control characters (excluding tab) are not permitted in literal strings. Please check: <     1
     2
     3
 >
	at com.akuleshov7.ktoml.tree.nodes.pairs.values.TomlLiteralString$Companion.escapeQuotesAndVerify(TomlLiteralString.kt:111)

This will happen because now we removed content from nodes and use toString() for printing it. And on that level emitter does not know anything about the type of string, because multiline: Boolean = false by the default.

So the question is: if we really need to remove content from nodes? It increases performance and removes code duplication with emitter, but in such cases as above - we are loosing an information about the source that we are parsing.

@NightEule5 what do you think? There is only one case when I see such problem now - with multiline strings, because only with them we need a multiline = true flag, so it is not so critical. And also it is only needed for us to debug or write tests, so probably should not be a huge problem...

But actually the basic problem looks to be much more simple: we are not setting multiline = true for literal strings while parsing. So when I will fix it - the problem will go away :D