-
Notifications
You must be signed in to change notification settings - Fork 636
Explicit error for comments, with README link #569
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
Conversation
eliben
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'm still thinking about this, but here are some initial comments
Also: add tests
pycparser/c_lexer.py
Outdated
| bad_octal_constant = '0[0-7]*[89]' | ||
|
|
||
| # comments are not supported | ||
| unsupported_c89_comment = r'\/\/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the c89/c99 distinction here. Aren't // just C++ style comments and /* the original C style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it made more sense to describe the comments from a C perspective, rather than a C++ perspective. I'll update this.
Also, I accidentally swapped c89 / c99.
pycparser/c_lexer.py
Outdated
|
|
||
| @TOKEN(unsupported_c89_comment) | ||
| def t_UNSUPPORTED_C89_COMMENT(self, t): | ||
| msg = "Comments are not supported (note: GCC's cpp removes comments, Clang's cpp does not)." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message is way too specific; you have a particular issue you're encountering now, but there are a million other reasons people could try to run pycparser on files with comments. It could point to the repository's README, for example (which has a section on the preprocessor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
A bit more context on my findings: invoking clang's preprocessor as In other words, clang's |
f915e6a to
a3b0bba
Compare
|
PR updated, tests are still TODO. (Edit: added a second commit rather than amend / force-push, to preserve PR context) |
a3b0bba to
06589e7
Compare
|
Ok, tests added to PR. This is ready for a re-review. |
README.rst
Outdated
| ``cpp``. A compatible ``cpp`` handles preprocessing directives like ``#include`` and | ||
| ``#define``, removes comments, and performs other minor tasks that prepare the C | ||
| code for compilation. | ||
| code for compilation. Note that clang's cpp does not remove comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what Clang's cpp is... not clang -E, right? Regardless, such a comment will likely go out of date, and I prefer excluding it. The sentence above says enough about what cpp should do
OK, thanks I understand the context now. Still, I wouldn't say too much about this in the README. I understand you ran into a frustrating situation, but we shouldn't over-index on it. pycparser has been around for ages now, and this very rarely comes up. The errors you added should improve the situation significantly, but I don't want to maintain additional statements and flowcharts on the README that may go stale at any point |
|
Sorry for the confusion: the flowchart was just for communication during this PR and will not be introduced into the repo. I picked up on and am trying hard to satisfy the desire to avoid over-indexing on error specificity, but I'm going to be frank: I feel the current PR's user help on this topic is already too minimal. The current PR:
To communicate my thinking on this topic, here's a possible spectrum of context we could offer the user: The minimum context the user needs in order to understand (but not fix) the problem is:
The minimum context to fix the problem would also include:
However, I also feel that the majority of developers are on Macs these days. A pleasant experience would also include direct, specific advice for that majority:
Please understand that the user help in the current PR is already less that what I'd prefer. |
|
Thinking about the staleness issue a bit more, I could change "Note that clang's cpp does not remove comments" to something like "Gcc includes a cpp which meets these requirements". That would be less likely to go stale, as it is independent of clang's behavior, and I would guess it is very unlikely that gcc would ever change their implementation to stop stripping comments. |
|
Thanks for sharing your thoughts. The PR's largest change is adding an explicit error "comments are not supported" with a README link. A user following this link will read about the requirements of cpp and will notice their cpp doesn't do the job. The text also says one may use I really think this is sufficient for now. By the way, it's entirely possible that Mac's cpp not removing comments is a new thing, because this issue would have come up more much frequently otherwise. These things change from time to time, and I want to keep our documentation as resilient as possible to these changes (it already talks quite a bit about the cpp issue!!) |
|
Oh my gosh, I am so sorry, I somehow missed that while clang's |
|
Ok, PR updated to remove "Note that clang's cpp does not remove comments". |

@eliben thanks so much for your blog and for pycparser!
This PR adds an explicit exception for comments, with a hint to the user that clang's cpp does not remove comments, and that simply using gcc's cpp instead will likely solve their problem.
See also my comment on a related github issue.
Hopefully this will curb the endless flood of "comments don't work" github issues! 😭