Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar for nested units(How to write grammar for nested units)
Grammar for nested units [message #1791644] Tue, 03 July 2018 09:45 Go to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Hello,

I need to write grammar for nested units.
I am writing an example below.

Grammar:
grammar org.xtext.example.mydsl1.AnimalDsl with org.eclipse.xtext.common.Terminals

generate animalDsl "http://www.xtext.org/example/mydsl1/AnimalDsl"

Model:
	animals+=Animals*;
	
Animals:
	{Animals}(name = Name animal+= Animal* end+=End*);

Animal:
	(name = Name e=End?);

Name:
	name=ID;

End:
	'END' pName=[Name|ID];


Model:
Pet
   Dog
     Cat
       Mouse
       END Mouse
     End Cat 
   END Dog   
   Duck
   END Duck
END Pet


Problem is "Duck", does not come in "Pet". In Outline view also, it shows at the same level as "Pet".
It should come under Pet as Pet is ending after Duck.

Could you please help with this.


Thanks and regards,
Virag Purnam
Re: Grammar for nested units [message #1791645 is a reply to message #1791644] Tue, 03 July 2018 09:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
your grammar does not know anything about indentation
and the end ist optional. so it is ambigous.
can you explain what you exactly want to achive?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammar for nested units [message #1791648 is a reply to message #1791645] Tue, 03 July 2018 10:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
=> why not simply

Model:
    animals+=Animal*;
    

Animal:
	name=ID
	children+=Animal*
	'END' pName=[Animal|ID];


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammar for nested units [message #1791655 is a reply to message #1791648] Tue, 03 July 2018 11:02 Go to previous message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Thanks Mr. Christian,

Works as expected.
Previous Topic:Grammar for nested units
Next Topic:About CrossReferenceSerialization in Xtext
Goto Forum:
  


Current Time: Thu Apr 18 05:01:52 GMT 2024

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

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

Back to the top