Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Adding function calls to DSL syntax
Adding function calls to DSL syntax [message #1386691] Thu, 19 June 2014 09:48 Go to next message
Eclipse UserFriend
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 #1386703 is a reply to message #1386691] Thu, 19 June 2014 10:46 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Adding function calls to DSL syntax [message #1386705 is a reply to message #1386703] Thu, 19 June 2014 11:25 Go to previous message
Eclipse UserFriend
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: Sat Jul 12 01:02:36 EDT 2025

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

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

Back to the top