Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext syntax question
xtext syntax question [message #713615] Mon, 08 August 2011 16:50 Go to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi,

I'd like to create a rule having mix content of text and nested rules. a la:

Model[
text img text img text ...
]

So I've tried combining them by optional elements. But the grammar
parser always complains on multiple alternatives. How can I solve such
issue?

Here is a sample grammar:

grammar org.xtext.example.mydsl.MyDsl with
org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model: {Model} "Model";
Element: {Element} content+=Line*;
Line: (content+=Text | content+=Image) ;
Text: text=STRING;
Image: "img[" image=STRING "]";

The parser should be able distingushing between "text" and img[, but he
doesn't :-(

Sven
Re: xtext syntax question [message #713617 is a reply to message #713615] Mon, 08 August 2011 16:56 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Hi Sven,

the problem is the assignment in the rule Model combined with the
assignment in rule Element.

Please consider the following input:

img img

The parser does not know if you want to have a single element with two
lines or two Elements with one line each.
Your rule 'Element' needs a delimiter at the end to identify when it's
finished or you choose to only have one element in the model.

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 08.08.11 18:50, Sven Krause wrote:
> Hi,
>
> I'd like to create a rule having mix content of text and nested rules. a
> la:
>
> Model[
> text img text img text ...
> ]
>
> So I've tried combining them by optional elements. But the grammar
> parser always complains on multiple alternatives. How can I solve such
> issue?
>
> Here is a sample grammar:
>
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> Model: {Model} "Model";
> Element: {Element} content+=Line*;
> Line: (content+=Text | content+=Image) ;
> Text: text=STRING;
> Image: "img[" image=STRING "]";
>
> The parser should be able distingushing between "text" and img[, but he
> doesn't :-(
>
> Sven
Re: xtext syntax question [message #713831 is a reply to message #713617] Tue, 09 August 2011 06:55 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Sebastion,

got it:
The solution is adding extra wrapper types EContent and MixedContent
inbetween:

grammar org.xtext.example.mydsl.MyDsl with
org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model: {Model} "Model[" elements+=Element* "]";
Element: {Element} content+=EContent*;
EContent: content+=MixedContent;
MixedContent: (content+=Text | content+=Image );
Text: text=STRING;
Image: "img[" image=STRING "]";


by the way:
is there an difference between keyword expression delimited with " and ' ?

Sven
Re: xtext syntax question [message #713838 is a reply to message #713831] Tue, 09 August 2011 07:05 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Hi Sven,

I'm surprised. Your solution should suffer from the same problems as
your first approach, e.g. rule Element may match the empty input and the
parser cannot decide, how often it should descend into Element coming
from rule Model.

No, there is no difference between 'keyword' and "keyword".

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

On 09.08.11 08:55, Sven Krause wrote:
> Hi Sebastion,
>
> got it:
> The solution is adding extra wrapper types EContent and MixedContent
> inbetween:
>
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> Model: {Model} "Model[" elements+=Element* "]";
> Element: {Element} content+=EContent*;
> EContent: content+=MixedContent;
> MixedContent: (content+=Text | content+=Image );
> Text: text=STRING;
> Image: "img[" image=STRING "]";
>
>
> by the way:
> is there an difference between keyword expression delimited with " and ' ?
>
> Sven
Re: xtext syntax question [message #713891 is a reply to message #713838] Tue, 09 August 2011 10:07 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Am 09.08.2011 09:05, schrieb Sebastian Zarnekow:
> Hi Sven,
>
> I'm surprised. Your solution should suffer from the same problems as
> your first approach, e.g. rule Element may match the empty input and the
> parser cannot decide, how often it should descend into Element coming
> from rule Model.
>
> No, there is no difference between 'keyword' and "keyword".
>
> Regards,
> Sebastian

Ok Sebastian,

but what is the proposed syntax model for such a construct >"text"
something "text"< ?

Sven
Re: xtext syntax question [message #713992 is a reply to message #713891] Tue, 09 August 2011 13:36 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Hi Sven,

to begin with, you should either

a) allow only one element in your model rule between the brackets
or
b) make an element consist only of one MixedContent.

Both approaches will lead to a model that contains any number of
MixedContent instances but with a reduced complexity in the structure of
the model.

Does that make sense?

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


On 09.08.11 12:07, Sven Krause wrote:
> Am 09.08.2011 09:05, schrieb Sebastian Zarnekow:
>> Hi Sven,
>>
>> I'm surprised. Your solution should suffer from the same problems as
>> your first approach, e.g. rule Element may match the empty input and the
>> parser cannot decide, how often it should descend into Element coming
>> from rule Model.
>>
>> No, there is no difference between 'keyword' and "keyword".
>>
>> Regards,
>> Sebastian
>
> Ok Sebastian,
>
> but what is the proposed syntax model for such a construct >"text"
> something "text"< ?
>
> Sven
Previous Topic:scoping function is called too late when code completion is expected
Next Topic:Folding on EReferences
Goto Forum:
  


Current Time: Wed Apr 14 08:05:03 GMT 2021

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

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

Back to the top