Adding function calls to DSL syntax [message #1386691] |
Thu, 19 June 2014 09:48  |
Eclipse User |
|
|
|
This is probably pretty easy but I thought I'd ask about it here because it strikes me as possibly a common problem that people encounter.
The big benefit I have gained from using Xtext/Xtend as a supplement to my Java application is collapsing of patterns I saw in my Java code to a more compact representation in the DSL.
Now I'm starting to see patterns develop in my DSL source code itself and I would like to collapse those again, if possible. If I were writing this in a normal language I would simply put those statements into a subroutine and then call them while passing any needed parameters. Or, I might pull that code out to be a separate object that could be re-used by other classes. This is what I'd really like to do.
Currently, my DSL simply goes line by line. The model is built up and then when the Xtend code generators are called, the model is iterated and the structure is created then, all according to the template code in the generator.
Adding the concept of a subroutine means that I need to isolate a certain group of statements and not treat those exactly like the rest of them. It would require some of the structural decisions to be managed at parsing rather than code generation time.
Is this a common problem? Any examples available showing how it's already been solved?
Thanks,
GW
[Updated on: Thu, 19 June 2014 09:50] by Moderator
|
|
|
|
Re: Adding function calls to DSL syntax [message #1386705 is a reply to message #1386703] |
Thu, 19 June 2014 11:25  |
Eclipse User |
|
|
|
Hi Gary,
whenever you see some patterns in your DSL, you may start with a very flexible solution:
just create a Template for your DSL editor with the ${placeholder} syntax.
After some time, you may not want to have all that boilerplate code in your DSL file, SO:
you can enhance your generator to handle these "patterns" (as a group of existing generator steps)
and you add these patters with some keyword and their placeholder-value pairs to your grammar.
Pretty easy.
Right now, I'm working on a LUECKEN(X)TEXT concept which adresses this kind of tasks.
|
|
|
Powered by
FUDForum. Page generated in 0.04550 seconds