Open f1nalspace opened 5 years ago
Seems that the C++ lexer has the property lexer.cpp.track.preprocessor
enabled by default. This is what's causing the "fail". You have two options to solve this.
editor.SetProperty("lexer.cpp.track.preprocessor", "0");
// Inactive whitespace
editor.Styles[64].ForeColor = ColorTranslator.FromHtml("#C0C0C0");
// Inactive block comment
editor.Styles[65].ForeColor = ColorTranslator.FromHtml("#90B090");
// Inactive line comment
editor.Styles[66].ForeColor = ColorTranslator.FromHtml("#90B090");
// Inactive Doc comment: block comments beginning with /** or /*!
editor.Styles[67].ForeColor = ColorTranslator.FromHtml("#D0D0D0");
// Inactive number
editor.Styles[68].ForeColor = ColorTranslator.FromHtml("#90B0B0");
// Inactive keyword
editor.Styles[69].ForeColor = ColorTranslator.FromHtml("#9090B0");
// Inactive double quoted string
editor.Styles[70].ForeColor = ColorTranslator.FromHtml("#B090B0");
// Inactive single quoted string
editor.Styles[71].ForeColor = ColorTranslator.FromHtml("#B090B0");
// Inactive UUIDs
editor.Styles[72].ForeColor = ColorTranslator.FromHtml("#C0C0C0");
// Inactive preprocessor
editor.Styles[73].ForeColor = ColorTranslator.FromHtml("#B0B090");
// Inactive operators
editor.Styles[74].ForeColor = ColorTranslator.FromHtml("#B0B0B0");
// Inactive indetifiers
editor.Styles[75].ForeColor = ColorTranslator.FromHtml("#B0B0B0");
// Inactive end of line where string is not closed
editor.Styles[76].ForeColor = ColorTranslator.FromHtml("#000000");
// Inactive verbatim strings for C#
editor.Styles[77].ForeColor = ColorTranslator.FromHtml("#90B090");
// Inactive regular expressions for JavaScript
editor.Styles[78].ForeColor = ColorTranslator.FromHtml("#7FAF7F");
// Inactive doc line comment: line comments beginning with /// or //!.
editor.Styles[79].ForeColor = ColorTranslator.FromHtml("#C0C0C0");
// Inactive keywords2
editor.Styles[80].ForeColor = ColorTranslator.FromHtml("#C0C0C0");
// Inactive comment keyword
editor.Styles[81].ForeColor = ColorTranslator.FromHtml("#C0C0C0");
// Inactive comment keyword error
editor.Styles[82].ForeColor = ColorTranslator.FromHtml("#C0C0C0");
// Inactive raw strings for C++0x
editor.Styles[84].ForeColor = ColorTranslator.FromHtml("#B090B0");
// Inactive triple-quoted strings for Vala
editor.Styles[85].ForeColor = ColorTranslator.FromHtml("#90B090");
// Inactive hash-quoted strings for Pike
editor.Styles[86].ForeColor = ColorTranslator.FromHtml("#90B090");
// Inactive preprocessor stream comment
editor.Styles[87].ForeColor = ColorTranslator.FromHtml("#A0C090");
// Inactive preprocessor stream doc comment
editor.Styles[88].ForeColor = ColorTranslator.FromHtml("#C0C0C0");
// Inactive user defined literals
editor.Styles[89].ForeColor = ColorTranslator.FromHtml("#D7A090");
// Inactive task marker
editor.Styles[90].ForeColor = ColorTranslator.FromHtml("#C3A1CF");
When the property lexer.cpp.track.preprocessor
is enabled, it basically interprets #if/#else/#endif to grey out code that is not active, like how Visual Studio does it. So, if you don't colourise these inactive styles (see option 2), everything inside the preprocessor, depending on the conditional, will appear unstyled.
Every word is appearing in blue color because your Style.Cpp.Identifier
and Style.Cpp.Word
are sharing the same color. Either change the color or remove the identifier styler.
Also, based on your code, you're not setting the lexer keywords. This will by default style them as Style.Cpp.Identifier
. You can set them with:
scintilla.SetKeywords(0, "abstract as base break case catch checked continue default delegate do else event explicit extern false finally fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof unchecked unsafe using virtual while");
scintilla.SetKeywords(1, "bool byte char class const decimal double enum float int long sbyte short static string struct uint ulong ushort void");
I'm unable to replicate a line comment doc failure. If you have an example, throw it in and I'll take a look.
Awesome, Thanks for that explanation! Now everything works as expected, expect for one thing: The comment doc blocks are not colored the way like i want it to be, so i want to add additional custom highlighting for that. How do i do that?
I know i can use StyleNeeded to colorize a range of text, but then i would lose the Cpp lexer :-( How can i call the Cpp lexer for a specific text range?
What i want is this:
I already have all the code implemented to parse and colorize doxygen comment blocks, but i have no idea how to use a existing lexer. So what i basically want is to make highlighting for multiple languages.
@f1nalspace Its not possible to use multiple lexers at the same time.. However you can use a lexer and then colorize whatever else using the UpdateStyle
event.. I'm not sure why you're saying you'd lose the lexer cause you won't.
First you set the styles on form load:
private enum NewStyles
{
Hotspot = 100,
Functions,
Publics,
Stocks,
Natives,
Defines,
Macros,
Enums,
PublicVars,
Tags
}
Editor.Styles[NewStyles.Functions].ForeColor = Color.Red;
Then in the event
private void Editor_UpdateStyle(object sender, UpdateUIEventArgs e)
{
var startPos = Editor.Lines[Editor.FirstVisibleLine].Position;
var endPos = Editor.Lines[Editor.FirstVisibleLine + Editor.LinesOnScreen].EndPosition;
int startStyle; int length; int style;
//TODO: some code to fill this vars.. gonna be a bit complex for blocks of code and you might want to go further then visible code..
Editor.StartStyling(startStyle);
Editor.SetStyling(length, style);
}
Thanks for the info, but i have now fully implemented everything myself: https://github.com/f1nalspace/doxygeneditor/tree/develop
I tested the scintilla .net cpp lexer with a fairly complex C-source and the highlighter fails in a lot of cases - even the most simplest ones:
The source i tested it with are: https://raw.githubusercontent.com/f1nalspace/final_game_tech/master/final_platform_layer.h
My code for setting up the editor is fairly simple:
I am not sure if the error is inside the wrapper or inside scintilla itself. My guess is, the lexer in scintilla itself is broken and i should roll out my own.