Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Orion (Archived) » [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 11:46 Go to next message
katie evans is currently offline katie evansFriend
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 07: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 15:24 Go to previous messageGo to next message
Mark Macdonald is currently offline Mark MacdonaldFriend
Messages: 35
Registered: July 2009
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 07:59 Go to previous messageGo to next message
katie evans is currently offline katie evansFriend
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 18:21 Go to previous message
Mark Macdonald is currently offline Mark MacdonaldFriend
Messages: 35
Registered: July 2009
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 18: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: Sat Apr 20 00:22:11 GMT 2024

Powered by FUDForum. Page generated in 0.03353 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top