Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom validation in xtext(Custom validation in xtext related to keywords)
Custom validation in xtext [message #1424566] Tue, 16 September 2014 05:50 Go to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi all,
Part of my grammar looks something like this:

rule1:
	"ruleName" name=ID
	"{"
		"enum1" e1=Enum1
		"enum2" e2=Enum2
	"}"
;


Enum1:
	value=INT "=" name=ID 
;

enum Enum2:
	TRUE|FALSE
;


Language would look something like:

"ruleName" name1
	{
		"enum1" 2=enumName1
		"enum2" TRUE
	}


But one problem is that:
I can define Enum1 as,

"enum1" 2=TRUE or "enum1" 2=FALSE also, which will give me an xtext error automatically as TRUE/FALSE are part of enum.
But I want to put a CUSTOM VALIDATION ERROR here.
When I tried to read Enum1 in the background , it gives me a null value i.e. it gives "2=null".

How to solve this?

Thanks in advance Smile


Arshad
Re: Custom validation in xtext [message #1424568 is a reply to message #1424566] Tue, 16 September 2014 05:55 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Arshad,
to avoid conflicts with keywords, there is a special form of ID starting with a "^".

"enum1" 2=^TRUE will do the job for you.

Greetings from Frankfurt/Germany, Uli
icon5.gif  Re: Custom validation in xtext [message #1424594 is a reply to message #1424568] Tue, 16 September 2014 06:42 Go to previous messageGo to next message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Uli,
Thanks for your reply.
Yes I have made use of this special ID.

But the solution you have proposed follows- prevent it before it is happened.

But what I want is, say that intentionally I have typed it wrong and I want get this data in the validator which is giving me currently null.

Any suggestions for this ?

Thanks .. Smile

Greetings from Bangalore/INDIA


Arshad

[Updated on: Tue, 16 September 2014 06:43]

Report message to a moderator

Re: Custom validation in xtext [message #1424612 is a reply to message #1424594] Tue, 16 September 2014 07:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you can always use nodeModelUtil to access the "textual" tree


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
icon14.gif  Re: Custom validation in xtext [message #1424643 is a reply to message #1424612] Tue, 16 September 2014 08:10 Go to previous message
Arshad Adavani is currently offline Arshad AdavaniFriend
Messages: 163
Registered: July 2013
Location: Bangalore
Senior Member
Hi Christian and Uli,
NodeModeUtil solved my problem Smile

Thank you both for the suggestions Smile

Greetings from Bangalore/India, Arshad


Arshad
Previous Topic:Qualified name relative to a namespace import?
Next Topic:Linking to Rules/JvmTypes/Enumerations
Goto Forum:
  


Current Time: Fri Apr 19 23:41:56 GMT 2024

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

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

Back to the top