-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
option to not eat comments #154
Comments
Has a decision been made regarding attaching comments to nodes during parsing? Additionally, it seems odd that there is no OnComment event handler. |
I haven't considered this issue in a while, but I'm happy to accept patches. I think an event handler for comments would be pretty uncontroversial. |
I also think this feature would be useful. It would be nice to be able to preserve comments the user put into a file when rewriting the file (as stated above). |
@jbeder, I'm trying to see about adding comments. Reading through concerns above and in other related tickets it looks like folks expect a comment to come after the thing it describes, but I think it may make sense to have both a "pre" and "post" comment. For example. # comment before a sequence
- first item
- # comment before a scalar
second item # trailing comment
# this is where it gets confusing
# I guess it could be possible to detect equivalent Mark.colum of consecutive
# comments to determine that it appears as though someone is continuing.
# in my mind, this is clearly a comment describing the last item, but is inconsistent
# with where the comment for the "second item" was placed
- last item I guess I have a couple questions, then I'll probably have more should I make any progress.
p.s. I am a huge fan of "I don't want yaml-cpp to output nasty YAML." And if works, one might be able to create "yaml-format" utilizing "yaml-cpp". |
Any progress on this one? The ability to edit commented YAML-files would be awesome. @SimplyKnownAsG From what I can see, Nodes in yaml-cpp are either scalars or collections (mappings or sequences). Because of that yaml-cpp can easily represent things like complex keys (keys that aren't scalars) by implementing the subscript operator like this: Node operator[](const Key& key); This is very nice and it makes Node versatile. Saying that Node can be a comment would lead to absurdities, at least for the above reason that comments cannot act as a key in a mapping. There are other reasons, such as the fact that comments can be placed between a key and a value, or that it can be placed before a document even starts (before a "---"). Excluding that idea would leave us with (at least) the second solution, to make comments a part of Node-objects. I'm planning to take a look at the code some more and see if/how this could be done. Wouldn't it be good to extend this feature to include empty lines as well? Because those are also part of the readability of a document. |
Would be great feature! |
I also need this feature. Here in this example I send to the server the node["configurationToSendServer"] and its mark positions, that I can handle the error positions. This works perfect if I don't have comments inside the configurationToSendServer. In the case that we have the comments, the node serialized and sent to the server is ate and will not appear in the server side, causing a wrong Mark information. name: example
description: "some decription"
configurationToSendServer:
name: execution
# comment to describe something
# the next line is wrong configuration for the server
serverProperty: foobarWrongProperty |
A lot of work, but starting with taking care of the simplest case, i.e., separate comment lines above the actual thing, would help a lot! |
I think it can be workable. You simply devine a new value type, a "CommentKey". The key could simply be a unique string, for example "#124" for a comment on line 124. You could similarly have a Comment value, or it could simply be a scalar. The nice thing here is that by containing whitespace and comments in the tree, you can emit the tree back out as it came in, after modifying things. I would personally like it so that Nodes could have comments attached to them if the comment appears on the same line; this could simply be an attribute in the YAML node, and can be added to the tree structure. I like this, because I can construct a template configuration tree with comments, unify it with the user config, then recreate it (without having to muck with the Emitter) |
I am inclined to agree with this. Comments cannot be a value, especially with lists:
If we treat the comment as a value, then I suppose there are actually 4 items here: Instead, I think the Node needs to own the comments associated with it. I would store them in a few strings: before, inline, and after, or head, text, and tail (etc. regarding the naming):
Are there situations where this sort of division can not be ideal - sure. Commenting out an item from the end of a list, for example, will add it to the beginning of the next item. But
|
Original issue reported on code.google.com by
chan...@gmail.com
on 9 Mar 2012 at 10:58The text was updated successfully, but these errors were encountered: