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

AddComment/trailing trivias do not write in the correct order #7

Closed
marekr opened this issue Apr 13, 2020 · 3 comments
Closed

AddComment/trailing trivias do not write in the correct order #7

marekr opened this issue Apr 13, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@marekr
Copy link

marekr commented Apr 13, 2020

I'm not sure what the true intended "way to use" AddComment is

But doing something like


                var table = new TableSyntax("test");
                doc.Tables.Add(table);
                table.AddComment("banana");

and later


                    var val = new StringValueSyntax("b value");
                    var item = new KeyValueSyntax("floopy a", "a value");
                    item.AddComment("something");

results in


#banana[test]
"floopy a" = # something"b value"

From what I can tell it's because trailing trivias are attached to items separately than the rest of the syntax and in the recursive loop its iterating, it'll hit the print of trivias before it finishes stacking children and printing them.

@xoofx xoofx added the bug Something isn't working label Apr 13, 2020
@xoofx
Copy link
Owner

xoofx commented Apr 13, 2020

Indeed, there is a bug in the serialization. I will push a fix later today.

@marekr
Copy link
Author

marekr commented Apr 14, 2020

@xoofx Thanks for the fix.
It works now for table items just fine.
One case though that doesn't quite work the way I expect it. I would like to add a comment next to the table header

[apples] # A red fruit

But if you add a trailing comment on the tablesyntax, it gets appended after all the key/value table items. If you add a trailing comment on the KeySyntax passed to TableSyntax, the comment gets inserted inside the brackets

[apples#A red fruit]

@xoofx
Copy link
Owner

xoofx commented Apr 14, 2020

That's intended, as the XXXSyntax has to respect anything you could write in a TOML to document (so you can place trivias all around).

You need to add it after table.CloseBracket.AddTrailingWhitespace().AddTrailingComment("your comment"), you can write your own extension method (e.g AddTableHeaderComment).

@xoofx xoofx closed this as completed Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants