Skip to content
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

CFamilyLexer: refuse quotes between parentheses for function definiti… #2208

Merged
merged 1 commit into from Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.

41 changes: 41 additions & 0 deletions tests/snippets/c/test_string_resembling_decl_end.txt
@@ -0,0 +1,41 @@
---input---
// This should not be recognized as a function declaration followed by
// garbage.
string xyz(");");

// This should not be recognized as a function definition.

string xyz("){ }");

---tokens---
'// This should not be recognized as a function declaration followed by\n' Comment.Single

'// garbage.\n' Comment.Single

'string' Name
' ' Text.Whitespace
'xyz' Name
'(' Punctuation
'"' Literal.String
');' Literal.String
'"' Literal.String
')' Punctuation
';' Punctuation
'\n' Text.Whitespace

'\n' Text.Whitespace

'// This should not be recognized as a function definition.\n' Comment.Single

'\n' Text.Whitespace

'string' Name
' ' Text.Whitespace
'xyz' Name
'(' Punctuation
'"' Literal.String
'){ }' Literal.String
'"' Literal.String
')' Punctuation
';' Punctuation
'\n' Text.Whitespace