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
Allow expressions in comments #300
Conversation
Needed to remove some comments from pr2.urdf
What would be the escape sequence? As in: how would someone prevent |
Same as in normal text expressions: multiple dollar signs: Lines 573 to 576 in 6d67741
|
hm, that's a bit annoying, certainly for documentation. We would then have to add something like:
otherwise I guarantee some of "my" users will start trying to use |
I get your point. What syntax do you propose then? |
I think the key question is where do you want to document what. You still can use single-dollar expressions as documentation in the xacro file. However, they will get replaced in the final file. Does that matter? The documentation was intended for the xacro in this case. If you want to document in the final file, just provide double dollars in the xacro. |
Yes, that's true. it will be confusing for users looking at the results of Edit: so I withdraw the question / remark. |
That's the basic idea of the macro processor 😉 |
So, you approve? |
I don't really have an opinion on this one. But that's mostly because there is no use-case described for this. |
Oh, my use case is to generate comments within a macro, documenting the generated doc: <robot>
<xacro:macro name="link" params="name">
<!-- link ${name} -->
<link name="${name}"/>
</xacro:macro>
<xacro:link name="foo"/>
</robot> becomes <robot>
<!-- link foo -->
<link name="foo"/>
</robot> |
Ok. I would have always expected the generated Is this in the context of the updates to the |
Yes, indeed, I would like to use the new feature there. |
Just encountered an error because of this, which took awhile to figure out because I didn't expect it to be a problem in an upstream ROS package. Personally, I don't think evaluating anything in comments makes sense, given that no other language does it. While I understand the desire to evalutate expressions to generate better looking documentation, perhaps the default behaviour should be no evaluation, and you can use some sort of escape sequence to force |
|
Releases triggered:
Consider using the debian packages from the ROS |
That's certainly a valid point of view. I'd still prefer xacro wouldn't parse comments by default. As a programmer, I don't expect the preprocessor to break because of some stuff that I have commented out. Right now, the changed behavior of xacro breaks lots of existing .xacro files everywhere that have commented-out sections with substitution args. |
@rhaschke: would it perhaps be an option to make this an opt-in? For your use-case, you could enable it. For others, it would be disabled by default. |
The latest melodic-devel / noetic-devel branch only throw a warning (but don't error) anymore on invalid expressions in the comments. |
I second @mintar's request for hiding this behavior behind a non-default parameter. Yes, warnings will not break stuff, but it's still a bit unexpected for me to comment-out a part of code and receive warnings relating to it. |
Not fully. I try to fix all warnings, so if it remains a warning I'll update my .xacro files to remove them - probably by mutilating the code so that xacro doesn't recognize the substitution arg any more, such as inserting a space between So I'm voting for hiding the new behavior behind a non-default parameter. But ultimately it's your decision. |
I agree: disabling some broken code by commenting, is a common use case that should be supported.
What do you think? |
All 3 options are fine with me. Personally, I think options 2 is the best one, because it is most explicit, most robust and also simplest. For example, you have a xacro with comments that should be evaluated, but you also include xacros from other packages. Unaware of your use case, the downstream package maintainer changes their xacro. With option 3, this could break your package, but it's no problem for option 2. |
Option 3 is most dangerous, no discussion. |
What about modified nr. 1:
That would allow enabling evaluation even for blocks of multiple comments (these are pretty commonly generated by IDEs when you comment-out a section of XML files). |
This would be more verbose for typing 😞 |
Okay, then option 2 seems the most reasonable. Your doubts were about implementation, i.e. whether you are able to modify comments from within xacro? If yes, then just removing the verbatim string that enables the processing would be enough, wouldn't it? |
No, I wouldn't like to keep all of the surrounding whitespace. But, how much to remove of this whitespace? |
Require exactly 1 witespace at the beginning |
What about these variants:
Removing exactly |
I don't really like the colon in the last line of your example. What if someone forgets it? Then the rest of the text would be skipped? |
According to the discussion in ros#300, comment evaluation should be an opt-in feature, primarily because commenting is regularly used to simply disable broken code. Obviously, in such a use case, comment evaluation would be counterproductive. Now, comment evaluation can be enabled with a special comment: `<!-- xacro:eval-comments -->` or `<!-- xacro:eval-comments:on -->` It remains active until: - the current XML tag's scope is left (or a new tag entered) - another tag or non-whitespace text is processed Reverts 43ceb30, i.e. issues an error on failed expression evaluation again.
According to the discussion in #300, comment evaluation should be an opt-in feature, primarily because commenting is regularly used to simply disable broken code. Obviously, in such a use case, comment evaluation would be counterproductive. Now, comment evaluation can be enabled with a special comment: `<!-- xacro:eval-comments -->` or `<!-- xacro:eval-comments:on -->` It remains active for the following comments until: - the current XML tag's scope is left (or a new tag entered) - another tag or non-whitespace text is processed - it becomes explicitly disabled via: `<!-- xacro:eval-comments:off -->` Reverts 43ceb30, i.e. issues an error on failed expression evaluation again.
I decided to go for a variant of #300 (comment). See #310. |
Implements #299.