diff --git a/pygments/lexers/c_cpp.py b/pygments/lexers/c_cpp.py index 5d3b9c7d11..59749fa670 100644 --- a/pygments/lexers/c_cpp.py +++ b/pygments/lexers/c_cpp.py @@ -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'), @@ -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'), diff --git a/tests/examplefiles/cpp/example.cpp.output b/tests/examplefiles/cpp/example.cpp.output index b82dd0955b..1e2444fce8 100644 --- a/tests/examplefiles/cpp/example.cpp.output +++ b/tests/examplefiles/cpp/example.cpp.output @@ -944,7 +944,7 @@ ' ' Text.Whitespace 'string' Name ' ' Text.Whitespace -'getOpenTag' Name.Function +'getOpenTag' Name '(' Punctuation 'const' Keyword ' ' Text.Whitespace diff --git a/tests/snippets/c/test_string_resembling_decl_end.txt b/tests/snippets/c/test_string_resembling_decl_end.txt new file mode 100644 index 0000000000..17ce2233e9 --- /dev/null +++ b/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