Skip to content

Commit

Permalink
CFamilyLexer: refuse quotes between parentheses for function definiti…
Browse files Browse the repository at this point in the history
…ons and declarations

Something like

id id2("){ ... }");

is no longer wrongly recognized as a "function"

id id2(") {
  ...
}
");

As the difference in the tests shows, this has the unfortunate side
effect that we no longer highlight something like

int f(param="default");

as a function declaration, but it is hard to imagine another way to
fix this (cf. “most vexing parse” problem).

Fixes pygments#2207
  • Loading branch information
jeanas committed Aug 14, 2022
1 parent eefba9b commit a0d664e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pygments/lexers/c_cpp.py
Expand Up @@ -132,9 +132,9 @@ class CFamilyLexer(RegexLexer):
r'(' + _possible_comments + r')' # possible comments
r'(' + _namespaced_ident + r')' # method name
r'(' + _possible_comments + r')' # possible comments
r'(\([^;]*?\))' # signature
r'(\([^;"\']*?\))' # signature
r'(' + _possible_comments + r')' # possible comments
r'([^;{/]*)(\{)',
r'([^;{/"\']*)(\{)',
bygroups(using(this), using(this, state='whitespace'), Name.Function, using(this, state='whitespace'),
using(this), using(this, state='whitespace'), using(this), Punctuation),
'function'),
Expand All @@ -143,9 +143,9 @@ class CFamilyLexer(RegexLexer):
r'(' + _possible_comments + r')' # possible comments
r'(' + _namespaced_ident + r')' # method name
r'(' + _possible_comments + r')' # possible comments
r'(\([^;]*?\))' # signature
r'(\([^;"\']*?\))' # signature
r'(' + _possible_comments + r')' # possible comments
r'([^;/]*)(;)',
r'([^;/"\']*)(;)',
bygroups(using(this), using(this, state='whitespace'), Name.Function, using(this, state='whitespace'),
using(this), using(this, state='whitespace'), using(this), Punctuation)),
include('types'),
Expand Down
2 changes: 1 addition & 1 deletion tests/examplefiles/cpp/example.cpp.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a0d664e

Please sign in to comment.