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: Fix matching of function parameters #2210

Merged
merged 1 commit into from Aug 18, 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
16 changes: 8 additions & 8 deletions pygments/lexers/c_cpp.py
Expand Up @@ -129,22 +129,22 @@ class CFamilyLexer(RegexLexer):
include('keywords'),
# functions
(r'(' + _namespaced_ident + r'(?:[&*\s])+)' # return arguments
r'(' + _possible_comments + r')' # possible comments
r'(' + _possible_comments + r')'
r'(' + _namespaced_ident + r')' # method name
r'(' + _possible_comments + r')' # possible comments
r'(\([^;"\']*?\))' # signature
r'(' + _possible_comments + r')' # possible comments
r'(' + _possible_comments + r')'
r'(\([^;"\')]*?\))' # signature
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'),
# function declarations
(r'(' + _namespaced_ident + r'(?:[&*\s])+)' # return arguments
r'(' + _possible_comments + r')' # possible comments
r'(' + _possible_comments + r')'
r'(' + _namespaced_ident + r')' # method name
r'(' + _possible_comments + r')' # possible comments
r'(\([^;"\']*?\))' # signature
r'(' + _possible_comments + r')' # possible comments
r'(' + _possible_comments + r')'
r'(\([^;"\')]*?\))' # signature
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)),
Expand Down
18 changes: 17 additions & 1 deletion tests/examplefiles/cpp/functions.cpp
Expand Up @@ -87,4 +87,20 @@ class raz {
// Make sure these are not functions:
else if(flag && func_call()) {}
new T();
const operator int() const {} // so int is lexed as type and not function.name
const operator int() const {} // so int is lexed as type and not function.name

class foo bar : public raz
{
Q_OBJECT
/// \cond INCLUDE_QPROPERTIES
Q_PROPERTY(arg1 arg2)
/// \endcond

public:
/*!
Lorem ipsum core vanditi.
*/
enum duck { dog, // Comment.
cat // Comment (see \ref replot).
};
};
73 changes: 73 additions & 0 deletions tests/examplefiles/cpp/functions.cpp.output

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