Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext grammar autocompletion
Xtext grammar autocompletion [message #1809343] Sat, 13 July 2019 18:03 Go to next message
TheEMF User is currently offline TheEMF UserFriend
Messages: 71
Registered: August 2018
Member
I have the following Xtext grammar :

ClassA :
	'object' name=ID  ('['declareNumberOfObjects=INT']')? ':' typeObjectA=TypeObjectA
;


ClassB :
	'object' name=ID ':' typeObjectB=TypeObjectB
;

ClassC :
	'object' name=ID ':' typeObjectC=TypeObjectC
;

TypeObjectA :
	objectAToInstantiate=[ObjectA] 'platform' targetedPlatform=('TYPE1'|'TYPE2')
;

TypeObjectB :
	objectBToInstantiate=[ObjectB] 'platform' targetedPlatform=('TYPE3'|'TYPE4')
;

TypeObjectC :
	objectCToInstantiate=[ObjectC] 'platform'  targetedPlatform=('TYPE5'|'TYPE6')
;



But I don't understand why when I arrive to the keyword 'platform' the autocompletion proposes me all TYPES (i.e TYPE1, TYPE2, TYPE3...etc) without taking into account the fact that I am in ClassA or ClassB or ClassC.

What I want is that if I am in ClassA the platform proposed would be TYPE1 or TYPE2 that's it, same for ClassB i.e TYPE3 or TYPE4...etc

Why this syntax does not achieve that and how can I achieve it ?

Regards

[Updated on: Sat, 13 July 2019 18:04]

Report message to a moderator

Re: Xtext grammar autocompletion [message #1809344 is a reply to message #1809343] Sat, 13 July 2019 18:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
i dont understand your grammar is ambigous besides the types

=> unless you type TYPE3 or TYPE5
the model texts in the front are the same.
objectAToInstantiate=[ObjectA]
is parsed as
objectAToInstantiate=ID

as well as
objectBToInstantiate=[ObjectB]
is parsed as
objectBToInstantiate=ID
=> you parse

object ID : ID platform

=> works as intended cause your grammar is bad

you can override completeXXxx in the proposal Provider
e.g. org.eclipse.xtext.ui.editor.contentassist.AbstractJavaBasedContentProposalProvider.completeKeyword(Keyword, ContentAssistContext, ICompletionProposalAcceptor)
but i have doubts you will be able to distinguish the cases from contentAsssitContext.currentModel etc in this case


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext grammar autocompletion [message #1809346 is a reply to message #1809344] Sat, 13 July 2019 18:41 Go to previous messageGo to next message
TheEMF User is currently offline TheEMF UserFriend
Messages: 71
Registered: August 2018
Member
Thanks for your reply.

I just want to specify in the grammar, when it is [ObjectA] the possibilities are ('TYPE1'|'TYPE2'), when it is [ObjectB] the possibilities are ('TYPE3'|'TYPE4')...Etc

What is the correct way to do that in the grammar ?

Thanks
Re: Xtext grammar autocompletion [message #1809347 is a reply to message #1809346] Sat, 13 July 2019 18:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
Not without changing the syntax. As I said you can try to fix content assist

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext grammar autocompletion [message #1809348 is a reply to message #1809346] Sat, 13 July 2019 19:01 Go to previous messageGo to next message
TheEMF User is currently offline TheEMF UserFriend
Messages: 71
Registered: August 2018
Member
I am ready to change the syntax I just want to know the possibilities I have
Re: Xtext grammar autocompletion [message #1809349 is a reply to message #1809348] Sat, 13 July 2019 19:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
As I said use a debugger and try if you can distinguish the cases from c9ntent assist context in complete keyword

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext grammar autocompletion [message #1809353 is a reply to message #1809349] Sat, 13 July 2019 22:42 Go to previous messageGo to next message
TheEMF User is currently offline TheEMF UserFriend
Messages: 71
Registered: August 2018
Member
I am trying to use content assist, however I can only accept what should I do to specify what to show in autocompletion

Here is the code :


override completeTypeObjectA_TargetedPlatform(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		super.completeTypePubSub_TargetedProtocol(model, assignment, context, acceptor)
		
		... // I don't know how to refuse a completion, I can only accept
	}



Could you please show how to do that ?
Re: Xtext grammar autocompletion [message #1809354 is a reply to message #1809353] Sun, 14 July 2019 06:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
Reading the code it would be obvious: don't call super if you want to refuse

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext grammar autocompletion [message #1809355 is a reply to message #1809354] Sun, 14 July 2019 10:58 Go to previous messageGo to next message
TheEMF User is currently offline TheEMF UserFriend
Messages: 71
Registered: August 2018
Member
I removed super and I still get the other proposals,
Re: Xtext grammar autocompletion [message #1809356 is a reply to message #1809355] Sun, 14 July 2019 11:32 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
Then please debug and see where it is coming from

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Creating Custom Task Tags
Next Topic:Suppress 'default' modifier on interface method?
Goto Forum:
  


Current Time: Tue Aug 20 16:45:39 GMT 2019

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

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

Back to the top