Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Keywords available only in specific cases
Keywords available only in specific cases [message #1839965] Fri, 02 April 2021 10:47 Go to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi all,

I am building the following grammar, where I use inheritance. The user can create a base country or an inherited country by using the keyword "extends". In an inherited country the user can remove trees. However, the keyword "remove" also shows up in a base country, and I want to restrict it, to only be able to remove trees in an inherited country. Is it possible to do that?
Country:
	"country" name=ID ("extends" supercountry=[Country|QualifiedName])?
	forests=Forest
	;
Forest:
	"{" 
	"forest" name=ID "{"
	("tree" trees+=Tree ("," trees+=Tree)*)*
	(("remove") removetree=[Tree])?
	"}";
Tree:
	name=ID
;


Thank you!
Re: Keywords available only in specific cases [message #1839966 is a reply to message #1839965] Fri, 02 April 2021 11:08 Go to previous messageGo to next message
Neeraj Bhusare is currently online Neeraj BhusareFriend
Messages: 174
Registered: July 2009
Location: Canada
Senior Member
You might be able to filter out the proposal by customizing the generated proposal provider class.
If I were you, I would "show an error message" if the user tries to remove the tree from the base.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Keywords available only in specific cases [message #1839967 is a reply to message #1839966] Fri, 02 April 2021 11:18 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Any idea on how that can be implemented?
An example from some other grammar or something?

Thank you!
Re: Keywords available only in specific cases [message #1839993 is a reply to message #1839967] Sat, 03 April 2021 08:22 Go to previous message
Neeraj Bhusare is currently online Neeraj BhusareFriend
Messages: 174
Registered: July 2009
Location: Canada
Senior Member
Please read the section "Creating Custom Validation Rules" here - https://www.eclipse.org/Xtext/documentation/103_domainmodelnextsteps.html
Please read the validation section here - https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
All the Xtext examples that come with Eclipse (File->New->Example...->Xtext Examples) have a validation implementation and I guess some have custom proposal provides too.

Please take some time to study the documentation and the example projects.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Previous Topic:Creating terminal STRING rule with start and end tokens?
Next Topic:missing RULE_BEGIN if using whitespace-aware
Goto Forum:
  


Current Time: Fri May 14 11:37:32 GMT 2021

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

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

Back to the top