Backslash in string [message #876959] |
Fri, 25 May 2012 15:43  |
Eclipse User |
|
|
|
Hello Xtext community!
I'm trying to define a terminal rule which allows strings to contain single backslashes, but with no success so far...
Example token: "c:\some\windows\path\file.txt"
This seems to be a logical solution for me
terminal STRING returns ecore::EString:
'"' (!'"')* '"';
or also this
terminal STRING returns ecore::EString:
'"' -> '"';
However when parsing an example file I'm getting the following error:
Error at line 7 at '"D:\myFolder123\ELMN.ed"': Illegal escape character \m
Could anybody give me a hint how to handle the \ character?
Your help is greatly appreciated!
Bryce
|
|
|
|
Re: Backslash in string [message #876980 is a reply to message #876959] |
Fri, 25 May 2012 16:08   |
Eclipse User |
|
|
|
Hi Bryce,
you have to register a value converter for your variant of STRING.
Please refer to the docs for details on value conversion.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 25.05.12 17:43, schrieb Bryce Brinkley:
> Hello Xtext community!
>
> I'm trying to define a terminal rule which allows strings to contain
> single backslashes, but with no success so far...
> Example token: "c:\some\windows\path\file.txt"
>
> This seems to be a logical solution for me
> terminal STRING returns ecore::EString:
> '"' (!'"')* '"';
> or also this
> terminal STRING returns ecore::EString:
> '"' -> '"';
> However when parsing an example file I'm getting the following error:
> Error at line 7 at '"D:\myFolder123\ELMN.ed"': Illegal escape character \m
>
> Could anybody give me a hint how to handle the \ character?
> Your help is greatly appreciated!
>
> Bryce
|
|
|
Re: Backslash in string [message #1736205 is a reply to message #876980] |
Mon, 27 June 2016 13:26   |
Eclipse User |
|
|
|
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]", "");
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.04367 seconds