Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Orion » [SOLVED] Passing Regex flags for patterns in Syntax Highlighting Grammar
[SOLVED] Passing Regex flags for patterns in Syntax Highlighting Grammar [message #1085802] Tue, 13 August 2013 07:46 Go to next message
katie evans is currently offline katie evans
Messages: 28
Registered: July 2012
Location: brisbane queensland austr...
Junior Member
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]

Report message to a moderator

Re: Passing Regex flags for patterns in Syntax Highlighting Grammar [message #1090007 is a reply to message #1085802] Mon, 19 August 2013 11:24 Go to previous messageGo to next message
Mark Macdonald is currently offline Mark Macdonald
Messages: 21
Registered: July 2009
Junior Member
The grammar engine has limited support for embedded regex flags. They must appear at the start of the expression. For example, try this:

"match": "(?i)(keyword1|keyword2|keyword3)"


The engine will interpret this as (keyword1|keyword2|keyword3) with the case-insensitive flag applied to the whole expression.

It would be more natural to provide actual JavaScript RegExp objects inside a grammar, but the engine doesn't currently support those.
Re: Passing Regex flags for patterns in Syntax Highlighting Grammar [message #1090491 is a reply to message #1090007] Tue, 20 August 2013 03:59 Go to previous messageGo to next message
katie evans is currently offline katie evans
Messages: 28
Registered: July 2012
Location: brisbane queensland austr...
Junior Member
Mark Macdonald wrote on Mon, 19 August 2013 11:24
The grammar engine has limited support for embedded regex flags. They must appear at the start of the expression. For example, try this:

"match": "(?i)(keyword1|keyword2|keyword3)"


The engine will interpret this as (keyword1|keyword2|keyword3) with the case-insensitive flag applied to the whole expression.

It would be more natural to provide actual JavaScript RegExp objects inside a grammar, but the engine doesn't currently support those.


Thanks. This solves my problem. As an afterthought is there a better (efficient & extensible) way of achieving this?
Re: Passing Regex flags for patterns in Syntax Highlighting Grammar [message #1092384 is a reply to message #1090491] Thu, 22 August 2013 14:21 Go to previous message
Mark Macdonald is currently offline Mark Macdonald
Messages: 21
Registered: July 2009
Junior Member
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]

Report message to a moderator

Previous Topic:Problem with import git from bitbucket
Next Topic:Can't using Hangul.(Korean language)
Goto Forum:
  


Current Time: Thu Jul 24 11:27:12 EDT 2014

Powered by FUDForum. Page generated in 0.08006 seconds