Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Defining subtypes without unsigned rule calls
Defining subtypes without unsigned rule calls [message #1769480] Tue, 01 August 2017 01:40 Go to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
Hi

I had a grammar like this:
Property:
	propertyName=ID ('=' values+=PropertyValue (',' values+=PropertyValue)*)? ';'
;
PropertyValue:
	StringValue | ArrayValue | ByteValue | Reference
;


This created a super class PropertyValue with sub-types such as StringValue, ArrayValue etc. This worked perfectly according to my needs.

However, now i need to extend the grammar so that I can add a common attribute to the PropertyValue class. Something like:
Property:
	propertyName=ID ('=' values+=PropertyValue (',' values+=PropertyValue)*)? ';'
;
PropertyValue:
	(readOnly?='*')? (StringValue | ArrayValue | ByteValue | Reference)
;


Note the new readOnly attribute under PropertyValue. This is now causing syntax errors as it forces me to assign the subtype values to some attribute.

If I move (readOnly?='*')? after subtypes, then it works but that is not what I really want.
Re: Defining subtypes without unsigned rule calls [message #1769502 is a reply to message #1769480] Tue, 01 August 2017 06:49 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 748
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You have to out the readOnly attribute in each subrule. Xtext will factor the attribute to the base class PropertyValue.

PropertyValue:
	(StringValue | ArrayValue | ByteValue | Reference)
;
StringValue:
   (readOnly?='*')?  ...... ;

ArrayValue:
   (readOnly?='*')?  ...... ;

Re: Defining subtypes without unsigned rule calls [message #1769505 is a reply to message #1769502] Tue, 01 August 2017 07:15 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
Yes that is what I am doing currently, but I asked in hope there was a way to "clean up" the grammar, by defining the attribute only once. Like we usually do with super and sub classes. It often gets confusing in my head how to mingle some of these common oop concepts with language grammars.
Re: Defining subtypes without unsigned rule calls [message #1769506 is a reply to message #1769505] Tue, 01 August 2017 07:16 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas IlyasFriend
Messages: 80
Registered: July 2009
Member
And thanks a lot for the help!
Re: Defining subtypes without unsigned rule calls [message #1769507 is a reply to message #1769506] Tue, 01 August 2017 07:23 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14064
Registered: July 2009
Senior Member
you can make cuse of grammar fragments to make it "more consistent" if you like
e.g


PropertyValue:
	 (StringValue | ArrayValue | ByteValue | Reference)
;

StringValue:
	ReadOnly value=STRING
;

ByteValue:
	ReadOnly value=INT
;

Reference:
	ReadOnlyvalue=ID
;

ArrayValue:
	 {ArrayValue} ReadOnly"#""[" (ints+=INT ("," ints+=INT)*)? "]"
;

fragment ReadOnly:	
(readOnly?='*')?
;


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Large grammar - "heap space" error - but ends by 'done'
Next Topic:Efficient way of loading an EMF resource at start-up?
Goto Forum:
  


Current Time: Thu Sep 23 06:37:21 GMT 2021

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

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

Back to the top