Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext grammar(Xtext grammar)
Xtext grammar [message #1735919] Thu, 23 June 2016 15:52 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

Can anyone tell me how to write terminal String to satisfy below declaration for string

"\9\9\9\9\9\9\9\9\9"

My terminal rule is:

terminal STRING : '"' ( '\\'('"'|('\r'? '\n')) | !('\n'|'"') )* '"' |
"'" ( '\\'("'"|('\r'? '\n')) | !('\n'|"'") )* "'";
Re: Xtext grammar [message #1735923 is a reply to message #1735919] Thu, 23 June 2016 16:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
are you sure this is a parsing problem and not a missing subclassing STRINGValueConverter problem?

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: Xtext grammar [message #1735924 is a reply to message #1735923] Thu, 23 June 2016 16:15 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
This is parsing problem because if I write string like "\\9\\9\\9\\9\\9\\9\\9" it is parsing without error.
Re: Xtext grammar [message #1735925 is a reply to message #1735924] Thu, 23 June 2016 16:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
STRING value converters says \9 is an invalid escape sequence.
please debug org.eclipse.xtext.conversion.impl.STRINGValueConverter.convertFromString(String, INode)


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: Xtext grammar [message #1735926 is a reply to message #1735925] Thu, 23 June 2016 16:21 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Thanks
Re: Xtext grammar [message #1736206 is a reply to message #1735926] Mon, 27 June 2016 13:29 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,
I have written the below code back slash problem solved. But how replace all with [a-z] solved my problem? I just threw a stone for replace its working

class CustomTerminalConverters extends DefaultTerminalConverters {
@Inject
private STRINGValueConverter stringValueConverter;

@ValueConverter(rule = "STRING")
override IValueConverter<String> STRING() {
return stringValueConverter;
}
}
class STRINGValueConverter extends AbstractLexerBasedConverter<String> {

override toValue(String string, INode node) throws ValueConverterException {
println("String value converter is called::::::::::::::::::"+node+" :::: "+string)
return string.replaceAll("[a-z]", "");
}

}
Re: Xtext grammar [message #1736210 is a reply to message #1736206] Mon, 27 June 2016 13:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
simply subclass STRINGValueConverter and add a binding for STRINGValueConverter to your subclass should be enhough

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: Xtext grammar [message #1736326 is a reply to message #1736210] Tue, 28 June 2016 12:40 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Sir could you please tell me how it is working?
Re: Xtext grammar [message #1736332 is a reply to message #1736326] Tue, 28 June 2016 13:08 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
i dont get your point

Xtext will call the STRINGValueConverter that is injected into DefaultValueConverterService thus you can subclass STRINGValueConverter

public class MySTRINGValueConverter extends STRINGValueConverter {
	
	@Override
	protected String convertFromString(String literal, INode node) throws ValueConverterWithValueException {
		// FIX impl here e.g. by copy paste adapt super impl
		return super.convertFromString(literal, node);
	}
	
	@Override
	protected String toEscapedString(String value) {
		// FIX impl here e.g. by copy paste adapt super impl
		return super.toEscapedString(value);
	}

}


and simply add a binding as you do it for 10000 stuff as well

    def Class<? extends STRINGValueConverter> bindSTRINGValueConverter() {
    	return MySTRINGValueConverter;
    }


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
Previous Topic:When to use XExpression, XblockExpression and just plain parser rule
Next Topic:IllegalValueException when extending EssentialOCL
Goto Forum:
  


Current Time: Tue Jan 26 12:37:10 GMT 2021

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

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

Back to the top