Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Optional properties using XText(Need utmost one occurrence for a set of properties)
Optional properties using XText [message #1799128] Fri, 30 November 2018 03:35 Go to next message
Eclipse UserFriend
Hi All,

I am new to XText and developing a DSL where each object can have a set of optional properties.
E.g.

Properties {
key1=value1,
key2=value2,
key3=value3,
key4=value4
}

The keys are predefined and each key can occur at most once. I have a simple grammar as depicted below. With this I am able to make the properties optional but the grammar allows for duplicate properties. Is there a way to check for single occurrence of each property ?? Thanks for any help.

PropertySet:
'Properties' '{'
((properties+=Property) (',' properties+=Property)*)? ';'
'}'
;

Property:
Property1 | Property2 | Property3 | Property4
;

Property1:
'key1' '=' value=STRING ;

Property2:
'key2' '=' value=Number ;

Property3:
'key3' '=' value=(Null | STRING) ;

Property4:
'key4' '=' value=Boolean ;

Boolean: 'true' | 'false';

Null: 'null';

terminal Number:
'-'? INT? '.' INT (('E'|'e') '-'? INT)?;
Re: Optional properties using XText [message #1799160 is a reply to message #1799128] Fri, 30 November 2018 11:44 Go to previous messageGo to next message
Eclipse UserFriend
Have a look at the concept of unordered groups
Re: Optional properties using XText [message #1799221 is a reply to message #1799160] Sun, 02 December 2018 13:13 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the reply. But I could not find a clean way to do unordered groups with the delimiter (',') in between. It should appear after each item except the last.
Re: Optional properties using XText [message #1799226 is a reply to message #1799221] Sun, 02 December 2018 16:29 Go to previous message
Eclipse UserFriend
Well then simply use a validation
Previous Topic:Force incremental build
Next Topic:Problem saving model instances with cross-references
Goto Forum:
  


Current Time: Fri Jun 13 12:07:58 EDT 2025

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

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

Back to the top