Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtext grammar(Xtext grammar)
Xtext grammar [message #1735919] Thu, 23 June 2016 11:52 Go to next message
Eclipse UserFriend
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 12:09 Go to previous messageGo to next message
Eclipse UserFriend
are you sure this is a parsing problem and not a missing subclassing STRINGValueConverter problem?
Re: Xtext grammar [message #1735924 is a reply to message #1735923] Thu, 23 June 2016 12:15 Go to previous messageGo to next message
Eclipse UserFriend
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 12:17 Go to previous messageGo to next message
Eclipse UserFriend
STRING value converters says \9 is an invalid escape sequence.
please debug org.eclipse.xtext.conversion.impl.STRINGValueConverter.convertFromString(String, INode)
Re: Xtext grammar [message #1735926 is a reply to message #1735925] Thu, 23 June 2016 12:21 Go to previous messageGo to next message
Eclipse UserFriend
Thanks
Re: Xtext grammar [message #1736206 is a reply to message #1735926] Mon, 27 June 2016 09:29 Go to previous messageGo to next message
Eclipse UserFriend
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 09:46 Go to previous messageGo to next message
Eclipse UserFriend
simply subclass STRINGValueConverter and add a binding for STRINGValueConverter to your subclass should be enhough
Re: Xtext grammar [message #1736326 is a reply to message #1736210] Tue, 28 June 2016 08:40 Go to previous messageGo to next message
Eclipse UserFriend
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 09:08 Go to previous message
Eclipse UserFriend
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;
    }
Previous Topic:When to use XExpression, XblockExpression and just plain parser rule
Next Topic:IllegalValueException when extending EssentialOCL
Goto Forum:
  


Current Time: Sat Jul 12 13:01:47 EDT 2025

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

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

Back to the top