Optional properties using XText [message #1799128] |
Fri, 30 November 2018 03:35  |
Eclipse User |
|
|
|
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)?;
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03995 seconds