Skip to main content



      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 05:45 Go to next message
Eclipse UserFriend
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 05:51 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: Grammar for nested units [message #1791648 is a reply to message #1791645] Tue, 03 July 2018 06:11 Go to previous messageGo to next message
Eclipse UserFriend
=> why not simply

Model:
    animals+=Animal*;
    

Animal:
	name=ID
	children+=Animal*
	'END' pName=[Animal|ID];
Re: Grammar for nested units [message #1791655 is a reply to message #1791648] Tue, 03 July 2018 07:02 Go to previous message
Eclipse UserFriend
Thanks Mr. Christian,

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


Current Time: Thu Jun 19 06:27:23 EDT 2025

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

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

Back to the top