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

Wrongly highlited comments in #include lines #1162

Closed
Anteru opened this issue Aug 31, 2019 · 2 comments
Closed

Wrongly highlited comments in #include lines #1162

Anteru opened this issue Aug 31, 2019 · 2 comments
Labels
S-major severity: major T-bug type: a bug X-imported imported from Bitbucket

Comments

@Anteru
Copy link
Collaborator

Anteru commented Aug 31, 2019

(Original issue 1458 created by pyannis on 2018-07-19T10:32:26.407841+00:00)

The comments in a "#include ..." line are not highlighted correctly, as can be seen in the image below.

img1.png

Sample C++ code to show the problem:

#!C++
#include <iostream>
#include <stdlib.h>     // for the random numbers in main...
#include     <sys/types.h>  // for getpid()
#include /* inline comment 1 */ <unistd.h>     /* in_c_1   */   // for getpid()
#include                        <unistd.h>     /* in_c_2   */
#include /* inline com"ment 2 */ <unistd.h>                      // for getpid()
#include <stdio.h>     // for sp<r"intf()

// Next include lines for pygments test only...
#include "stdio.h"     // for spr"intf() /* not_inline  < > <" "" >>>
#include "<stdio.h">     // for spr"intf() /* not_inline  < > <" "" >>>
#include <"stdio.h>"     // for spr"intf() /* not_inline  < > <" "" >>>
#include stdio.h     // for spr"intf() /* not_inline  < > <" "" >>>
#include /* abc */ stdio.h     // for spr"intf() /* not_inline  < > <" "" >>>

using namespace std;    // an inline comment...

/*! \file matrix.cpp This is a class to manipulate 2D matrices.
    It also contain a main program to test its functionality.
 */

//! This is a class to manipulate 2D matrices.

/*! The Matrix objects are constructed providing their dimensions.<br>
    The matrix elements should be set via the #Mij method.<br>
    Various matrix operations are defined for the Matrix class.
 */

//------------------------------------------------------
class Matrix {
public:
  //! Constructor
  Matrix(int m, int n);
@Anteru Anteru added T-bug type: a bug X-imported imported from Bitbucket S-major severity: major labels Aug 31, 2019
@Anteru
Copy link
Collaborator Author

Anteru commented Aug 31, 2019

(Original comment by pyannis on 2018-07-19T11:17:48.934181+00:00)

I have a modification for c_cpp.py that solves this issue:

#!diff
# HG changeset patch
# User pyannis
# Date 1531996802 -7200
#      Thu Jul 19 12:40:02 2018 +0200
# Node ID d304b1e694c10efc86d674b3f0472073de92f0b6
# Parent  7941677dc77d4f2bf0bbd6140ade85a9454b8b80
Addresses Issue #1458

diff -r 7941677dc77d -r d304b1e694c1 pygments/lexers/c_cpp.py
--- a/pygments/lexers/c_cpp.py	Mon Mar 13 19:16:03 2017 +0000
+++ b/pygments/lexers/c_cpp.py	Thu Jul 19 12:40:02 2018 +0200
@@ -127,8 +127,8 @@
             (r'\\', String),  # stray backslash
         ],
         'macro': [
-            (r'(include)(' + _ws1 + r')([^\n]+)',
-             bygroups(Comment.Preproc, Text, Comment.PreprocFile)),
+            (r'(include)('+_ws1+r')("[^"]+")([^\n]*)', bygroups(Comment.Preproc, using(this), Comment.PreprocFile, Comment.Single)),
+            (r'(include)('+_ws1+r')(<[^>]+>)([^\n]*)', bygroups(Comment.Preproc, using(this), Comment.PreprocFile, Comment.Single)),
             (r'[^/\n]+', Comment.Preproc),
             (r'/[*](.|\n)*?[*]/', Comment.Multiline),
             (r'//.*?\n', Comment.Single, '#pop'),

Using this modified c_cpp.py, with the same C++ code as in the previous comment, I get what I expect:
img2.png

hgruniaux added a commit to hgruniaux/pygments that referenced this issue Jan 6, 2020
Anteru pushed a commit that referenced this issue May 22, 2020
* General improvement to the C/C++ lexer

* Add missing C11 keywords

Add '_Imaginary', '_Static_assert', '_Atomic' keywords.

* Highlight C11 std atomic types (#906)

Add support for C11 atomic types `atomic_*`.

* Extended character literals prefixes for C/C++

Add support for `u'a'`, `U'a'` (C++11, C11), and `u8'a'` (C++17, C2x).
[Reference](https://en.cppreference.com/w/cpp/language/character_literal).
[Reference](https://en.cppreference.com/w/c/language/character_constant).

* Fix bad floating point highlighting in C lexer

Fix bad highlighting for `5.`, where `.` was not highlighted.

* Fix hex floating literal highlighting in C

Hexadecimal floating point literals needs an exponent (`0x5p8`). Before this commit, event floating-point literals without an exponent were accepted (e.g. `0x5.5`).

* Support '$' in identifiers, C/C++

Some old C/C++ compilers have supported `$` (dollar sign) in identifiers, and some news continue to support this for legacy reasons. That is, some codes may use them, and it is therefore preferable to color them correctly.

* Cleaning and fixing some bugs in C/C++ lexer

- Add '_Pragma' keyword
- Recognize the identifier following 'typename' as Name.Class
- Do not tokenize 'class' or 'struct' following 'enum' as Name.Class, but instead as Keyword (C++ lexer)
- Move some C++ keywords to the generic lexer (`alignas`, `alignof`, etc...)
- Add some C keywords (`noreturn`, `imaginary`, `complex`)
- And others things...

* Fix building errors in C/C++ lexer

* Fix bug in C/C++

Now `class`, `struct`, `enum`, `union`, etc... can be used alone. Previously, the lexer do not recognizes them if they are not followed by an identifier. This regression was introduced in 013bf6a by me.

* Reuse old states names for C/C++

Some lexers depends on the old states names (e.g. `classname` state) to works. This commit, reintroduce these old names.

* Improve C/C++ lexer documentation

* Correct english errors in C lexer documentation

* Cleaning and Unicode literals for C

* Move Unicode literals from C++ to generic C

* Remove useless 'classname' state in ECLexer

* Revert "Remove useless 'classname' state in ECLexer"

This reverts commit 89a0c13.

* Revert "Revert "Remove useless 'classname' state in ECLexer""

This reverts commit 2d47343.

* Add support for UCNs in C and C++

* Apply correction from #1162

Solves #1162

* Correctly highlights negatives numbers in C++

* Revert some changes from 8fe8ed6

* Add unicode suffixes to C++ raw string literals

* Solves #1166

* Fix previous regression in C like lexer

* Fix invalid regex in C like lexer

* Fix #1396 and now are identifiers support UCNs in C and C++ lexer

* Update AUTHORS

* Add missing Python raw string prefix

Co-authored-by: Hubert Gruniaux <42495291+HubertGruniaux@users.noreply.github.com>
@Anteru
Copy link
Collaborator Author

Anteru commented May 22, 2020

Fixed by #1350

@Anteru Anteru closed this as completed May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-major severity: major T-bug type: a bug X-imported imported from Bitbucket
Projects
None yet
Development

No branches or pull requests

1 participant