Skip to main content



      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 01:50 Go to next message
Eclipse UserFriend
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
Re: Custom validation in xtext [message #1424568 is a reply to message #1424566] Tue, 16 September 2014 01:55 Go to previous messageGo to next message
Eclipse UserFriend
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 02:42 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Tue, 16 September 2014 02:43] by Moderator

Re: Custom validation in xtext [message #1424612 is a reply to message #1424594] Tue, 16 September 2014 03:20 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

you can always use nodeModelUtil to access the "textual" tree
icon14.gif  Re: Custom validation in xtext [message #1424643 is a reply to message #1424612] Tue, 16 September 2014 04:10 Go to previous message
Eclipse UserFriend
Hi Christian and Uli,
NodeModeUtil solved my problem Smile

Thank you both for the suggestions Smile

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


Current Time: Sun Jul 27 14:31:26 EDT 2025

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

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

Back to the top