Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Script with condition
Script with condition [message #893413] Tue, 03 July 2012 23:23 Go to next message
Eclipse UserFriend
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 03:52 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Script with condition [message #893470 is a reply to message #893438] Wed, 04 July 2012 05:00 Go to previous message
Eclipse UserFriend
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: Sun Jul 27 16:20:10 EDT 2025

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

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

Back to the top