Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext keywords at wrong position(Xtext keywords at wrong position)
icon5.gif  Xtext keywords at wrong position [message #1485511] Mon, 24 November 2014 09:54 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi All,

Consider the following DSL snippet :

entity Name1 {
property1 NOT_APPLICABLE 
property2 NOT_APPLICABLE 
}


Here entity, property1 and property2 are keywords in my grammar.

Is there a direct way to know if I have typed my keyword at wrong position ?

Say something like :

entity Name1 {
property1 property1  
property2 property2 
}


At this point, no doubt xtext provides me an error but I want to put customized error message.

So is there a better way or I have to iterate my model completely ?


Thanks for any help..




Arshad
Re: Xtext keywords at wrong position [message #1485516 is a reply to message #1485511] Mon, 24 November 2014 09:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

i am not sure if i get your question but you can customize error messages through
org.eclipse.xtext.parser.antlr.ISyntaxErrorMessageProvider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon5.gif  Re: Xtext keywords at wrong position [message #1485592 is a reply to message #1485516] Mon, 24 November 2014 11:16 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
HI Christian,

To be more precise,
Say that I have declared an enum in my grammar:

enum MyEnum:
	VALUE1| VALUE2
;


and value for property1 and property2 would be one among the enum values.
Something like:

entity Name1 {
property1 VALUE1
property2 VALUE2
}


Now, say that I am creating one more entity like:

entity VALUE1{
property1 VALUE1
property2 VALUE2
}



You can see above that the name of the entity is set to VALUE1.
Entity name follows ID grammar rule.
VALUE1 is a valid ID but it matches one of my keywords and xtext gives me an error for this because its used in a wrong position.

Here I want to provide my custom error message.
So my doubt was, whether Xtext provides us some help to detect this automatically or we need to iterate over the model completely for this.

Thanks for any help.


Arshad
Re: Xtext keywords at wrong position [message #1485597 is a reply to message #1485592] Mon, 24 November 2014 11:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
No,

you you have to customize the ISyntaxErrorMessageProvider. debug the existing implementation an have a look what happens. maybe you can find it out.
the default error message will be like expected ID and got VALUE1.

btw if you want to allow keywords you could (depending on your grammar) introduce a Datatype rule like

MY_ID: ID | ''VALUE1" | "VALUE2"

and use that instead if ID for the name attr.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon14.gif  Re: Xtext keywords at wrong position [message #1485657 is a reply to message #1485597] Mon, 24 November 2014 12:26 Go to previous message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian,
Thanks for the info.

I did it using ISyntaxErrorMessageProvider.


Thanks..


Arshad
Previous Topic:eclipse build runs in endless loop
Next Topic:Xtext editor broken
Goto Forum:
  


Current Time: Tue Sep 24 10:24:49 GMT 2024

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

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

Back to the top