Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Extend Terminal Rule
Extend Terminal Rule [message #1102297] Thu, 05 September 2013 16:02 Go to next message
Björn Rellesch is currently offline Björn RelleschFriend
Messages: 38
Registered: January 2013
Member
Hello,

I want to extend the terminal-rule "ID", in order that a "-" is allowed in the names of an element.

How can I simply use "terminal ID = ID & '-'" in my DSL?

Example:
process Create-Contract {
...
}

Greets Björn
Re: Extend Terminal Rule [message #1102420 is a reply to message #1102297] Thu, 05 September 2013 18:52 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
Hi,

i guess you have to copy and paste override it.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Extend Terminal Rule [message #1103111 is a reply to message #1102420] Fri, 06 September 2013 11:41 Go to previous messageGo to next message
Björn Rellesch is currently offline Björn RelleschFriend
Messages: 38
Registered: January 2013
Member
Hi,

if I do so, I lose the auto-completion functionality, if I have to define e. g. the name of an element. Due to this fact the method complete_ID() in the class TerminalsProposalProvider isn't called when I override the Terminal ID in the grammar.

Is there any other possibility?

Greets Björn
Re: Extend Terminal Rule [message #1103116 is a reply to message #1103111] Fri, 06 September 2013 11:46 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
No but you can adapt the proposal provider as well

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Extend Terminal Rule [message #1103140 is a reply to message #1103116] Fri, 06 September 2013 12:18 Go to previous messageGo to next message
Björn Rellesch is currently offline Björn RelleschFriend
Messages: 38
Registered: January 2013
Member
Ok, I can do so.
But why is the standard proposal provider not invoked?
How can I ensure, that other funktinalities will work correct, which are not as obvious as auto-completion, whe I override the Terminal ID (e. g. if we want to add a label provider or we want to use grammar-mixing in e. g. two years)?
Re: Extend Terminal Rule [message #1103181 is a reply to message #1103140] Fri, 06 September 2013 13:07 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
HI,

i am not quite sure if we are talking about the same:

from AbstractMyDslProposalProvider

	public void complete_ID(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// subclasses may override
	}


from TerminalsProposalProvider

public void complete_ID(EObject model, RuleCall ruleCall, final ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		if (doCreateIdProposals()) {
			PrefixMatcher newMatcher = new PrefixMatcher() {
				@Override
				public boolean isCandidateMatchingPrefix(String name, String prefix) {
					String strippedName = name;
					if (name.startsWith("^") && !prefix.startsWith("^")) {
						strippedName = name.substring(1);
					}
					return context.getMatcher().isCandidateMatchingPrefix(strippedName, prefix);
				}
			};
			ContentAssistContext myContext = context.copy().setMatcher(newMatcher).toContext();
			String feature = getAssignedFeature(ruleCall);
			String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
			String displayText = proposalText;
			if (feature != null)
				displayText = proposalText + " - " + ruleCall.getRule().getName();
			proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
			ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, myContext);
			if (proposal instanceof ConfigurableCompletionProposal) {
				ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
				configurable.setSelectionStart(configurable.getReplacementOffset());
				configurable.setSelectionLength(proposalText.length());
				configurable.setAutoInsertable(false);
				configurable.setSimpleLinkedMode(myContext.getViewer(), '\t', ' ');
			}
			acceptor.accept(proposal);
		}
	}


if you override id xtext cannot know if using this code is still sufficient or not.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Get the value of a reference from Value Converter
Next Topic:Why posts are not displaying immediately on this forum?
Goto Forum:
  


Current Time: Fri Apr 26 19:18:23 GMT 2024

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

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

Back to the top