Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding function calls to DSL syntax
Adding function calls to DSL syntax [message #1386691] Thu, 19 June 2014 13:48 Go to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
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 13:50]

Report message to a moderator

Re: Adding function calls to DSL syntax [message #1386703 is a reply to message #1386691] Thu, 19 June 2014 14:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13367
Registered: July 2009
Senior Member
Hi,

i think the best examples for that are Xtend and Xbase. But for simple routines this may be way too compilcated.

the only thing that is difficult when dealing with such thinks a methods that this is a point when you definitively need a typesystem (at least when the methods have params)

you may have a look at lorenzo bettinis xtext book.
there is e.g. a "small java" language.
the example code can be found here:https://github.com/LorenzoBettini/packtpub-xtext-book-examples/tree/master/org.example.smalljava


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding function calls to DSL syntax [message #1386705 is a reply to message #1386703] Thu, 19 June 2014 15:25 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 248
Registered: June 2013
Senior Member
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.
Previous Topic:Reference does not work
Next Topic:Replacing STRING terminal/skip inserting closing terminal
Goto Forum:
  


Current Time: Wed Feb 26 20:44:43 GMT 2020

Powered by FUDForum. Page generated in 0.02163 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top