1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
John Camelon 2004-06-08 17:57:37 +00:00
parent 1a728b8a2a
commit 8b2e0e8b4d
6 changed files with 249 additions and 129 deletions

View file

@ -28,5 +28,6 @@ public class Directives {
public static final String POUND_PRAGMA = "#pragma"; //$NON-NLS-1$
public static final String POUND_ELIF = "#elif"; //$NON-NLS-1$
public static final String POUND_BLANK = "#"; //$NON-NLS-1$
public static final String _PRAGMA = "_Pragma"; //$NON-NLS-1$
}

View file

@ -27,6 +27,8 @@ public class KeywordSetKey extends Enum
public static final KeywordSetKey EXPRESSION = new KeywordSetKey( 9 );
public static final KeywordSetKey MEMBER = new KeywordSetKey(10);
public static final KeywordSetKey ALL = new KeywordSetKey( 11 );
public static final KeywordSetKey KEYWORDS = new KeywordSetKey( 12 );
public static final KeywordSetKey TYPES = new KeywordSetKey( 13 );
/**
* @param enumValue
*/

View file

@ -736,7 +736,7 @@ public final class Scanner implements IScanner, IScannerData {
private static final String PASTING = "<pasting>"; //$NON-NLS-1$
private static final String DEFINED = "defined"; //$NON-NLS-1$
private static final String _PRAGMA = "_Pragma"; //$NON-NLS-1$
private static final String POUND_DEFINE = "#define "; //$NON-NLS-1$
private IScannerContext lastContext = null;
@ -1584,7 +1584,7 @@ public final class Scanner implements IScanner, IScannerData {
if (ident.equals(DEFINED))
return newToken(IToken.tINTEGER, handleDefinedMacro());
if( ident.equals(_PRAGMA) && language == ParserLanguage.C )
if( ident.equals(Directives._PRAGMA) && language == ParserLanguage.C )
{
handlePragmaOperator();
return null;

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
*/
public class KeywordSets {
public static Set getKeywords( KeywordSetKey kind, ParserLanguage language )
{
if( kind == KeywordSetKey.EMPTY )
@ -53,28 +52,32 @@ public class KeywordSets {
if( kind == KeywordSetKey.MACRO )
return MACRO_ONLY;
if( kind == KeywordSetKey.PP_DIRECTIVE )
return PP_DIRECTIVES;
return (Set) PP_DIRECTIVES_TABLE.get( language );
if( kind == KeywordSetKey.EXPRESSION )
return (Set) EXPRESSION_TABLE.get( language );
if( kind == KeywordSetKey.ALL )
return (Set) ALL_TABLE.get( language );
if( kind == KeywordSetKey.KEYWORDS )
return (Set) KEYWORDS_TABLE.get( language );
if( kind == KeywordSetKey.TYPES )
return (Set) TYPES_TABLE.get( language );
//TODO finish this
return null;
}
private static final Set EMPTY_TABLE = new HashSet();
private static final Set EMPTY_TABLE = new HashSet(0);
private static final Set NAMESPACE_ONLY_SET;
static
{
NAMESPACE_ONLY_SET = new HashSet();
NAMESPACE_ONLY_SET = new HashSet(1);
NAMESPACE_ONLY_SET.add(Keywords.NAMESPACE );
}
private static final Set MACRO_ONLY;
static
{
MACRO_ONLY = new HashSet();
MACRO_ONLY = new HashSet(1);
MACRO_ONLY.add("defined()" ); //$NON-NLS-1$
}
@ -305,30 +308,51 @@ public class KeywordSets {
FUNCTION_MODIFIER_TABLE.put( ParserLanguage.CPP, FUNCTION_MODIFIER_CPP );
FUNCTION_MODIFIER_TABLE.put( ParserLanguage.C, FUNCTION_MODIFIER_C );
}
private static final Set PP_DIRECTIVES;
private static final Set PP_DIRECTIVES_C;
static
{
PP_DIRECTIVES = new TreeSet();
PP_DIRECTIVES.add(Directives.POUND_BLANK);
PP_DIRECTIVES.add(Directives.POUND_DEFINE);
PP_DIRECTIVES.add(Directives.POUND_UNDEF);
PP_DIRECTIVES.add(Directives.POUND_IF);
PP_DIRECTIVES.add(Directives.POUND_IFDEF);
PP_DIRECTIVES.add(Directives.POUND_IFNDEF);
PP_DIRECTIVES.add(Directives.POUND_ELSE);
PP_DIRECTIVES.add(Directives.POUND_ENDIF);
PP_DIRECTIVES.add(Directives.POUND_INCLUDE);
PP_DIRECTIVES.add(Directives.POUND_LINE);
PP_DIRECTIVES.add(Directives.POUND_ERROR);
PP_DIRECTIVES.add(Directives.POUND_PRAGMA);
PP_DIRECTIVES.add(Directives.POUND_ELIF);
PP_DIRECTIVES_C = new TreeSet();
PP_DIRECTIVES_C.add(Directives.POUND_BLANK);
PP_DIRECTIVES_C.add(Directives.POUND_DEFINE);
PP_DIRECTIVES_C.add(Directives.POUND_UNDEF);
PP_DIRECTIVES_C.add(Directives.POUND_IF);
PP_DIRECTIVES_C.add(Directives.POUND_IFDEF);
PP_DIRECTIVES_C.add(Directives.POUND_IFNDEF);
PP_DIRECTIVES_C.add(Directives.POUND_ELSE);
PP_DIRECTIVES_C.add(Directives.POUND_ENDIF);
PP_DIRECTIVES_C.add(Directives.POUND_INCLUDE);
PP_DIRECTIVES_C.add(Directives.POUND_LINE);
PP_DIRECTIVES_C.add(Directives.POUND_ERROR);
PP_DIRECTIVES_C.add(Directives.POUND_PRAGMA);
PP_DIRECTIVES_C.add(Directives.POUND_ELIF);
PP_DIRECTIVES_C.add(Directives._PRAGMA );
}
private static final Set PP_DIRECTIVES_CPP;
static
{
PP_DIRECTIVES_CPP = new TreeSet();
PP_DIRECTIVES_CPP.add(Directives.POUND_BLANK);
PP_DIRECTIVES_CPP.add(Directives.POUND_DEFINE);
PP_DIRECTIVES_CPP.add(Directives.POUND_UNDEF);
PP_DIRECTIVES_CPP.add(Directives.POUND_IF);
PP_DIRECTIVES_CPP.add(Directives.POUND_IFDEF);
PP_DIRECTIVES_CPP.add(Directives.POUND_IFNDEF);
PP_DIRECTIVES_CPP.add(Directives.POUND_ELSE);
PP_DIRECTIVES_CPP.add(Directives.POUND_ENDIF);
PP_DIRECTIVES_CPP.add(Directives.POUND_INCLUDE);
PP_DIRECTIVES_CPP.add(Directives.POUND_LINE);
PP_DIRECTIVES_CPP.add(Directives.POUND_ERROR);
PP_DIRECTIVES_CPP.add(Directives.POUND_PRAGMA);
PP_DIRECTIVES_CPP.add(Directives.POUND_ELIF);
}
private static final Set ALL_C;
static
{
ALL_C = new TreeSet(PP_DIRECTIVES);
ALL_C = new TreeSet(PP_DIRECTIVES_CPP);
ALL_C.add( Keywords.AUTO);
ALL_C.add( Keywords.BREAK);
ALL_C.add( Keywords.CASE);
@ -372,7 +396,7 @@ public class KeywordSets {
private static final Set ALL_CPP;
static
{
ALL_CPP = new TreeSet(PP_DIRECTIVES);
ALL_CPP = new TreeSet(PP_DIRECTIVES_CPP);
ALL_CPP.add( Keywords.AND );
ALL_CPP.add( Keywords.AND_EQ);
ALL_CPP.add( Keywords.ASM);
@ -456,5 +480,167 @@ public class KeywordSets {
ALL_TABLE.put( ParserLanguage.C, ALL_C );
ALL_TABLE.put( ParserLanguage.CPP, ALL_CPP );
}
private static final Set KEYWORDS_CPP;
static
{
KEYWORDS_CPP = new TreeSet();
KEYWORDS_CPP.add( Keywords.AND );
KEYWORDS_CPP.add( Keywords.AND_EQ );
KEYWORDS_CPP.add( Keywords.ASM );
KEYWORDS_CPP.add( Keywords.AUTO );
KEYWORDS_CPP.add( Keywords.BITAND );
KEYWORDS_CPP.add( Keywords.BITOR );
KEYWORDS_CPP.add( Keywords.BREAK );
KEYWORDS_CPP.add( Keywords.CASE );
KEYWORDS_CPP.add( Keywords.CATCH );
KEYWORDS_CPP.add( Keywords.CLASS );
KEYWORDS_CPP.add( Keywords.COMPL );
KEYWORDS_CPP.add( Keywords.CONST );
KEYWORDS_CPP.add( Keywords.CONST_CAST );
KEYWORDS_CPP.add( Keywords.CONTINUE );
KEYWORDS_CPP.add( Keywords.DEFAULT );
KEYWORDS_CPP.add( Keywords.DELETE );
KEYWORDS_CPP.add( Keywords.DO );
KEYWORDS_CPP.add( Keywords.DYNAMIC_CAST );
KEYWORDS_CPP.add( Keywords.ELSE );
KEYWORDS_CPP.add( Keywords.ENUM );
KEYWORDS_CPP.add( Keywords.EXPLICIT );
KEYWORDS_CPP.add( Keywords.EXPORT );
KEYWORDS_CPP.add( Keywords.EXTERN );
KEYWORDS_CPP.add( Keywords.FALSE );
KEYWORDS_CPP.add( Keywords.FOR );
KEYWORDS_CPP.add( Keywords.FRIEND );
KEYWORDS_CPP.add( Keywords.GOTO );
KEYWORDS_CPP.add( Keywords.IF );
KEYWORDS_CPP.add( Keywords.INLINE );
KEYWORDS_CPP.add( Keywords.MUTABLE );
KEYWORDS_CPP.add( Keywords.NAMESPACE );
KEYWORDS_CPP.add( Keywords.NEW );
KEYWORDS_CPP.add( Keywords.NOT );
KEYWORDS_CPP.add( Keywords.NOT_EQ );
KEYWORDS_CPP.add( Keywords.OPERATOR );
KEYWORDS_CPP.add( Keywords.OR );
KEYWORDS_CPP.add( Keywords.OR_EQ );
KEYWORDS_CPP.add( Keywords.PRIVATE );
KEYWORDS_CPP.add( Keywords.PROTECTED );
KEYWORDS_CPP.add( Keywords.PUBLIC );
KEYWORDS_CPP.add( Keywords.REGISTER );
KEYWORDS_CPP.add( Keywords.REINTERPRET_CAST );
KEYWORDS_CPP.add( Keywords.RESTRICT );
KEYWORDS_CPP.add( Keywords.RETURN );
KEYWORDS_CPP.add( Keywords.SIZEOF );
KEYWORDS_CPP.add( Keywords.STATIC );
KEYWORDS_CPP.add( Keywords.STATIC_CAST );
KEYWORDS_CPP.add( Keywords.STRUCT );
KEYWORDS_CPP.add( Keywords.SWITCH );
KEYWORDS_CPP.add( Keywords.TEMPLATE );
KEYWORDS_CPP.add( Keywords.THIS );
KEYWORDS_CPP.add( Keywords.THROW );
KEYWORDS_CPP.add( Keywords.TRUE );
KEYWORDS_CPP.add( Keywords.TRY );
KEYWORDS_CPP.add( Keywords.TYPEDEF );
KEYWORDS_CPP.add( Keywords.TYPEID );
KEYWORDS_CPP.add( Keywords.TYPENAME );
KEYWORDS_CPP.add( Keywords.UNION );
KEYWORDS_CPP.add( Keywords.USING );
KEYWORDS_CPP.add( Keywords.VIRTUAL );
KEYWORDS_CPP.add( Keywords.VOLATILE );
KEYWORDS_CPP.add( Keywords.WHILE );
KEYWORDS_CPP.add( Keywords.XOR );
KEYWORDS_CPP.add( Keywords.XOR_EQ );
}
private static Set KEYWORDS_C;
static
{
KEYWORDS_C = new TreeSet();
KEYWORDS_C.add( Keywords.ASM );
KEYWORDS_C.add( Keywords.AUTO );
KEYWORDS_C.add( Keywords.BREAK );
KEYWORDS_C.add( Keywords.CASE );
KEYWORDS_C.add( Keywords.CONST );
KEYWORDS_C.add( Keywords.CONTINUE );
KEYWORDS_C.add( Keywords.DEFAULT );
KEYWORDS_C.add( Keywords.DO );
KEYWORDS_C.add( Keywords.ELSE );
KEYWORDS_C.add( Keywords.ENUM );
KEYWORDS_C.add( Keywords.EXTERN );
KEYWORDS_C.add( Keywords.FOR );
KEYWORDS_C.add( Keywords.GOTO );
KEYWORDS_C.add( Keywords.IF );
KEYWORDS_C.add( Keywords.INLINE );
KEYWORDS_C.add( Keywords.REGISTER );
KEYWORDS_C.add( Keywords.RETURN );
KEYWORDS_C.add( Keywords.RESTRICT );
KEYWORDS_C.add( Keywords.SIZEOF );
KEYWORDS_C.add( Keywords.STATIC );
KEYWORDS_C.add( Keywords.STRUCT );
KEYWORDS_C.add( Keywords.SWITCH );
KEYWORDS_C.add( Keywords.TYPEDEF );
KEYWORDS_C.add( Keywords.UNION );
KEYWORDS_C.add( Keywords.VOLATILE );
KEYWORDS_C.add( Keywords.WHILE );
}
private static final Hashtable KEYWORDS_TABLE;
static
{
KEYWORDS_TABLE = new Hashtable(2);
KEYWORDS_TABLE.put( ParserLanguage.C, KEYWORDS_C );
KEYWORDS_TABLE.put( ParserLanguage.CPP, KEYWORDS_CPP );
}
private static final Set TYPES_C;
static
{
TYPES_C = new TreeSet();
TYPES_C.add( Keywords.CHAR );
TYPES_C.add( Keywords.DOUBLE );
TYPES_C.add( Keywords.FLOAT );
TYPES_C.add( Keywords.INT );
TYPES_C.add( Keywords.LONG );
TYPES_C.add( Keywords.SHORT );
TYPES_C.add( Keywords.SIGNED );
TYPES_C.add( Keywords.UNSIGNED );
TYPES_C.add( Keywords.VOID );
TYPES_C.add( Keywords._BOOL );
TYPES_C.add( Keywords._COMPLEX );
TYPES_C.add( Keywords._IMAGINARY );
}
private static final Set TYPES_CPP;
static
{
TYPES_CPP = new TreeSet();
TYPES_CPP.add( Keywords.BOOL );
TYPES_CPP.add( Keywords.CHAR );
TYPES_CPP.add( Keywords.DOUBLE );
TYPES_CPP.add( Keywords.FLOAT );
TYPES_CPP.add( Keywords.INT );
TYPES_CPP.add( Keywords.LONG );
TYPES_CPP.add( Keywords.SHORT );
TYPES_CPP.add( Keywords.SIGNED );
TYPES_CPP.add( Keywords.UNSIGNED );
TYPES_CPP.add( Keywords.VOID );
TYPES_CPP.add( Keywords.WCHAR_T );
}
private static Hashtable TYPES_TABLE;
static
{
TYPES_TABLE = new Hashtable( 2 );
TYPES_TABLE.put( ParserLanguage.C, TYPES_C );
TYPES_TABLE.put( ParserLanguage.CPP, TYPES_CPP );
}
private static Hashtable PP_DIRECTIVES_TABLE;
static
{
PP_DIRECTIVES_TABLE = new Hashtable( 2 );
PP_DIRECTIVES_TABLE.put( ParserLanguage.C, PP_DIRECTIVES_C );
PP_DIRECTIVES_TABLE.put( ParserLanguage.CPP, PP_DIRECTIVES_CPP );
}
}

View file

@ -7,8 +7,12 @@ package org.eclipse.cdt.internal.ui.text;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IRule;
@ -23,37 +27,8 @@ import org.eclipse.jface.util.PropertyChangeEvent;
*/
public final class CCodeScanner extends AbstractCScanner {
private static String[] fgKeywords= {
"asm", "auto", //$NON-NLS-1$ //$NON-NLS-2$
"break", //$NON-NLS-1$
"case", //$NON-NLS-1$
"const", "continue", //$NON-NLS-1$ //$NON-NLS-2$
"default", "do", //$NON-NLS-1$ //$NON-NLS-2$
"else", "enum", "extern", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"for", //$NON-NLS-1$
"goto", //$NON-NLS-1$
"if", "inline", //$NON-NLS-1$ //$NON-NLS-2$
"register", "return", "restrict", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"sizeof", "static", "struct", "switch", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"typedef", //$NON-NLS-1$
"union", //$NON-NLS-1$
"volatile", //$NON-NLS-1$
"while", "_Pragma" //$NON-NLS-1$ //$NON-NLS-2$
};
private static String[] fgTypes= { "char", "double", "float", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"int", "long", "short", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"signed", "unsigned", "void", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"_Bool", "_Complex", "_Imaginary"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static String[] fgConstants= { "NULL", "__DATE__", "__LINE__", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"__TIME__", "__FILE__", "__STDC__"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static String[] fgPreprocessor= { "#define", "#undef", "#include", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#error", "#warning", "#pragma", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#ifdef", "#ifndef", "#if", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#else", "#elif", "#endif", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#line"}; //$NON-NLS-1$
private static String[] fgTokenProperties= {
@ -101,21 +76,25 @@ public final class CCodeScanner extends AbstractCScanner {
WordRule wordRule= new WordRule(new CWordDetector(), token);
token= getToken(ICColorConstants.C_KEYWORD);
for (int i=0; i<fgKeywords.length; i++)
wordRule.addWord(fgKeywords[i], token);
Iterator i = ParserFactory.getKeywordSet( KeywordSetKey.KEYWORDS, ParserLanguage.C ).iterator();
while( i.hasNext() )
wordRule.addWord((String) i.next(), token);
token= getToken(ICColorConstants.C_TYPE);
for (int i=0; i<fgTypes.length; i++)
wordRule.addWord(fgTypes[i], token);
for (int i=0; i<fgConstants.length; i++)
wordRule.addWord(fgConstants[i], token);
i = ParserFactory.getKeywordSet( KeywordSetKey.TYPES, ParserLanguage.C ).iterator();
while( i.hasNext() )
wordRule.addWord((String) i.next(), token);
for (int j=0; j<fgConstants.length; j++)
wordRule.addWord(fgConstants[j], token);
rules.add(wordRule);
token = getToken(ICColorConstants.C_TYPE);
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), token);
for (int i=0; i<fgPreprocessor.length; i++) {
preprocessorRule.addWord(fgPreprocessor[i], token);
}
i = ParserFactory.getKeywordSet( KeywordSetKey.PP_DIRECTIVE, ParserLanguage.C ).iterator();
while( i.hasNext() )
preprocessorRule.addWord((String) i.next(), token);
rules.add(preprocessorRule);
setDefaultReturnToken(getToken(ICColorConstants.C_DEFAULT));

View file

@ -5,10 +5,14 @@ package org.eclipse.cdt.internal.ui.text;
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.KeywordSetKey;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.SingleLineRule;
@ -22,47 +26,10 @@ import org.eclipse.jface.util.PropertyChangeEvent;
*/
public final class CppCodeScanner extends AbstractCScanner {
private static String[] fgKeywords= {
"and", "and_eq", "asm", "auto", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"bitand", "bitor", "break", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"case", "catch", "class", "compl", "const", "const_cast", "continue", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
"default", "delete", "do", "dynamic_cast", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"else", "enum", "explicit", "export", "extern", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"false", "final", "finally", "for", "friend", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"goto", //$NON-NLS-1$
"if", "inline", //$NON-NLS-1$ //$NON-NLS-2$
"mutable", //$NON-NLS-1$
"namespace", "new", "not", "not_eq", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"operator", "or", "or_eq", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"private", "protected", "public", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"redeclared", "register", "reinterpret_cast", "return", "restrict", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"sizeof", "static", "static_cast", "struct", "switch", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"template", "this", "throw", "true", "try", "typedef", "typeid", "typename", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"union", "using", //$NON-NLS-1$ //$NON-NLS-2$
"virtual", "volatile", //$NON-NLS-1$ //$NON-NLS-2$
"while", //$NON-NLS-1$
"xor", "xor_eq" //$NON-NLS-1$ //$NON-NLS-2$
};
private static String[] fgTypes= { "bool", "char", "double", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"float", "int", "long", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"short", "signed", "unsigned", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"void", "wchar_t", "_Bool", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"_Complex", "_Imaginary"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static String[] fgConstants= { "false", "NULL", "true", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static String[] fgConstants= { "NULL", //$NON-NLS-1$
"__DATE__", "__LINE__", "__TIME__", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"__FILE__", "__STDC__"}; //$NON-NLS-1$ //$NON-NLS-2$
private static String[] fgPreprocessor= { "#define", "#undef", "#include", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#error", "#warning", "#pragma", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#ifdef", "#ifndef", "#line", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#undef", "#if", "#else", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"#elif", "#endif"}; //$NON-NLS-1$ //$NON-NLS-2$
private static String[] fgTokenProperties= {
ICColorConstants.C_KEYWORD,
ICColorConstants.C_TYPE,
@ -109,21 +76,24 @@ public final class CppCodeScanner extends AbstractCScanner {
WordRule wordRule= new WordRule(new CWordDetector(), token);
token= getToken(ICColorConstants.C_KEYWORD);
for (int i=0; i<fgKeywords.length; i++)
wordRule.addWord(fgKeywords[i], token);
Iterator iter = ParserFactory.getKeywordSet( KeywordSetKey.KEYWORDS, ParserLanguage.CPP ).iterator();
while( iter.hasNext() )
wordRule.addWord((String)iter.next(), token);
token= getToken(ICColorConstants.C_TYPE);
for (int i=0; i<fgTypes.length; i++)
wordRule.addWord(fgTypes[i], token);
iter = ParserFactory.getKeywordSet( KeywordSetKey.TYPES, ParserLanguage.CPP ).iterator();
while( iter.hasNext() )
wordRule.addWord((String) iter.next(), token);
for (int i=0; i<fgConstants.length; i++)
wordRule.addWord(fgConstants[i], token);
rules.add(wordRule);
token = getToken(ICColorConstants.C_TYPE);
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), token);
for (int i=0; i<fgPreprocessor.length; i++) {
preprocessorRule.addWord(fgPreprocessor[i], token);
}
iter = ParserFactory.getKeywordSet( KeywordSetKey.PP_DIRECTIVE, ParserLanguage.CPP ).iterator();
while( iter.hasNext() )
preprocessorRule.addWord((String) iter.next(), token);
rules.add(preprocessorRule);
setDefaultReturnToken(getToken(ICColorConstants.C_DEFAULT));
@ -154,22 +124,4 @@ public final class CppCodeScanner extends AbstractCScanner {
}
}
public static String[] getKeywords(){
int keysLength = fgKeywords.length;
int typesLength = fgTypes.length;
int preprocessorLength = fgPreprocessor.length;
int constsLength = fgConstants.length;
String[] keywords = new String[keysLength + typesLength + preprocessorLength + constsLength];
System.arraycopy(fgKeywords,0,keywords,0,keysLength);
System.arraycopy(fgTypes,0,keywords,keysLength,typesLength);
System.arraycopy(fgPreprocessor,0,keywords,(keysLength + typesLength),preprocessorLength);
System.arraycopy(fgConstants,0,keywords,(keysLength + typesLength + preprocessorLength),constsLength);
return keywords;
}
}