Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » how to extract STRING content?
how to extract STRING content? [message #780819] Thu, 19 January 2012 14:03 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi,
the built-in terminal STRING, when used in grammar rules, returns the
literal string complete with escape sequence and bracketing quotes.

This is unsurprising.

I want to extract the supposed "value" of the string literal and I'm a
bit surprised I didn't find a standard way to do it.

If I understand correctly I should define a grammar rule like:

StringValue returns ecore::EString: value=STRING;

and then implement my own value converter.
Is this true?

I would be more than a bit surprised this very basic functionality isn't
included in the standard framework.

Am I missing something?

TiA
Mauro
Re: how to extract STRING content? [message #780824 is a reply to message #780819] Thu, 19 January 2012 14:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, you mix up parser rules that result in an class with Data type
rules that result in an edatatype. So the grammar you posted makes no
sense at all. Regards Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: how to extract STRING content? [message #780843 is a reply to message #780824] Thu, 19 January 2012 15:07 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Il 19/01/2012 15:17, Christian Dietrich ha scritto:
> Hi, you mix up parser rules that result in an class with Data type rules
> that result in an edatatype. So the grammar you posted makes no sense at
> all. Regards Christian

Sorry, my bad.

Grammar should read:

terminal SCONST returns ecore::EString:
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"'
|
"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
;

.... but question remains: How do I get the unescaped value of the
string, as opposed to the escaped and quoted value STRING returns?

Is the only method to define a custom converter?

TiA
Mauro
Re: how to extract STRING content? [message #780846 is a reply to message #780843] Thu, 19 January 2012 15:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Yes you need a ValueConverter - XText doesnt know anything about your semantics (or reuse the one from STRING)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to generate language with comments
Next Topic:Re-using OutlineTreeProvider??
Goto Forum:
  


Current Time: Thu Apr 25 22:25:19 GMT 2024

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

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

Back to the top