Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » INT terminal rule for negative values
INT terminal rule for negative values [message #907988] Tue, 04 September 2012 14:00 Go to next message
Robert Wild is currently offline Robert WildFriend
Messages: 33
Registered: August 2012
Member
Hi,

is there a way to use negative values with the builtin terminal rule 'INT'? It only seems to accept numbers without a leading minus.

I can build something like this:
SignedInt:
	sign=('-')? value=INT
;

But this does not behave very intuitively in ContentAssist, and the sign has to be parsed manually.

So, is there a better way to do that?

Re: INT terminal rule for negative values [message #908859 is a reply to message #907988] Thu, 06 September 2012 06:09 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

this is what datatype rules are for.

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

look at the Terminals grammar as you will have to import the Ecore for referencing the return type.

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: INT terminal rule for negative values [message #909036 is a reply to message #908859] Thu, 06 September 2012 12:52 Go to previous message
Robert Wild is currently offline Robert WildFriend
Messages: 33
Registered: August 2012
Member
That works fine. Thank you.

To get the contentAssist to propose something one needs to add this to ProposalProvider:
	public void complete_SignedInt(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		complete_INT(model, ruleCall, context, acceptor);
	}
Previous Topic:headless xtext plugins
Next Topic:Inject issue with Eclipse Juno
Goto Forum:
  


Current Time: Thu Nov 26 18:59:59 GMT 2020

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

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

Back to the top