Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unable to incorporate default IValueConverters(extends DefaultTerminalConverters enough?)
Unable to incorporate default IValueConverters [message #716844] Thu, 18 August 2011 15:03 Go to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Hi!

Having a blast playing with XText, but I've hit a brick wall I can't seem to surmount. I created a custom IValueConverter, and have it working (please see SOURCE below). However, the default IValueConverters do not seem to be working. For instance, I get parse errors in my generated editor for the ID rule - the only way to bypass the parse error is no prepend ID instances with '^' (please see Example below). Does anyone see my mistake?

Example
For this rule:
Define:
	DefineKeyword
	name = ID
	value = (ID | STRING)
;


the following syntax results in an error:
Define MY_VAR "value"


yet this syntax parses successfully:
Define ^MY_VAR "value"


SOURCE
Bound my custom IValueConverterService implementation:
public class TplXRuntimeModule extends com.exoanalytic.seas.tplx.AbstractTplXRuntimeModule {
	@Override
	public Class<? extends IValueConverterService> bindIValueConverterService() {
		return TplXValueConverterService.class;
	}
}


Extended DefaultTerminalConverters:
public class TplXValueConverterService extends DefaultTerminalConverters
{
	@ValueConverter(rule = "DEFINE_REFERENCE")
	public IValueConverter<String> defineReferenceValueConverter() {
		return new AbstractNullSafeConverter<String>() {
			@Override
			protected String internalToValue(String string, INode node)
				throws ValueConverterException {
				return string.startsWith("$") ? string.substring(1) : string;
			}
 
			@Override
			protected String internalToString(String value) {
				if (GrammarUtil.getAllKeywords(getGrammar()).contains(value)) {
					return "$"+value;
				}
				return value;
			}
		};
	}
}
Re: Unable to incorporate default IValueConverters [message #716903 is a reply to message #716844] Thu, 18 August 2011 18:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13930
Registered: July 2009
Senior Member
Hi,

can you share a complete reproducable grammar?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unable to incorporate default IValueConverters [message #716911 is a reply to message #716903] Thu, 18 August 2011 18:54 Go to previous messageGo to next message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Christian - thanks for the reply. Please see the attached file.
  • Attachment: TplX.xtext
    (Size: 1.85KB, Downloaded 102 times)
Re: Unable to incorporate default IValueConverters [message #716921 is a reply to message #716911] Thu, 18 August 2011 19:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13930
Registered: July 2009
Senior Member
Hi,

the problem is that DEFINE_REFERENCE hides ID

why not using a Datatype Rule instead of a terminal?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unable to incorporate default IValueConverters [message #716940 is a reply to message #716921] Thu, 18 August 2011 20:56 Go to previous message
Joey Mink is currently offline Joey MinkFriend
Messages: 87
Registered: July 2009
Location: Centreville, VA, USA
Member

Wow, thanks for the detective work. I changed the DEFINE_REFERENCE terminal rule to this Data Type Rule and no other changes were req'd - it simply worked!

DEFINE_REFERENCE returns ecore::EString:
	'$' ID	
;


Woohoo! Oh yeah, I also had to add this to the top of the grammar:

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Previous Topic:Prevent DirectoryCleaner to clean up 'xtend-gen' directory
Next Topic:problem with deploying plugin developed by xtext
Goto Forum:
  


Current Time: Sat May 08 20:33:30 GMT 2021

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

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

Back to the top