Home » Modeling » TMF (Xtext) » Content assist for keywords and terminals
Content assist for keywords and terminals [message #696957] |
Fri, 15 July 2011 08:09 |
Mirko Raner Messages: 125 Registered: July 2009 Location: New York City, NY |
Senior 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 #696972 is a reply to message #696957] |
Fri, 15 July 2011 08:28 |
Sebastian Zarnekow Messages: 3118 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 |
Mirko Raner Messages: 125 Registered: July 2009 Location: New York City, NY |
Senior 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
|
|
|
Goto Forum:
Current Time: Thu Sep 26 06:27:05 GMT 2024
Powered by FUDForum. Page generated in 0.04267 seconds
|