Syntax highlighting modification

Topics: User Forum
Dec 3, 2010 at 7:26 AM
Edited Dec 3, 2010 at 12:14 PM

Hi - I came across scintilla as a possible alternative to my current RTB-based solution (which has absolutely awful performance). scintilla performance looks good and I want to use it but I need to be able to change the syntax highlighting rules in the following way. I will be using scintilla to display/edit XML files and I want to use standard XML syntax highlighting (which I have got working) but I ALSO want to add my own special highlighting for any text that is surrounded by { }. This type of text has a special meaning in the XML that I am working with and I need it to be displayed differently. Is there an easy way to modify the configuration files to achieve this?

Thanks for any help you can provide

 EDIT: To elaborate a little and follow up with some other things I've tried...

What I am trying to achieve is this:

If I have some XML like this...

<block>

    <variable>T00001</variable>

   <variable>{FAULT}</variable>

</block>

I want to have regular XML syntax highlighting but I also want the '{FAULT}' text to be highlighted (in a different style, e.g.. with a yellow back color).

I don't want to get into writing a lexer or anything like that but I feel like it should be possible to make some minor tweaks to an existing configuration.

Ideally I would want to highlight anything that is enclosed in { } in this way but if necessary it would be possible to predicyt exactly which pieces of text could appear enclosed in { } and therefore I wonder if one solution is to add these as extra keywords. I have been experimenting with this but I cannot seem to get it to work. I found this article (http://scintillanet.codeplex.com/Thread/View.aspx?ThreadId=211606) which seemed to give some promising pointers nothing I've tried seems to work.

I have set the ConfigurationManager.Language property to 'xml' and then when I tried modifying the Lexing.Keywords collection directly (as below) it seemed to have no effect.

            txtCodeTemplate.Lexing.Keywords[7] = keywords.ToString(1, keywords.Length - 1);
            txtCodeTemplate.Styles[7].BackColor = Color.Yellow;

When I tried using the ConfigurationManager.Configure() method (as below) I got a 'Object reference not set' exception coming out of the Configure() method.

            Configuration config = new Configuration("xml");
            config.Lexing_Keywords.Add(new KeyWordConfig(7, keywords.ToString(1, keywords.Length - 1), false));
            txtCodeTemplate.ConfigurationManager.Configure(config);

 Any help would be very much appreciated.

 

Dec 6, 2010 at 9:42 PM

I use different Lexers, however I think Style[5] is KeyWord.

txtCodeTemplate.Styles[5].BackColor = Color.Yellow; // KeyWords
txtCodeTemplate.Styles[6].BackColor = Color.Yellow; // 'Single Quotes Words'
txtCodeTemplate.Styles[7].BackColor = Color.Yellow; // "Double Quoted Words"