|
Re: Can I use Xtext for a DSL containing javascript? [message #1046897 is a reply to message #1046173] |
Mon, 22 April 2013 10:09  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05768 seconds