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

[Bug]: C/C++: Highlight the import files #461

Closed
lzhiyong opened this issue Sep 29, 2022 · 4 comments
Closed

[Bug]: C/C++: Highlight the import files #461

lzhiyong opened this issue Sep 29, 2022 · 4 comments
Assignees
Labels
Milestone

Comments

@lzhiyong
Copy link

lzhiyong commented Sep 29, 2022

Description
the CPlusPlusTokenMaker.flex and CTokenMaker.flex can't parse header files correctly.

like this: <xxx.h>

IMG_20220929_190938

Expected behavior
Can correctly highlight header files.

like this:

IMG_20220929_191008

Java version
openjdk-17

Additional context
I can't fix this as I'm not familiar with the Jflex syntax.
see the cpp.flex

Pseudo code:

/* Add state to import files */
%state IMPORT_FILE

%%

<YYINITIAL> {
    ...
    /* Preprocessor directives */
    "#"{WhiteSpace}*{PreprocessorWord}    { start = zzMarkedPos-2; yybegin(IMPORT_FILE); }
  
    <IMPORT_FILE>{
        /* <xxx.h> or <xxx> as the StringLiteral  */
	{WhiteSpace}\*<{AnyChrChr}>    { int temp=zzStartRead; addToken(start,zzStartRead-1, Token.PREPROCESSOR); addToken(temp,zzMarkedPos-1, Token.LITERAL_CHAR); start = zzMarkedPos; }
	\n			{ addToken(start,zzStartRead-1, Token.LITERAL_CHAR); return firstToken; }
	<<EOF>>			{ addToken(start,zzStartRead-1, Token.LITERAL_CHAR); return firstToken; }
    }

}
@lzhiyong lzhiyong added the bug label Sep 29, 2022
@bobbylight bobbylight self-assigned this Oct 22, 2022
@bobbylight bobbylight added this to the 3.3.1 milestone Oct 22, 2022
@lzhiyong
Copy link
Author

@bobbylight thanks

@lzhiyong
Copy link
Author

lzhiyong commented Oct 26, 2022

IMG_20221026_172140


@bobbylight, there are still some problems.

// contains /
#include <sys/types.h>

// contains -
#include <gnu/libc-version.h>

// contains multiple spaces between # and include
// contains multiple spaces between include and <
# include    <stdio.h>
#        include <math.h>

I think the correct expression should be "#"[ \t\f]*"include"[ \t\f]*"<"[A-Za-z0-9_.-/]+">"


In addition, is there a way to highlight the import file? like Java, kotlin...

// highlight the java.util.ArrayList
import java.util.ArrayList;

bobbylight added a commit that referenced this issue Oct 29, 2022
@bobbylight
Copy link
Owner

Thanks, I've addressed the whitespace and / and - characters and published a 3.3.1-SNAPSHOT build to Sonatype with these changes.

As for your second question, are you asking for a way to highlight the imported file a different color than the surrounding < and > characters? Or are you asking if we can be smarter and highlight files known to be in the standard library?

@lzhiyong
Copy link
Author

lzhiyong commented Oct 29, 2022

As for your second question, are you asking for a way to highlight the imported file a different color than the surrounding < and > characters? Or are you asking if we can be smarter and highlight files known to be in the standard library?

@bobbylight thanks, Specify package name color
for example:

// like include 

// highlight the 'com.xxx.package_name'
package com.xxx.package_name;

// highlight the 'com.xxx.class_name'
import com.xxx.class_name;

@bobbylight bobbylight changed the title [Bug]: Highlight the import files [Bug]: C/C++: Highlight the import files Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants