Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » terminal rule that returns a float
terminal rule that returns a float [message #493636] Tue, 27 October 2009 12:36 Go to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
Hi,
I would like to build a terminal rule that returns value of type float.

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

terminal ENG returns ecore::EFloat :
('-'|'+')? (INT '.' INT| '.' INT | INT '.') ('e' ('-'|'+') INT)?;

(the rule definition come from another thread in this forum about how to define a Real)

I stick with the same error marker in the editor --- java.lang.String cannot be cast to java.lang.Float ...on every "supposed" float value

Any idea?

Cheers,
Stefano
Re: terminal rule that returns a float [message #493640 is a reply to message #493636] Tue, 27 October 2009 12:49 Go to previous messageGo to next message
Ilyas Keser is currently offline Ilyas KeserFriend
Messages: 85
Registered: July 2009
Member
Hi Stefano,

afaik, you need to provide your own implementation of IValueConverterService (see [1] page 14 -> Return types).

ILyas

[1] http://www.eclipse.org/Xtext/documentation/0_7_2/xtext.pdf


Stefano Cottafavi schrieb:
> Hi,
> I would like to build a terminal rule that returns value of type float.
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> terminal ENG returns ecore::EFloat :
> ('-'|'+')? (INT '.' INT| '.' INT | INT '.') ('e' ('-'|'+') INT)?;
>
> (the rule definition come from another thread in this forum about how to
> define a Real)
>
> I stick with the same error marker in the editor --- java.lang.String
> cannot be cast to java.lang.Float ...on every "supposed" float value
> Any idea?
>
> Cheers,
> Stefano
Re: terminal rule that returns a float [message #493704 is a reply to message #493636] Tue, 27 October 2009 16:00 Go to previous messageGo to next message
Stefano Cottafavi is currently offline Stefano CottafaviFriend
Messages: 57
Registered: July 2009
Member
perfect! thank you very much. My own ValueConverterService now contains

@ValueConverter(rule = "ENG")
	public IValueConverter<Float> ENG() {
		return new AbstractToStringConverter<Float>() {
			@Override
			protected Float internalToValue(String string, AbstractNode node) throws ValueConverterException {
				return Float.valueOf(string);
			}
			
		};
	}


Cheers,
Stefano
Re: terminal rule that returns a float [message #516970 is a reply to message #493704] Thu, 25 February 2010 16:11 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

Hello,

I am trying to do the same, bur I wasn't able to figure in what class to add the methods. I tried creating a new one that extends DefaultTerminalConverters as suggested in the manual, but I think it is not being compiled and added to the generated dsl files.

Thanks,

Horacio


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: terminal rule that returns a float [message #516975 is a reply to message #493636] Thu, 25 February 2010 16:31 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You have to bind the IValueConverterService to your service in your runtime module.
Re: terminal rule that returns a float [message #517000 is a reply to message #516975] Thu, 25 February 2010 17:12 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

I know, that is what the manual says.. Don't mean to be rude but what does that mean in plain old 1st year English? Shocked

Thanks,


Horacio


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: terminal rule that returns a float [message #517003 is a reply to message #493636] Thu, 25 February 2010 17:19 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
You have a <DSLName>RuntimeModule.java file in your sources. Just add :

@Override
public Class<? extends IValueConverterService> bindIValueConverterService() {
return <YourValueConverter>.class;
}
Re: terminal rule that returns a float [message #517008 is a reply to message #517003] Thu, 25 February 2010 17:32 Go to previous messageGo to next message
Michel Simeon is currently offline Michel SimeonFriend
Messages: 130
Registered: December 2009
Senior Member
Hi Stefano,

I had similar problems and tried my way with value converter.

However, if you use the latest milestone of 0.8.0 stream the value converter will automatically delegate to the EcoreFactory for datatypes without an explicit conversion rule. Floats, Doubles, Dates etc should work out of the box this way.

MS
Re: terminal rule that returns a float [message #517091 is a reply to message #517008] Fri, 26 February 2010 08:58 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Michel Simeon schrieb:
> I had similar problems and tried my way with value converter.
> However, if you use the latest milestone of 0.8.0 stream the value
> converter will automatically delegate to the EcoreFactory for datatypes
> without an explicit conversion rule. Floats, Doubles, Dates etc should
> work out of the box this way.
As long as you stick with the string representation used in EcoreFactory.
For float that is the contract of
java.lang.Float.valueOf(String)

Sven


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:Validating with a hand-written metamodel
Next Topic:Unresolved proxy problem (with potential solution)
Goto Forum:
  


Current Time: Fri Apr 19 03:13:52 GMT 2024

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

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

Back to the top