0

In my application I have to type in some code for a specific domain and I would like to create a DSL for that. The DSL just should have some really basic commands.

DSL code example:

srccode{
    code: "if("
    func: insertInputData(1)
    code: "){\n    "
    func: insertOutputData(0)
    code: "\n}\n"
    cond: checkForOutputConnection(1):
        code: "else{\n    "
        func: insertOutputData(1)
        code: "\n}\n"
}

This code should get translated into source code of a general purpose language (f.ex. Python) like this:

def getSrcCode():
    s = ""
    s += "if("
    s += insertInputData(1)
    s += "){\n    "
    s += insertOutputData(0)
    s += "\n}\n"
    if(outputConnected(1)):
        s += "else{\n    "
        s += insertOutputData(1)
        s += "\n}\n"
    return s

So its actually just about a simple translation.

  • Xtext seems to get quite complex no later than when trying to integrate it in other (non-java) applications and well it seems to stich to Java.
  • JetBrains MPS is surely is something completely awesome but I don't want a projectional editor, just pure text

(this might be wrong, I didn't use any of them so far)

What workbench or tool would you recommend me to use to achieve the possibility to translate the code into other languages easily like as shown (I prefer something, that is fairly limited somehow but easy to learn and use while fitting my low needs).

mep
  • 341
  • 2
  • 11
  • Have you looked at https://dbader.org/blog/writing-a-dsl-with-python ? – Ross Presser Mar 20 '19 at 19:47
  • not yet, I will take a look, thanks! – mep Mar 20 '19 at 19:49
  • I'm definitely biased to xtext. You can create generators in xtext to generate whatever code you want based on the AST that is parsed from your text. This does mean you would be programming in something like Java or Xtend (a great language that simplifies Java but compiles to Java) – Zannith Mar 20 '19 at 20:17
  • for python specific you might consider https://github.com/textX/textX too – Christian Dietrich Mar 20 '19 at 21:08

1 Answers1

0

It's true that you can't get rid of the projectional editor in MPS, but with a good design of the DSL, you can limit the end-user and control their flow.

If you decide to give a chance to the projectional editor, this is the plugin that you will need http://dslfoundry.com/first-prototype-of-plaintextflow-released/

Cheers!