Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Terminal rule named INT not awaiting an Integer
Terminal rule named INT not awaiting an Integer [message #982862] Tue, 13 November 2012 13:31 Go to next message
Franck Malartic is currently offline Franck MalarticFriend
Messages: 5
Registered: September 2012
Junior Member
Hello,

Just to let you know that I run into a problem by using a grammar with terminal rule defined like this :

terminal fragment SIGN               :   '+' | '-' ;
terminal fragment DIGIT              : ('0'..'9');
terminal INT returns ecore::ELong   : SIGN? DIGIT+;

Note that my grammar is not using common terminals (org.eclipse.xtext.common.Terminals).

The problem when parsing is a conversion exception : "java.lang.Integer cannot be cast to java.lang.Long".

With the debugger, it appears that org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService#getConverter(String lexerRule) returns an instance of org.eclipse.xtext.conversion.impl.INTValueConverter instead of the DefaultTerminalConverter.

By changing the terminal rule name to LONG (or anything else) it works fine (so that is not a issue for me anymore).

I am not sure if this is bug or if INT is a some kind of reserved terminal rule name.
Hope that can help,
Regards,
franck

PS: using eclipse Indigo with xtext 2.2.1.
Re: Terminal rule named INT not awaiting an Integer [message #982877 is a reply to message #982862] Tue, 13 November 2012 13:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6485
Registered: July 2009
Senior Member
Hi you have to bind a proper ivalueconverterservice yourself

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Terminal rule named INT not awaiting an Integer [message #982917 is a reply to message #982877] Tue, 13 November 2012 14:28 Go to previous message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 86
Registered: July 2009
Member
Hi!

You can also watch this screencast about terminals and IValueConverters: http://xtextcasts.org/episodes/11-custom-terminals

In your special case you have to define a new terminal (LINT for example), IValueConverter and hide or reuse the INT terminal:

terminal fragment SIGN : '+' | '-' ;
terminal LINT returns ecore::ELong : SIGN? INT;

(untested)

Regards,
Boris
Previous Topic:Conflicting content assist proposal handlers
Next Topic:Validator - Error/Warning Message Syntax
Goto Forum:
  


Current Time: Sun Nov 23 20:19:21 GMT 2014

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

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