Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Orion » Grammar for complex language
Grammar for complex language [message #1404624] Mon, 04 August 2014 14:22 Go to next message
Frederic Delhoume is currently offline Frederic DelhoumeFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,

I am writing a syntax.js file for a custom language.
I have some nice results, but also some difficulties for advanced constructs.
The language allows embedded Javascript code using syntax

execute OPTIONAL_NAME {
var i;
}


I would like to recognize this pattern an use already existing JS syntax.js.

I am using :
{
			// TODO: nested {} detection
			begin: "(execute)\\s+[A-z]*\\s*\\{",
			end: "\\}",
			captures: {
				1: {name: "keyword.mod"}
			},
			contentName: "js.embedded.mod",
			patterns: [
				{
					include: "orion.js"
				}
			]
		}, {
			match : "\\b(?:" + keywords.join("|") + ")\\b",
			name : "keyword.mod"
		},


It works quite well, except when there are multiple execute blocks in the input (see attachments). I would also like this to work for nested {} statements in embedded JS code.

Is there's a solution for all these issues ?

index.html and opleditor.js are to be placed at folder up to orion
syntax.js should be in orion/editor/text_mod/
opleditor.css should be in orion/editor/themes/



  • Attachment: index.html
    (Size: 2.28KB, Downloaded 37 times)
  • Attachment: opleditor.js
    (Size: 7.39KB, Downloaded 36 times)
  • Attachment: syntax.js
    (Size: 3.15KB, Downloaded 39 times)
  • Attachment: oplide.css
    (Size: 0.93KB, Downloaded 26 times)
  • Attachment: orion_editor.jpg
    (Size: 58.44KB, Downloaded 63 times)
Re: Grammar for complex language [message #1413946 is a reply to message #1404624] Fri, 29 August 2014 20:57 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Hi Frederic, sorry for the late response,

I don't understand the problem, I've changed the example to include
three 'execute's and they each style their contained javascript
(screenshot attached). I assume I'm trying the wrong thing.

If your previously-attached screenshot shows the problem then can you
specify which text in it is not styled as you need?

Thanks,
Grant


On 8/4/2014 10:22 AM, Frederic Delhoume wrote:
> Hi,
>
> I am writing a syntax.js file for a custom language.
> I have some nice results, but also some difficulties for advanced constructs.
> The language allows embedded Javascript code using syntax
>
> execute OPTIONAL_NAME {
> var i;
> }
>
>
> I would like to recognize this pattern an use already existing JS syntax.js.
>
> I am using :
> {
> // TODO: nested {} detection
> begin: "(execute)\\s+[A-z]*\\s*\\{",
> end: "\\}",
> captures: {
> 1: {name: "keyword.mod"}
> },
> contentName: "js.embedded.mod",
> patterns: [
> {
> include: "orion.js"
> }
> ]
> }, {
> match : "\\b(?:" + keywords.join("|") + ")\\b",
> name : "keyword.mod"
> },
>
> It works quite well, except when there are multiple execute blocks in the input (see attachments). I would also like this to work for nested {} statements in embedded JS code.
>
> Is there's a solution for all these issues ?
>
> index.html and opleditor.js are to be placed at folder up to orion
> syntax.js should be in orion/editor/text_mod/
> opleditor.css should be in orion/editor/themes/
>
>
>
>
Re: Grammar for complex language [message #1414780 is a reply to message #1413946] Mon, 01 September 2014 09:36 Go to previous messageGo to next message
Frederic Delhoume is currently offline Frederic DelhoumeFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,

Thanks for your answer.

The issue is that so-called execute blocks can be mixed with normal grammar statements, as in :

execute {
var i;
}

dvar int foo;

execute BLOCK {
var j;
}

execute keywords are part of the normal grammar, and should be colored in blue, along with dvar. And contents enclosed in execute block should be in other color.

So far I anderstand that the rule for detecting the first execute block matches until the end of the second block, and I would like it to stop at first matching }, so that dvar is colored in blue.

[Updated on: Mon, 01 September 2014 09:37]

Report message to a moderator

Re: Grammar for complex language [message #1415348 is a reply to message #1414780] Tue, 02 September 2014 15:23 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
Ok, I understand what you're saying. I think the partitioning of the
code blocks is actually working fine, but the problem is that the same
visual styling is being applied to the js keywords and to your
language's keywords. To test this, in your syntax.js change the two
"name" values from "keyword.mod" to "string", and you should see the
styling for your language's keywords become distinct from the js keywords.

Assuming you see this, you probably need to define a .css style for
..keyword.mod rather than for .keyword, to ensure that it is the style
that gets applied to your language's keywords rather than Orion's
definition for .keyword.

If you don't think this is the issue you're seeing or if you have
further questions then please let me know.

Grant
Re: Grammar for complex language [message #1415356 is a reply to message #1415348] Tue, 02 September 2014 15:36 Go to previous messageGo to next message
Frederic Delhoume is currently offline Frederic DelhoumeFriend
Messages: 8
Registered: July 2009
Junior Member
I think the issue is that the first execute block is correctly recognized, but it is extending beyond line 40, where is should switch back to normal coloring. Now it is extending until line 59 because matching rule finds } at this location.
Everything in between is considered as Javascript.
For example "in" at line 47 should be blue, and execute at line 54 also.
  • Attachment: Untitled.jpg
    (Size: 42.96KB, Downloaded 38 times)

[Updated on: Tue, 02 September 2014 15:40]

Report message to a moderator

Re: Grammar for complex language [message #1415814 is a reply to message #1415356] Wed, 03 September 2014 17:59 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
I'm not sure what to think here, I don't see this problem. My context
is a bit different from yours, but I would not think that this could
affect the styler's identification of block bounds. Can you use the
element inspector in the Chrome debugger to hover over one of the
incorrectly-coloured "in"s and verify whether its class is .keyword.mod
or .keyword.control.js? And which Orion and browser versions are you using?

Grant


On 9/2/2014 11:36 AM, Frederic Delhoume wrote:
> I think the issue is that the first execute block is correctly recognized, but it is extending beyond line 40, where is hould switch back to normal coloring. Now it is extending until line 59 bacause matching rule finds } at this location.
> Everything in between is considered as Javascript.
> For example "in" at line 47 should be blue, and execute at line 54 also.
>
Re: Grammar for complex language [message #1416077 is a reply to message #1415814] Thu, 04 September 2014 09:24 Go to previous message
Frederic Delhoume is currently offline Frederic DelhoumeFriend
Messages: 8
Registered: July 2009
Junior Member
Here is the inspector view in Chrome. The badly colored in keyword has the .keyword.control.js style.

I think the version I use is 6.x, is there's a way to know the version from .js sources ?
I am only using the editor JS component, not the complete framework.
  • Attachment: chrome.jpg
    (Size: 82.59KB, Downloaded 47 times)
Previous Topic:Integration of Xtext with Flux
Next Topic:How to enable syntax highlighting for javascript ?
Goto Forum:
  


Current Time: Mon Aug 03 04:52:37 GMT 2015

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

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