Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Complete keyword with lookahead
Complete keyword with lookahead [message #828096] Sat, 24 March 2012 07:23 Go to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
Hi!

If one of the next grammar elements of a content assist context is a special keyword how can I propose at this context what follows after the keyword (without hacking the grammar with a special datatype)? For example, if the grammar snippet looks like
IndexedType: "[" ind=[Index] "]"

where "[" is keyword, I want to show up at the context offset before "[" not only the keyword "[", but also the whole completion rule, like "[i]" as a proposal. The problem is, that the complete* and complete_* rules are not called at at context of a keyword, which has no feature assigned to it.
The easiest way would be to override completeKeyword and call completeIndexedType_Ind which itself needs a non-null Assignment object, and I don't know where to get it from. Is there a better method to concatenate following proposals?

Best regards,
Alex.
Re: Complete keyword with lookahead [message #828103 is a reply to message #828096] Sat, 24 March 2012 07:42 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

one option is to provide a template proposal for that. You can try them out using the Xtext editor's preference page, export them and provide them along with the editor.
This is is covered in the documentation as well as some blog posts.

Alex
Re: Complete keyword with lookahead [message #828125 is a reply to message #828103] Sat, 24 March 2012 08:30 Go to previous messageGo to next message
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012
Member
A template is a nice idea, thank you for the hint. But I don't think its the correct feature for me in this context. I want to look at the token "[i]" as a whole name and not providing a template of the form "'[' ... ']'".
Sure I can write a grammar like
IndexedType: ind=[Index | PrefixedID] "]"
PrefixedID: "[" ID;

and change the corresponding qualified name in order to use default XText features. But that's a sort of hack in the grammar.

So far I have overwritten completeKeyword which itself doesn't call lookUpCrossReferences but imitates this by manually calling the scope provider for objects of type Index. After that I call ICompletionAcceptor with changed ICompletionProposals.
But somehow I think that this way is a sort of hacky as well, since I have to overwrite the completeKeyword method. Eventually there might be for this kind of proposals ("concatenation" of proposals with lookahead) some corresponding API methods, but I haven't found any of these, since when calling the proposal provider before a keyword, I think, the only complete method which is called is completeKeyword.

[Updated on: Sat, 24 March 2012 08:31]

Report message to a moderator

Re: Complete keyword with lookahead [message #828472 is a reply to message #828096] Sat, 24 March 2012 21:40 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3107
Registered: July 2009
Senior Member
Hi Alex,

you can obtain the assignment from the YourDslGrammarAccess.
Instead of completeKeyword I'd try to specialize the complete_IndexType
implementation.

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

Am 24.03.12 03:23, schrieb Alex G:
> Hi!
>
> If one of the next grammar elements of a content assist context is a
> special keyword how can I propose at this context what follows after the
> keyword (without hacking the grammar with a special datatype)? For
> example, if the grammar snippet looks like
>
> IndexedType: "[" ind=[Index] "]"
>
> where "[" is keyword, I want to show up at the context offset before "["
> not only the keyword "[", but also the whole completion rule, like "[i]"
> as a proposal. The problem is, that the complete* and complete_* rules
> are not called at at context of a keyword, which has no feature assigned
> to it.
> The easiest way would be to override completeKeyword and call
> completeIndexedType_Ind which itself needs a non-null Assignment object,
> and I don't know where to get it from. Is there a better method to
> concatenate following proposals?
>
> Best regards,
> Alex.
Previous Topic:Xtext, Xbase 2.3 - expressions with no side effects
Next Topic:alternative for opening external xtext files
Goto Forum:
  


Current Time: Mon Mar 30 20:03:34 GMT 2020

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

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

Back to the top