Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross References & Strings
Cross References & Strings [message #639454] Tue, 16 November 2010 16:11 Go to next message
PTavares  is currently offline PTavares Friend
Messages: 3
Registered: November 2010
Junior Member
Hi to all!
I need to devoloped a parser and I come across with xtext a couped weeks ago.
I love it but I have some doubts that I like to been explained.

1.) If I have something like this:

Prefix:
'prefix' name=(STRING|ID);

Command:
prefix=[Prefix] ':' arg=ID;

Why I only get the cross reference if the "prefix" is ID?
And how can I resolve it to get with cross reference with a string but unquoted?


2.) If my parser needs to allow something like this:
The following strings are equivalent:

hello
"hello"
'hello'
"hel" + "lo"
'hel' + "lo"

How can I differentiate a STRING from a ID?

3.) In relation to the second question, to concatenate strings with a plus sign ('+') I add the rule:

CUSTOMSTRING:
(STRING ('+' STRING)*);

With this new rule did I really need to add a Value converter? For which prupose?
Re: Cross References & Strings [message #639869 is a reply to message #639454] Thu, 18 November 2010 08:40 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
1) Try

StringOrId:
STRING | ID;

Prefix:
'prefix' name=StringOrID;

Command:
prefix=[Prefix|StringOrID] ...

By default, cross references are expected to have the Syntax of an ID.
So prefix=[Prefix] is the same as prefix=[Prefix|ID]. If you don't want
that, you have to put the rule for the Syntax after a | in the square
brackets, as sketched above.

2) You don't have to, just use the delegating datatype rule as described
above.

3) If you don't provide a value converter, the plus sign will be part of
the String.



Am 16.11.10 17:11, schrieb PTavares:
> Hi to all!
> I need to devoloped a parser and I come across with xtext a couped weeks
> ago.
> I love it but I have some doubts that I like to been explained.
>
> 1.) If I have something like this:
>
> Prefix:
> 'prefix' name=(STRING|ID);
>
> Command:
> prefix=[Prefix] ':' arg=ID;
>
> Why I only get the cross reference if the "prefix" is ID? And how can I
> resolve it to get with cross reference with a string but unquoted?
>
>
> 2.) If my parser needs to allow something like this:
> The following strings are equivalent:
>
> hello
> "hello"
> 'hello'
> "hel" + "lo"
> 'hel' + "lo"
>
> How can I differentiate a STRING from a ID?
>
> 3.) In relation to the second question, to concatenate strings with a
> plus sign ('+') I add the rule:
>
> CUSTOMSTRING:
> (STRING ('+' STRING)*);
>
> With this new rule did I really need to add a Value converter? For which
> prupose?


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:using AbstractXtextTests
Next Topic:xtext parser node
Goto Forum:
  


Current Time: Thu Apr 25 04:32:20 GMT 2024

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

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

Back to the top