Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsCan I use Xtext for a DSL containing javascript?
https://www.eclipse.org/forums/index.php/mv/msg/480259/1046173/#msg_1046173
<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.]]>sean davis2013-04-21T13:44:25-00:00Re: Can I use Xtext for a DSL containing javascript?
https://www.eclipse.org/forums/index.php/mv/msg/480259/1046897/#msg_1046897
> 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]]>Henrik Lindberg2013-04-22T14:09:29-00:00