[Bug]: C/C++: Highlight the import files
lzhiyong opened this issue · comments
Description
the CPlusPlusTokenMaker.flex
and CTokenMaker.flex
can't parse header files correctly.
like this: <xxx.h>
Expected behavior
Can correctly highlight header files.
like this:
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; }
}
}
@bobbylight thanks
@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;
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?
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;