Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can I use Xtext for a DSL containing javascript?(Can I use Xtext for a DSL containing javascript?)
icon7.gif  Can I use Xtext for a DSL containing javascript? [message #1046173] Sun, 21 April 2013 13:44 Go to next message
sean davis is currently offline sean davisFriend
Messages: 1
Registered: April 2013
Junior Member
I am looking at using Xtext to create an eclipse plugin to define a custom language. This language is xml-like for the most part, however javascript can also be using within script tags- see below for example...

<TEMPLATE>
<BUTTON label=hello>btn1</BUTTON>
<SCRIPT>
function helloWorld(){
alert('Hello');
}
</SCRIPT>
</TEMPLATE>


I have no issue with the <> tags, but is it possible to use Rhino/an external parser etc. for within the script tags. If so, what is the best approach? I would like any errors in the javascript to be highlighting in the same way as the rest of the file.

I haven't got any code snippets as at the moment I am just doing a proof of concept. Hope my question is clear, if not let me know. Thanks in advance.
Re: Can I use Xtext for a DSL containing javascript? [message #1046897 is a reply to message #1046173] Mon, 22 April 2013 14:09 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
On 2013-22-04 14:58, sean davis wrote:
> I am looking at using Xtext to create an eclipse plugin to define a
> custom language. This language is xml-like for the most part, however
> javascript can also be using within script tags- see below for example...
>
> <TEMPLATE>
> <BUTTON label=hello>btn1</BUTTON>
> <SCRIPT>
> function helloWorld(){
> alert('Hello');
> }
> </SCRIPT>
> </TEMPLATE>
>
>
> I have no issue with the <> tags, but is it possible to use Rhino/an
> external parser etc. for within the script tags. If so, what is the best
> approach? I would like any errors in the javascript to be highlighting
> in the same way as the rest of the file.
>
Writing an (accurate) JavaScript parser/validator in any language is a
nightmare basically because JavaScript is filled with surprises. I went
quite far along the path of basing a language on JavaScript and tried to
implement this with Xtext, and my advice is - don't do it.

OTOH, what you can do is to lex/parse the JavaScript as opaque/verbatim
pieces of text in the Xtext model, and run an external parser/lexer
(Rhino) to generate warnings/errors. You then issue these from within
your Xtext environment - override the Linker and implement the
additional behavior in the callback you get when the rest of the linking
is done.

Alternatively, do this in the validator (if you validate the javascript
snippet by snippet).

I do something similar with Ruby logic; using an external Ruby Parser in
cloudsmith / geppetto @ github.

Hope that helps
Regards
- henrik
Previous Topic:Build path specifies execution environment J2SE-1.5.
Next Topic:Xtext Grammar - usage of 'returns'
Goto Forum:
  


Current Time: Wed Nov 26 19:14:23 GMT 2014

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

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