Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Script with condition
Script with condition [message #893413] Wed, 04 July 2012 03:23 Go to next message
Nicolas Rousseau is currently offline Nicolas RousseauFriend
Messages: 18
Registered: July 2009
Junior Member
Hello,

I have a script with something like:

Parameter:
(name=EString ':'value=EString)
;


Parameters:
(parameter+=Parameter)
( "," parameter+=Parameter)*
;

(model simplified)

However what i'd like is to avoid to display the parameter if the value is empty (or null)

Means if i have:
Parameter.name = 'D'
Parameter.value = ''

or

Parameter.name = 'E'
Parameter.value = null (<not set>)

I simply want to display the result like:
A:a,
B:b,
C:c

and not:
A:a,
B:b,
C:c,
D:,
E:

How to achieve this?
I tried even things like extends the "isTransient".
But it generate things like:
A:a,
B:b,
C:c,,
(means with empty parameter but with comma..)

I guess there is something really better than this and more simple than modify the isTransient...

note: I'm still using the version 1.0.1 of xtext....


Thanks in advance !
Re: Script with condition [message #893438 is a reply to message #893413] Wed, 04 July 2012 07:52 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

it is not quite clear but I think you are talking about generating something with Xpand in a foreach construct. In this case you can simply use something like .reject(e|e.value==null) in order to filter elements.

If you share your Xpand code, it would be easier to provide the correct syntax.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Script with condition [message #893470 is a reply to message #893438] Wed, 04 July 2012 09:00 Go to previous message
Nicolas Rousseau is currently offline Nicolas RousseauFriend
Messages: 18
Registered: July 2009
Junior Member
in fact to give more concrete example, here's one part of the (real) grammar:

As you can see, based on emf model directly.
SubjobType returns talendFile::SubjobType:
    {talendFile::SubjobType}
    'addSubjob'
    '{'
    (elementParameter+=(ElementParameterType | SchemaElementParameterType))
    ("," elementParameter+=(SchemaElementParameterType | ElementParameterType))*
    '}';

ElementParameterType returns talendFile::ElementParameterType:
    {talendFile::ElementParameterType}
    (name=EString ':' value=EExpression);

SchemaElementParameterType returns talendFile::ElementParameterType:
    {talendFile::ElementParameterType}
    (name=EString '{' elementValue+=ElementValueType ("," elementValue+=ElementValueType)* '}')?;


Everything works well here...

but if the value of ElementParameterType is empty or null, i'd like to don't generate anything.

Actually, with this grammar, when i give EMF model and try to get the script, i can get things like:

addSubjob {
   A:a,
   B:b,
   C:c,
   D:,
   E:
}

(only considering the ElementParameterType)
but i'd prefer generate only something like:

addSubjob {
   A:a,
   B:b,
   C:c
}


(with real values only)
Previous Topic:Lazy Linking is broken in 2.3
Next Topic:Grammar for natural language business rules
Goto Forum:
  


Current Time: Tue Apr 23 13:57:48 GMT 2024

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

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

Back to the top