Own language problem

Topics: User Forum
Feb 13, 2012 at 8:15 AM

First, sorry for my bad english ;).


I read a lot about defining own language syntax highlighting, but NOTHING works!

First i tried to use tips from http://scintillanet.codeplex.com/wikipage?title=HowToCustomConfig . Font has changed, also text in ' ' and after # have red background and black foreground. And that's all. var, string, numeric expressions - nothing. What am i doing wrong?

Second chance - i copied the cs.xml from configuration/builtin to my configuration file and changed the name of language to "zyx". When i set Language property to CS - all works fine. When "zyx" - nothing works :(. I have no idea, what's wrong :/

Feb 13, 2012 at 10:55 PM

Firstly, the name of the language must be the same as the name of the file. (that's my guess as to the issue)
Also, nothing is going to colorize unless you have it set to use a valid parser from scintilla (it's one of the properties you can set in the xml file).

Feb 14, 2012 at 5:04 AM

XML file must be the same name as language - but why it changed the font? He found configuration properly. "valid parser from sctintilla [...] you can set in the xml file" - i copied all from builtin configuration of c#. Now i changed to CodeBox control and it works fine for me (i don't need huge tool for that), but i want to know, what i did wrong :)

Feb 14, 2012 at 5:00 PM

I can understand your frustration. This topic has been a sore spot for many developers over the years and it doesn't help that our configuration implementation is like spaghetti and our documentation is thin.

Assuming you wanted to copy the standard C# configuration and make some changes, here is what you need to do.

Step 1:
The standard C# configuration file is found in the \ScintillaNET\Configuration\Builtin\cs.xml file in source control. Copy that file to your application bin folder and rename it. For this example, we'll rename it to zyx.xml.

Step 2:
In the zyx.xml file, change the Name attribute of the Language node to "zyx". Your XML file should now look like this:

<?xml version="1.0" encoding="utf-8"?>
    <Language Name="zyx">
        <!-- omitted -->

NOTE: I've omitted nearly all of the document for brevity.

The value of the Name attribute corresponds to the ConfigurationManager.Language property (see below) and they have to match.

Step 3:
In your code, you can now enable your custom configuration by doing the following:

scintilla.Lexing.LexerLanguageMap["zyx"] = "cpp";
scintilla.ConfigurationManager.CustomLocation = Environment.CurrentDirectory;
scintilla.ConfigurationManager.Language = "zyx";

The first line defines a language-to-lexer mapping. Scintilla has no built in lexer named "zyx" but we know that it is similar to C# so we can use the C++ lexer. If we don't tell Scintilla how to map our configuration to a lexer we won't get syntax highlighting. What confuses so many people is that ScintillaNET has a built in mapping by default from "cs" (C#) to "cpp" (C++). That explains why languages called "cs" always seem to work but others do not.

The second line informs ScintillaNET where to look for custom configuration files. This is not normally checked by default and since we put our zyx.xml file in our application bin we need to tell ScintillaNET to look for it there.

The last line puts it all together and loads our configuration. The Language property value is "zyx" because that's what we specified in the Name attribute of the Language node in our XML file above. If those don't match ScintillaNET will simply ignore your request.


Hopefully that helps.



Feb 16, 2012 at 8:22 AM

Thanks for that step-by-step explanation. Soon i will try this, because your control looks more powerful and less buggy than codebox :)

Feb 28, 2012 at 10:53 AM


I tried step by step as you told and... it works! Unlike CodeBox extremely fast. Great job!

Public your post as a part of documentation.

Thx a lot :)