Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Content assist and caracter encoding
Content assist and caracter encoding [message #512711] Sat, 06 February 2010 17:35 Go to next message
Michel Simeon is currently offline Michel Simeon
Messages: 125
Registered: December 2009
Senior Member
I am working on content assist by defining a number of strings in <my language>ProposalProvider.

If the string includes say the word "données" , then upon ctrl-space the editor will display \u00E9 for the é.

Is there a way to change that?

Thanks for support
MS
Re: Content assist and caracter encoding [message #512731 is a reply to message #512711] Sat, 06 February 2010 20:28 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2852
Registered: July 2009
Senior Member
Hi Michel,

I guess you have to override the STRING conversion in your value
converter. That should do the trick.
If you currently do not have an own value converter, please inherit from
DefaultTerminalConverters and bind your own implementation in you
runtime module to the IValueConverterService.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Am 06.02.10 18:35, schrieb Michel Simeon:
> I am working on content assist by defining a number of strings in <my
> language>ProposalProvider.
>
> If the string includes say the word "données" , then upon ctrl-space the
> editor will display \u00E9 for the é.
>
> Is there a way to change that?
>
> Thanks for support
> MS
>
Re: Content assist and caracter encoding [message #513612 is a reply to message #512731] Wed, 10 February 2010 17:09 Go to previous messageGo to next message
Michel Simeon is currently offline Michel Simeon
Messages: 125
Registered: December 2009
Senior Member
[quote title=Sebastian Zarnekow wrote on Sat, 06 February 2010 15:28]Hi Michel,

I guess you have to override the STRING conversion in your value
converter. That should do the trick.
If you currently do not have an own value converter, please inherit from
DefaultTerminalConverters and bind your own implementation in you
runtime module to the IValueConverterService.

Regards,
Sebastian
--

I have created my own value converter ( i needed one anyway). I actually copied the STRING conversion from DefaultTerminalConverters, and called a modified version of convertToJavaString, where the default switch case does not recreate the \uxxxx notation as in the original.

So my question is: what is the rationale for doing it that way ? Also, why are Default Terminals so limited, would not it be usefull to include floating point numbers or negative integers ?

Regards
MS
Re: Content assist and caracter encoding [message #513802 is a reply to message #513612] Thu, 11 February 2010 11:17 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2852
Registered: July 2009
Senior Member
Hi Michael,

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.

We decided to limit the default terminal rules to a reasonable set of
commonly used tokens. That's why there is no floating point number and
no signed integer rule. However, if you create your own data type or
terminal rule and do not create a converter for it, the default emf
based conversion will be used, e.g.

SignedInt return EInt:
('+'|'-')? INT;

should work. Note that this functionality has been added in the latest
milestone of the 0.8.0 stream.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Am 10.02.10 18:09, schrieb Michel Simeon:
> I have created my own value converter ( i needed one anyway). I actually
> copied the STRING conversion from DefaultTerminalConverters, and called
> a modified version of convertToJavaString, where the default switch case
> does not recreate the \uxxxx notation as in the original.
>
> So my question is: what is the rationale for doing it that way ? Also,
> why are Default Terminals so limited, would not it be usefull to include
> floating point numbers or negative integers ?
>
> Regards
> MS
Re: Content assist and caracter encoding [message #513929 is a reply to message #513802] Thu, 11 February 2010 17:13 Go to previous messageGo to next message
Michel Simeon is currently offline Michel Simeon
Messages: 125
Registered: December 2009
Senior Member
[quote title=Sebastian Zarnekow wrote on Thu, 11 February 2010 06:17]Hi Michael,

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.

We decided to limit the default terminal rules to a reasonable set of
commonly used tokens. That's why there is no floating point number and
no signed integer rule. However, if you create your own data type or
terminal rule and do not create a converter for it, the default emf
based conversion will be used, e.g.

SignedInt return EInt:
('+'|'-')? INT;

should work. Note that this functionality has been added in the latest
milestone of the 0.8.0 stream.

Regards,
Sebastian
--
Thank you for the clarification. I has indeed defined my own SignedInt and Float rules together with corresponding value converters, and checked that I could do without those value converters.

Regards
MS


Re: Content assist and caracter encoding [message #514017 is a reply to message #513929] Fri, 12 February 2010 07:40 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Michel Simeon wrote:
>
> 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.

Follow-up question:

I need to define a rule for URIs and believe it can be done as follows:
- define URI datatype in my domain model
- generate and implement the createFromString and convertToString in the
factory
- define a terminal rule that return the datatype

Is this correct, i.e. will the parser use the factory methods? How
should I signal syntax errors in the createFromString method, so it is
picked up by the parser (in case the terminal rule isn't tight enough)?

Hallvard
Re: Content assist and caracter encoding [message #514024 is a reply to message #514017] Fri, 12 February 2010 09:03 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1767
Registered: July 2009
Senior Member
Hallvard Trætteberg schrieb:
> Michel Simeon wrote:
>>
>> 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.
>
> Follow-up question:
>
> I need to define a rule for URIs and believe it can be done as follows:
> - define URI datatype in my domain model
> - generate and implement the createFromString and convertToString in the
> factory
> - define a terminal rule that return the datatype
>
> Is this correct, i.e. will the parser use the factory methods?

Yes, as long as you use 0.8.0 >= M4.

> How
> should I signal syntax errors in the createFromString method, so it is
> picked up by the parser (in case the terminal rule isn't tight enough)?

Errors which occur during value conversion can be reported by throwing a
org.eclipse.xtext.conversion.ValueConverterException.

Cheers,
Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Content assist and caracter encoding [message #514127 is a reply to message #514024] Fri, 12 February 2010 09:16 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 594
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Sven Efftinge wrote:
> Hallvard Trætteberg schrieb:
>> Follow-up question:
>>
>> I need to define a rule for URIs and believe it can be done as follows:
>> - define URI datatype in my domain model
>> - generate and implement the createFromString and convertToString in
>> the factory
>> - define a terminal rule that return the datatype
>>
>> Is this correct, i.e. will the parser use the factory methods?
>
> Yes, as long as you use 0.8.0 >= M4.

:-)

>> How should I signal syntax errors in the createFromString method, so
>> it is picked up by the parser (in case the terminal rule isn't tight
>> enough)?
>
> Errors which occur during value conversion can be reported by throwing a
> org.eclipse.xtext.conversion.ValueConverterException.

The URI class throws an IllegalArgumentException, so from what you write
I need to wrap it in a ValueConverterException. It doesn't seem right to
do this in the Factory, after all it should be independent of Xtext.
Hence, I have to create an Xtext value converter after all? Wouldn't it
make sense to catch all RuntimeExceptions and treat them as
ValueConverterExceptions?

Hallvard
Re: Content assist and caracter encoding [message #514136 is a reply to message #514127] Fri, 12 February 2010 14:48 Go to previous message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2852
Registered: July 2009
Senior Member
Hi Hallvard,

you wouldn't like the error message "IllegalArgumentException: ..." in
your editor, would you? Furthermore, RuntimeExceptions usually indicate
programming errors and that's why we should not catch those.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 12.02.10 15:08, schrieb Hallvard Trætteberg:
> Sven Efftinge wrote:
>> Hallvard Trætteberg schrieb:
>>> Follow-up question:
>>>
>>> I need to define a rule for URIs and believe it can be done as follows:
>>> - define URI datatype in my domain model
>>> - generate and implement the createFromString and convertToString in
>>> the factory
>>> - define a terminal rule that return the datatype
>>>
>>> Is this correct, i.e. will the parser use the factory methods?
>>
>> Yes, as long as you use 0.8.0 >= M4.
>
> :-)
>
>>> How should I signal syntax errors in the createFromString method, so
>>> it is picked up by the parser (in case the terminal rule isn't tight
>>> enough)?
>>
>> Errors which occur during value conversion can be reported by throwing
>> a org.eclipse.xtext.conversion.ValueConverterException.
>
> The URI class throws an IllegalArgumentException, so from what you write
> I need to wrap it in a ValueConverterException. It doesn't seem right to
> do this in the Factory, after all it should be independent of Xtext.
> Hence, I have to create an Xtext value converter after all? Wouldn't it
> make sense to catch all RuntimeExceptions and treat them as
> ValueConverterExceptions?
>
> Hallvard
Previous Topic:Referencing 'internal' objects
Next Topic:strange duplication check
Goto Forum:
  


Current Time: Tue Sep 30 14:05:08 GMT 2014

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

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