Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Escaping keywords with a QualifiedNameValueConverter?
Escaping keywords with a QualifiedNameValueConverter? [message #898680] Fri, 27 July 2012 07:40 Go to next message
Ian Warwick is currently offline Ian WarwickFriend
Messages: 44
Registered: April 2012
Member
I am trying to escape a keyword and I read from several google results that if I register a value converter for my qualified name rule it will do it automatically, but its not working for me.

This is my grammar

grammar com.fluxtah.example.sharedprefs.SharedPreferencesModel with org.eclipse.xtext.common.Terminals

generate sharedPreferencesModel "url goes here"

Model:
	'package' packageName=FQN
	preferencesBlock=PreferencesBlock;

PreferencesBlock:
	'preferences' name=ID '{' (prefs+=Preference)* '}';

Preference:
	name=ID ':' type=PreferenceType
;

enum PreferenceType:
	String='String' | 
	Integer='int' | 
	Boolean='boolean' | 
	Float='float' |
	Long='long'
	;


FQN:
	ID (=>'.' ID)*;


And this is my module config:

public class SharedPreferencesModelRuntimeModule extends com.fluxtah.example.sharedprefs.AbstractSharedPreferencesModelRuntimeModule {
	
	@Override
	public Class<? extends IValueConverterService> bindIValueConverterService() {
		return ValueConverters.class;
	}
}


And here is my value converter:

public class ValueConverters extends DefaultTerminalConverters {
	@Inject QualifiedNameValueConverter mFQNValueConverter;
	
	@ValueConverter(rule = "FQN")
    public IValueConverter<String> FQN() {
		return mFQNValueConverter;
    }
}


And my model:

package com.fluxtah.example.preferences.qux

preferences DashUser {
    IsAuthenticated:boolean
    LoginNamespace:String
    LoginPassword:String
    LoginUsername:String
}



But the package declaration still shows an error so I guess I have missed something fundamental in my understanding of value converters?

Really appreciate if someone could help me.

[Updated on: Fri, 27 July 2012 07:40]

Report message to a moderator

Re: Escaping keywords with a QualifiedNameValueConverter? [message #898688 is a reply to message #898680] Fri, 27 July 2012 08:18 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

yes you missed something fundamental. In order for the value converter to handle escaping, something must be escaped in the model file.

In package com.fluxtah.example.preferences.qux "preferences" is not escaped, hence tokenized as a keyword (which is not allowed in your FQN definition) and not as ID. This causes the error in the editor.

The default escaping character for an ID used to be ^.

package com.fluxtah.example.^preferences.qux would then be syntactically correct. NOW, the value converter's job is to make sure that the escape character will not go into the semantic model.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Escaping keywords with a QualifiedNameValueConverter? [message #898696 is a reply to message #898688] Fri, 27 July 2012 08:56 Go to previous message
Ian Warwick is currently offline Ian WarwickFriend
Messages: 44
Registered: April 2012
Member
Thanks! thats great Smile
Previous Topic:Refactoring nested elements/references
Next Topic:XText cross referencing scoping
Goto Forum:
  


Current Time: Fri Apr 19 11:11:11 GMT 2024

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

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

Back to the top