Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Content assist for keywords and terminals
icon5.gif  Content assist for keywords and terminals [message #696957] Fri, 15 July 2011 08:09 Go to next message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 98
Registered: July 2009
Location: New York City, NY
Member
Hi there,

I'm working with Xtext for almost 2 years now, but I still come across surprises every once in a while...

I have a simple Xtext 2.0 grammar for creating rhymes like "one fish two fish red fish blue fish":
grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
generate fish "http://raner.ws/xtext/Fish"
Fish: fish+=QualifiedFish+;
QualifiedFish: qualifier=Qualifier 'fish';
Qualifier: ONE|TWO|RED|BLUE;
terminal ONE: 'one';
terminal TWO: 'two';
terminal RED: 'red';
terminal BLUE: 'blue';
The editor only gives me content assist AFTER a 'one', 'two', 'red', or 'blue', i.e. it offers the completion 'fish'. I do not get any content assist at the beginning of a QualifiedFish rule; when pressing Ctrl+Space in an empty file, I would expect to be given a choice of one, two, red, blue, but nothing comes up.
I also tried a variation that uses no terminals, which displays the same behavior:
grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
generate fish "http://raner.ws/xtext/Fish"
Fish: fish+=QualifiedFish+;
QualifiedFish: qualifier=Qualifier 'fish';
Qualifier: 'one'|'two'|'red'|'blue';
The only way I can get full content assist is by using an enum rule:
grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
generate fish "http://raner.ws/xtext/Fish"
Fish: fish+=QualifiedFish+;
QualifiedFish: qualifier=Qualifier 'fish';
enum Qualifier: one|two|red|blue;
Is there no content assist for the first two grammars because essentially Qualifier is a data type rule and there is no actual Qualifier EClass? I'd appreciate it if someone could explain this in a few words... intuitively, I would expect content assist to work in all three variations of the grammar.
Also, I'd like to know if the choice of inline keywords versus proper terminals plays any role for the content assist (apparently it does not, but are there any rules of thumb when to use terminal rules and when to just inline keywords?)

Thanks,

Mirko

Re: Content assist for keywords and terminals [message #696965 is a reply to message #696957] Fri, 15 July 2011 08:21 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

there is no out of the box support for datatype rules. You may be wondering why not as in your case there are only 4 distict cases. But what about very complicated datatype rules with lots of optionality, multiplicity, calls to other datatype rules etc.
Rather than possibly proposing nonsense, Xtext does not propose anything. Of course you are free to implement your own proposals. In your case you might want to inject the grammar access into the proposal provider in order to automatically pick up new alternatives of your qualifier rule.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Content assist for keywords and terminals [message #696970 is a reply to message #696965] Fri, 15 July 2011 08:26 Go to previous messageGo to next message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 98
Registered: July 2009
Location: New York City, NY
Member
Okay, so it is indeed because of the data type rule... Thanks for clarifying that!
Re: Content assist for keywords and terminals [message #696972 is a reply to message #696957] Fri, 15 July 2011 08:28 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hi Mirko,

what you describe looks similar to these requests:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=315624
https://bugs.eclipse.org/bugs/show_bug.cgi?id=309303

You may want to add your example there.

A rule of thumb is: If it's a keyword (and you'd expect it to look like
a keyword (purple) in the editor), use a keyword.

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

On 15.07.11 10:09, Mirko Raner wrote:
> Hi there,
>
> I'm working with Xtext for almost 2 years now, but I still come across
> surprises every once in a while...
>
> I have a simple Xtext 2.0 grammar for creating rhymes like "one fish two
> fish red fish blue fish":
>
> grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
> generate fish "http://raner.ws/xtext/Fish"
> Fish: fish+=QualifiedFish+;
> QualifiedFish: qualifier=Qualifier 'fish';
> Qualifier: ONE|TWO|RED|BLUE;
> terminal ONE: 'one';
> terminal TWO: 'two';
> terminal RED: 'red';
> terminal BLUE: 'blue';
> The editor only gives me content assist AFTER a 'one', 'two', 'red', or
> 'blue', i.e. it offers the completion 'fish'. I do not get any content
> assist at the beginning of a QualifiedFish rule; when pressing
> Ctrl+Space in an empty file, I would expect to be given a choice of one,
> two, red, blue, but nothing comes up.
> I also tried a variation that uses no terminals, which displays the same
> behavior:
>
> grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
> generate fish "http://raner.ws/xtext/Fish"
> Fish: fish+=QualifiedFish+;
> QualifiedFish: qualifier=Qualifier 'fish';
> Qualifier: 'one'|'two'|'red'|'blue';
> The only way I can get full content assist is by using an enum rule:
>
> grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
> generate fish "http://raner.ws/xtext/Fish"
> Fish: fish+=QualifiedFish+;
> QualifiedFish: qualifier=Qualifier 'fish';
> enum Qualifier: one|two|red|blue;
> Is there no content assist for the first two grammars because
> essentially Qualifier is a data type rule and there is no actual
> Qualifier EClass? I'd appreciate it if someone could explain this in a
> few words... intuitively, I would expect content assist to work in all
> three variations of the grammar.
> Also, I'd like to know if the choice of inline keywords versus proper
> terminals plays any role for the content assist (apparently it does not,
> but are there any rules of thumb when to use terminal rules and when to
> just inline keywords?)
>
> Thanks,
>
> Mirko
>
>
Re: Content assist for keywords and terminals [message #697803 is a reply to message #696972] Mon, 18 July 2011 05:08 Go to previous message
Mirko Raner is currently offline Mirko RanerFriend
Messages: 98
Registered: July 2009
Location: New York City, NY
Member
Thanks for the pointers, Sebastian.

I think there are two overlapping issues here. Bug 315624 talks about terminal rules (i.e., lexer rules), whereas bug 309303 talks about data type rules (i.e., parser rules). Unfortunately, the example given in bug 315624 actually demonstrates the problem of bug 309303 rather than that of 315624. So, it's a bad choice of example, but I don't see 315624 as a duplicate of 309303.
Using yet two more variations of the fish example from earlier, I get no content assist on "I" and "like" with this grammar:
grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
generate fish "http://raner.ws/xtext/Fish"
Fish: I LIKE fish=QualifiedFish;
QualifiedFish: qualifier=Qualifier 'fish';
enum Qualifier: one|two|red|blue;
terminal I: 'I';
terminal LIKE: 'like';
However, when I replace the terminals I and LIKE by keywords the content assist actually works:
grammar ws.raner.xtext.Fish with org.eclipse.xtext.common.Terminals
generate fish "http://raner.ws/xtext/Fish"
Fish: 'I' 'like' fish=QualifiedFish;
QualifiedFish: qualifier=Qualifier 'fish';
enum Qualifier: one|two|red|blue;
I think this is what the original poster for bug 315624 actually meant. As you pointed out, it makes not much sense to construct synthetic proposals for rules like ID or SL_COMMENT, but simple terminal rules that are equivalent to keywords should probably be treated like keywords for the purpose of content assist.

I'll add my comments to those two bugs as well.

Thanks,

Mirko

Previous Topic:(no subject)
Next Topic:Nomenclature question about Parser Rules
Goto Forum:
  


Current Time: Wed Sep 30 10:35:49 GMT 2020

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

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

Back to the top