0

I need to provide and IDE with a syntax checker and validator for a very simple DSL.

The DSL's interpreter already exists so there is no need for another one. The DSL is suitable for xtext & xtend except that it allows one to escape to javascript, which I have heard is quite a messy language.

Is XText suitable for this scenario? I have heard that it is extremely difficult to adapt xtext to javascript and I haven't seen an open source xtext javascript project that I could easily link to or extend.

Thanks!

EDIT: The dsl I am working with is the nools rule language. It looks like this:

rule "rule report to user" {
    when{
        $ctr: Counter $ctr.count % 1000 == 0 {count: $count}
    }
    then{
        console.log("Progressing...");
        modify($ctr, function(){this.count = $count + 1;});
    }
}

JavaScript appears in the pattern in each statement in the when clause. In this example the pattern is "$ctr.count % 1000 == 0"). There are a limited number of non-javascript substitutions in the patterns e.g. to support a regex operator '=~'.

The entirety of the then clause is JavaScript, except that aliases defined in the when appear as variables in the then clause. In this example $ctr is such an alias.

Toaster
  • 1,911
  • 2
  • 23
  • 43

1 Answers1

1

If

  • the syntax unambiguously separates "normal code" and "Javascript escapes"
  • you don't care about editor support for the Javascript parts

then you could create an Xtext grammar that parses the Javascript parts verbatim.

I can't give much more specific advice without seeing the DSL and knowing its use cases.

Stefan Oehme
  • 449
  • 2
  • 7
  • Thank you. I amended the question with additional information. Is there an existing Xtext grammar that parses Javascript? – Toaster Oct 31 '14 at 19:49
  • I found a proof of concept for a typescript grammar on Github: github.com/vorburger/eclipse-typescript-xtext/ But I guess making this work well will take a lot of time. JavaScript is no simple langauge =) – Stefan Oehme Nov 01 '14 at 20:30
  • Thanks for your input. I will have a look, time is an important factor so maybe IDE support is not in our future. – Toaster Nov 02 '14 at 11:01