Store comments in the tree
NightEule5 opened this issue · comments
Strixpyrr commented
For encoding, we should support adding comments to the file. Since an AddComment
annotation is suggested in #114, I assume this is an intended feature. We'll need to add comments to the tree
Comments are likely to be "attached" to other elements, like:
# Comment
key = "value" # Other comment
So I think it makes sense to apply comments to a TomlNode
instance, rather than being nodes themselves.
Something like this:
public sealed class TomlNode(
public open val content: String,
public open val lineNo: Int,
public val comments: List<String>,
public val inlineComment: String,
public open val config: TomlConfig = TomlConfig()
)
Or:
data class TomlComments(
public val comments: List<String>,
public val inlineComments: String
)
public sealed class TomlNode(
public open val content: String,
public open val lineNo: Int,
public val comments: TomlComments,
public open val config: TomlConfig = TomlConfig()
)
We could also optionally retain or ignore comments during parsing with an ignoreComments
property in the config