Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to generate a method using xtend from xtext based syntax
how to generate a method using xtend from xtext based syntax [message #1275633] Sun, 23 March 2014 10:54 Go to next message
Zeinab Amouri is currently offline Zeinab AmouriFriend
Messages: 8
Registered: March 2014
Junior Member
Dear all,

I try to create a domain specific language using Xtext. I have an entity which should do some specific operation in my model. I generate my classes and their fields in java using Xtend but I have no idea about how I can generate a method using Xtend rules from my DSL syntax? Could somebody help me?

thanks in advance
Re: how to generate a method using xtend from xtext based syntax [message #1275661 is a reply to message #1275633] Sun, 23 March 2014 11:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not quite sure what you are talking about. can you please be a bit more specific.
- do you use jvmmodelinferrer?
- if not generating a class or a field is the same as generating methods.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to generate a method using xtend from xtext based syntax [message #1275815 is a reply to message #1275661] Sun, 23 March 2014 17:41 Go to previous messageGo to next message
Zeinab Amouri is currently offline Zeinab AmouriFriend
Messages: 8
Registered: March 2014
Junior Member
I used Xtext to declare language's syntax. I have several rules in my DSL that some of them can parsed as classes and others can parsed as a class's fields. Now I want to parse some other rules that used in another as methods. I used doGenrate method to generate my java classes and declare a compile method to transform former group of rules to fields.
Re: how to generate a method using xtend from xtext based syntax [message #1275848 is a reply to message #1275815] Sun, 23 March 2014 18:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i still do not understand how we can help you?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to generate a method using xtend from xtext based syntax [message #1275865 is a reply to message #1275848] Sun, 23 March 2014 19:38 Go to previous messageGo to next message
Zeinab Amouri is currently offline Zeinab AmouriFriend
Messages: 8
Registered: March 2014
Junior Member
Hi,
Please consider I have several entity in a domain. Each entity has some features that can parsed as properties in a java class(One java class has been generate for each entity). Entities also has some operations(behavior in abstract way) that I want to appear as methods in java classes later. I asked you hep me to find how I could generate methods for my entity's operations using in "*Generator.xtend" file.

regards
Re: how to generate a method using xtend from xtext based syntax [message #1275872 is a reply to message #1275865] Sun, 23 March 2014 19:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

i still do not understand your problem. especially without any grammar
generating operations is generating fields is generating any text ....
'''
public <<returnType>> <<name>>(<<FOR p : params SEPARATOR ",">><<p.type>> <<p.name>><ENDFOR>>) {
...
}
'''


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to generate a method using xtend from xtext based syntax [message #1275881 is a reply to message #1275872] Sun, 23 March 2014 20:11 Go to previous messageGo to next message
Zeinab Amouri is currently offline Zeinab AmouriFriend
Messages: 8
Registered: March 2014
Junior Member
Hi,
I have this grammar:

Form:
'Form' name = ID '{' (Logic += LogicalUnit)* operation=Operation '}';

LogicalUnit:
'field' name = ID '{' (features += Feature) '}';

Feature:
'name' ':' name = ID
'type' ':' type = ID
'label' ':' label = STRING
;
Operation:
name = ID : operation = ID ;


I know that generate fields means generate text. But assumes I want to generate a method in Form class when parser meets Operation rule. So if I use the code you mentioned I can generate a method for my Operation? I should use it when I parsed Form class?

Re: how to generate a method using xtend from xtext based syntax [message #1275884 is a reply to message #1275881] Sun, 23 March 2014 20:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes. of course it is different in your case.
please show us your template and what the actual problem is.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to generate a method using xtend from xtext based syntax [message #1275885 is a reply to message #1275884] Sun, 23 March 2014 20:16 Go to previous message
Zeinab Amouri is currently offline Zeinab AmouriFriend
Messages: 8
Registered: March 2014
Junior Member
Thank you
In fact I want to implement this language and I need generate code for it for a university project. You want to see which template exactly?

[Updated on: Sun, 23 March 2014 20:20]

Report message to a moderator

Previous Topic:formatting generated java-files after build
Next Topic:Xtext 2.6 binary compatibility
Goto Forum:
  


Current Time: Fri Apr 19 20:40:42 GMT 2024

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

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

Back to the top