This project is read-only.

javascript support

Topics: Developer Forum
Feb 26, 2008 at 7:03 PM

I was playing around with adding a js.xml file to support javascript, based on the instructions in this post

However, I find that in order to get it to work I also need to add the following line of code:

_lexerLanguageMap.Add("js", "cpp");

Just curious if there are any plans to extract this language map into a resource as well? Although not a big deal, it just seems that one shouldn't need to modify C# code to add support for a language.


ps. Thanks for creating this project! I can't tell you how useful it is to have an open-source code editor that integrates easily with .NET.
Feb 26, 2008 at 9:14 PM
Edited Feb 26, 2008 at 11:02 PM
This is a subject that really needs to be documented because it's confusing. This should hopefully give you a little more of a better picture, obviously you already know a lot of how this works.

"Languages" aren't really supported by the Native Scintilla control. A language is basically a named configuration with the Language name as the key. This concept was introduced with SCite, and almost all text editors based off of Scintilla uses some variation of this concept. ScintillaNET also uses this concept and because of this the hosting applications don't have to worry about creating their own configuration implementations.

One of the components of a language configuration is the lexer. Lexers are the syntax parser code that provide the automatic coloring. Not every language has its own lexer specifically for its syntax, in fact most languages use a lexer that can also be used for another language. So take for instance JavaScript. It doesn't have its own lexer, but its syntax is close enough to c++ that the cpp lexer can be used. In fact c, c++, c#, Java, and JavaScript all use the cpp lexer because their syntax is similar enough. The biggest difference between all of them is the list of keywords, which is fed into the lexer as another configuration item.

You can specify the lexer name in the config file like such:
<Lexer LexerName="cpp" />

Of course this doesn't actually modify the LexerLanguageMap buried in ScintillaNET's lexing class. The LexerLanguageMap is a lower level default mapping between languages and lexers. It's there for convenience so that you don't have to explicitly specify the lexer for the built in supported languages. JavaScript is a perfect candidate to put in here but it isn't because I haven't gotten around to adding the JavaScript built in language configuration yet. However as I said above it isn't necessary to have this entry as long as you specify the lexer in the JavaScript configuration file.

Once you finalize the JavaScript config file I would really appreciate it if you could mail it to me so that I can add it to the project as a built in language. (