Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can Ecore::EString be used in XText?
Can Ecore::EString be used in XText? [message #1834708] Mon, 16 November 2020 16:39 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi guys,

I have generated an XText grammar from an ecore model and the grammar that I got is the following:

grammar org.xtext.example.mydsl16.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl16/MyDsl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

WorldMap returns WorldMap:
	'WorldMap'
	'{'
		'WorldMap' WorldMap=EString
		'countrycorona'  countrycorona+=CountryCorona ( "," countrycorona+=CountryCorona)*  
	'}';


CountryCorona returns CountryCorona:
	'CountryCorona'
	'{'
		'CountryCorona' CountryCorona=EString
		'population' population=EInt
		'continent' continent=EString
		'infectedPopulation' infectedPopulation=EInt
		'zonelabel' zonelabel=zonelabelcolour
	
	'}';

EString returns ecore::EString:
	STRING | ID;

EInt returns ecore::EInt:
	'-'? INT;

enum zonelabelcolour returns zonelabelcolour:
				red = 'red' | orange = 'orange' | yellow = 'yellow' | green = 'green' | white = 'white'; 


My issue is that when I try write a model for this grammar, I usually use CTRL Space, to get the suggestion for the following token. However after I write WorldMap { WorldMap, I get

no viable alternative at input '<EOF>'

Furthermore, I do not get a suggestion that the next token should be an EString. Refering to XText documentation I should be able to use this EString, but apparently I can't. Do you know what might be the issue?

Thank you!
Re: Can Ecore::EString be used in XText? [message #1834710 is a reply to message #1834708] Mon, 16 November 2020 16:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
if you have a datatype rule (in your case EString), you have to override and implement
the corresponding complete_XXXX method yourself inside YourDslProposalProvider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can Ecore::EString be used in XText? [message #1834711 is a reply to message #1834710] Mon, 16 November 2020 16:51 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Christian,

Thank you for your answer! Could you be a bit more specific on the steps that I should follow to do that?

I thought that adding

EString returns ecore::EString:
	STRING | ID;



would be enough
Re: Can Ecore::EString be used in XText? [message #1834712 is a reply to message #1834711] Mon, 16 November 2020 17:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
grammar != content assist

so implement complete_EString
and create the proposals you want to have

public class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	@Override
	public void complete_EString(EObject model, RuleCall ruleCall, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		acceptor.accept(createCompletionProposal("NiceID", context));
		acceptor.accept(createCompletionProposal("\"NiceString\"", context));
	}
}





Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can Ecore::EString be used in XText? [message #1834715 is a reply to message #1834712] Mon, 16 November 2020 18:14 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
When I try it, I get this error

Multiple markers at this line
	- ContentAssistContext cannot be resolved to a 
	 type
	- RuleCall cannot be resolved to a type
	- EObject cannot be resolved to a type
Re: Can Ecore::EString be used in XText? [message #1834716 is a reply to message #1834715] Mon, 16 November 2020 18:21 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Managed to fix it, thanks!
Re: Can Ecore::EString be used in XText? [message #1834720 is a reply to message #1834716] Mon, 16 November 2020 19:18 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You should not rely on Completion Assist. It can be very useful, but most tools try to prioritize good suggestions over a ridiculous volume of suggestions. Unfortunately if your prevailing text has typos that point the tool in the 'wrong' direction, you will get 'wrong' suggestions. Also the completion coding often involves manual contributions that are hard to debug thoroughly, so you often encounter bugs, particularly where incremental update is needed to accommodate changes in referenced resources.

Regards

Ed Willink
Previous Topic:Automatically generate XText grammar from UML Profile in Papyrus
Next Topic:TemplateProposalProvider for webapplication
Goto Forum:
  


Current Time: Thu Mar 28 13:14:39 GMT 2024

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

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

Back to the top