-
Notifications
You must be signed in to change notification settings - Fork 153
Improve #error and #warning tokenization #251
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,23 +94,62 @@ | |
] | ||
} | ||
{ | ||
'begin': '^\\s*((#)\\s*(error|warning))\\b' | ||
'captures': | ||
'begin': '^\\s*((#)\\s*(error|warning))\\b\\s*' | ||
'beginCaptures': | ||
'1': | ||
'name': 'keyword.control.directive.diagnostic.$3.c' | ||
'2': | ||
'name': 'punctuation.definition.directive.c' | ||
'end': '(?<!\\\\)(?=\\n)|(?=//)|(?=/\\*(?!.*\\\\\\s*\\n))' | ||
'end': '(?<!\\\\)(?=\\n)' | ||
'name': 'meta.preprocessor.diagnostic.c' | ||
'patterns': [ | ||
{ | ||
'include': '#comments' | ||
# double quoted string patterns for #error/warning lines (terminates at newline w/o line_continuation_character) | ||
'begin': '"' | ||
'beginCaptures': | ||
'0': | ||
'name': 'punctuation.definition.string.begin.c' | ||
'end': '"|(?<!\\\\)(?=\\s*\\n)' | ||
'endCaptures': | ||
'0': | ||
'name': 'punctuation.definition.string.end.c' | ||
'name': 'string.quoted.double.c' | ||
'patterns': [ | ||
{ | ||
'include': '#line_continuation_character' | ||
} | ||
] | ||
} | ||
{ | ||
'include': '#strings' | ||
# single quoted string patterns for #error/warning lines (terminates at newline w/o line_continuation_character) | ||
'begin': '\'' | ||
'beginCaptures': | ||
'0': | ||
'name': 'punctuation.definition.string.begin.c' | ||
'end': '\'|(?<!\\\\)(?=\\s*\\n)' | ||
'endCaptures': | ||
'0': | ||
'name': 'punctuation.definition.string.end.c' | ||
'name': 'string.quoted.single.c' | ||
'patterns': [ | ||
{ | ||
'include': '#line_continuation_character' | ||
} | ||
] | ||
} | ||
{ | ||
'include': '#line_continuation_character' | ||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. Should just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name chose was based on already present There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L133 is |
||
'patterns': [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 {
'match': '[\'"]'
'name': 'invalid.deprecated.mismatched-quote.c'
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried your proposal and it looks like this: My understanding is that GCC is not that cleaver. There is no warning about missing/missed used of quote for this: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
{ | ||
'include': '#line_continuation_character' | ||
} | ||
{ | ||
'include': '#comments' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, GCC output for If error message is quoted, then comment becomes part of it. |
||
} | ||
] | ||
} | ||
] | ||
} | ||
|
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.