I'm using RSyntaxTextArea
and I found a guide on syntax highlighting here. However, I have the simple requirement that I only need to modify the list of highlighted keywords (and or functions) from an existing language syntax highlighting style (e.g. SYNTAX_STYLE_CPLUSPLUS
).
@Override
public TokenMap getWordsToHighlight() {
TokenMap tokenMap = new TokenMap();
tokenMap.put("case", Token.RESERVED_WORD);
tokenMap.put("for", Token.RESERVED_WORD);
tokenMap.put("if", Token.RESERVED_WORD);
tokenMap.put("foo", Token.RESERVED_WORD); // Added
tokenMap.put("while", Token.RESERVED_WORD);
tokenMap.put("printf", Token.FUNCTION);
tokenMap.put("scanf", Token.FUNCTION);
tokenMap.put("fopen", Token.FUNCTION);
return tokenMap;
}
I do not want to implement a new language parsing via getTokenList()
(like described in the guide) just to do this. The implementation of getWordsToHighlight()
also forces you to implement getTokenList()
. Isn't there a simpler way? Preferably without hacky solutions like reflection though.
Nevermind, might as well just use the given implementation and fix the undefined variables by prepending the respective data types:
The only problem with this is that existing syntax highlighting (like block comments) gets lost.