-
Notifications
You must be signed in to change notification settings - Fork 154
Improve #error and #warning tokenization #251
base: master
Are you sure you want to change the base?
Conversation
error/warning message are now properly scoped.
|
What's the status of this pull request? If this fixes the issue without any regressions we would like to get the fix in. |
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.
Sorry for the delay. Left some comments, but this will need spec coverage in order to be merged.
# unquoted strings patterns for #error/warning lines (terminates at newline w/o line_continuation_character) | ||
'begin': '[^\'"]' | ||
'end': '(?<!\\\\)(?=\\s*\\n)' | ||
'name': 'string.unquoted.single.c' |
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.
Should just be string.unquoted.c
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.
Name chose was based on already present string.quoted.single.c
at line 133. Should I still change it to string.unquoted.c
?
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.
L133 is string.quoted.single.c
because it uses single quotes. As an unquoted string (by the name) has no quotes, it should just be string.unquoted.c
. This is consistent with other languages across the Atom organization.
'begin': '[^\'"]' | ||
'end': '(?<!\\\\)(?=\\s*\\n)' | ||
'name': 'string.unquoted.single.c' | ||
'patterns': [ |
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.
Given that GCC emits warnings by default if you have mismatched quotes, would it make sense to match for quotes here and scope them as invalid.deprecated.mismatched-quote.c
?
{
'match': '[\'"]'
'name': 'invalid.deprecated.mismatched-quote.c'
}
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 tried your proposal and it looks like this:
I'm not sure what you means, English is not my mother tongue, I might have missed something.
My understanding is that GCC is not that cleaver. There is no warning about missing/missed used of quote for this:
#warning Well, you don't actually need quote, but it's highly recommended
but there is for:
#error doesn't
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.
👍 then let's not add it to avoid highlighting quotes as errors when they shouldn't be.
'1': | ||
'name': 'keyword.control.directive.diagnostic.$3.c' | ||
'2': | ||
'name': 'punctuation.definition.directive.c' | ||
'end': '(?<!\\\\)(?=\\n)|(?=//)|(?=/\\*(?!.*\\\\\\s*\\n))' | ||
'end': '(?<!\\\\)(?=\\n)' |
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.
It looks like the lookahead for comments was removed here. Was that intentional?
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.
Short answer, yes. I see no benefit of having this, thus I removed it. I have to admit that it might not be the proper way to do things. While we have the opportunity, could you provide an example where having this makes a difference? I couldn't come up with one.
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.
You're right, I previously thought that #error test /* comment */ test
would terminate the error message at the comment, but clearly based on your tests it doesn't.
'include': '#line_continuation_character' | ||
} | ||
{ | ||
'include': '#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.
It looks like this will match comments inside the unquoted error message such as #error test /* comment */ test
.
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.
Correct, GCC output for
#error Unquoted message, /* yet another one */ but different
will be
issue_233.c:28:2: error: #error Unquoted message, but different
Comment is not actually part of the error message when unquoted.
If error message is quoted, then comment becomes part of it.
Thanks for the detailed responses @fnadeau 🙇. If you could just change the scope to |
Update: I'm working on this still. I found issues with error/warning message on multiple lines when updating spec file. |
What’s the status on this? (Jeff-hykin made that vs code thingy but I still want to use atom) |
TL;DR
Hi! It's a bit late where I'm from rn 🥱, so I'm not in a position to process all the regex above; please bear with me. i.e., the following seems fine… #error The quick brown fox called 'John Appleseed' jumped around and broke my code… for a while but stuff breaks when the viewer encounters this: #error The quick brown fox jumped, halted, caught its breath… \
and then proceeded to step all over my code. Again, for a while. PS: I know a lot of you hardcore folks are going to be mad that I soiled the ethos of C-like coding and all by even trying to write error/warning messages that are long enough to be broken into separate lines 😅, but once I found the little glitch, I couldn't forget about it… |
Atom defaults to the tree parser. If this bug still exists on the tree parser, then we should open up an issue on the c++ tree sitter grammar repo. However, it is still possible to use the textmate parser in atom. In that case the cpp grammar I made can be ported almost effortlessly (only metadata and file name changes). But, the most up to date version of Atom has been the atom community edition. So we should probably make a fork of this repo, then ask them to use the fork instead, because Atom team basically isn't merging anything. |
Seems,cool! |
Fix highlight of error directive
Requirements
Description of the Change
This treats text following warning and error as plain text with no interpretation.
There is one flaw with #233:
From: https://gcc.gnu.org/onlinedocs/cpp/Diagnostics.html
'The line must consist of complete tokens. It is wisest to make the argument of these directives be a single string constant; this avoids problems with apostrophes and the like.'
Unmatch token will generate compilation warning:
GCC does threat comments in a warning/error as the message and not has comment.
Alternate Designs
None
Benefits
Fix highlight issue when unmatch token are in a error/warning comment
Possible Drawbacks
None known.
Applicable Issues
Fixes #233