[SOLVED] Passing Regex flags for patterns in Syntax Highlighting Grammar [message #1085802] |
Tue, 13 August 2013 07:46  |
Eclipse User |
|
|
|
I am trying to write a plugin which will add syntax highlighting. I have written a grammar which declares the rules for syntax highlighting.
Here's a sample of code I have written:
provider.registerServiceProvider("orion.edit.highlighter", {}, {
type : "grammar",
contentType: ["text/xyz"],
grammar: {
patterns: [
{
name: "lang.keyword",
match: "(keyword1 | keyword2 | keyword3)"
}
The keywords are to be highlighted in a case insensitive manner. How to pass the case insensitive flag 'i' in this scenario?
[Updated on: Tue, 20 August 2013 03:56] by Moderator
|
|
|
|
|
Re: Passing Regex flags for patterns in Syntax Highlighting Grammar [message #1092384 is a reply to message #1090491] |
Thu, 22 August 2013 14:21  |
Eclipse User |
|
|
|
I wouldn't say we have anything more efficient right now. The only currently-existing alternative is to write an asynchronous highlighting provider service. This involves using an "orion.edit.model" service to receive text change events from the Orion editor, and using them to reconstruct a copy of the text buffer, which you can inspect to decide which syntax highlighting styles should be generated, and fire the appropriate styles back to the Orion editor.
This way is more complex, but also more powerful, since you can respond to changes in the file text with arbitrary logic in code, rather than being limited to a grammar format defined by metadata.
An example such implementation is in the Orion-codemirror plugin, which lives here on Github. You could even use this plugin as a starting point, and simply add support to it for your "keyword1|keyword2|.." language. Your language's highlighting rules would have to be written as a CodeMirror "mode", which is basically a small parser.
[Updated on: Thu, 22 August 2013 14:22] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02788 seconds