Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » can't use any word same than a keyword in my custom Enum rule
can't use any word same than a keyword in my custom Enum rule [message #896932] Fri, 20 July 2012 13:25 Go to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi,

I've create a enum rule this way:

Enum:
	'enum' name = ValidID
	'{'
	  (literals+=EnumLiteral ((',')? literals+=EnumLiteral)*)?
	'}'
;

EnumLiteral:
    name=ValidID 
    ('as' literal=STRING)? 
    ('=' value=INT)?
;



But unfortunately, I can't use any word that is a keyword inside this enum.

Is there any way I can handle this ?

thanks,

Cristiano
Re: can't use any word same than a keyword in my custom Enum rule [message #896942 is a reply to message #896932] Fri, 20 July 2012 13:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

what about escaping the keyword (uisng tilde) e.g.

enum ~enum {~as as "as"}


Alternatively change your grammar to use

ValidIDPlus: ValidID | "enum" | "as";


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: can't use any word same than a keyword in my custom Enum rule [message #896955 is a reply to message #896942] Fri, 20 July 2012 14:10 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi Christian,

well, I think I will go for the first option... but I need inform the user.

Could you tell me how could I get a list of all keywords inside a validation method... this I could compare what the user puts in the enum and warning him that he must escape that error word.

thanks

Cristiano

Re: can't use any word same than a keyword in my custom Enum rule [message #896956 is a reply to message #896955] Fri, 20 July 2012 14:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what about combining
org.eclipse.xtext.GrammarUtil.getAllKeywords(Grammar)
and
org.eclipse.xtext.IGrammarAccess.getGrammar()

inject the second and call the first from whereever you want


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: can't use any word same than a keyword in my custom Enum rule [message #896957 is a reply to message #896956] Fri, 20 July 2012 14:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S: http://blog.dietmar-stoll.de/2012/07/custom-syntax-error-messages-with-quick.html might give a solution to your problem

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: can't use any word same than a keyword in my custom Enum rule [message #896990 is a reply to message #896957] Fri, 20 July 2012 17:05 Go to previous message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Cool !

That is what I looking for !! Very Happy

Thanks again Christian !
Previous Topic:Accessing the validator from the build participant
Next Topic:Resolving imports in standalone generator
Goto Forum:
  


Current Time: Tue Apr 16 17:45:19 GMT 2024

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

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

Back to the top