Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Replacing STRING terminal/skip inserting closing terminal
Replacing STRING terminal/skip inserting closing terminal [message #1386648] Thu, 19 June 2014 05:59 Go to next message
dan jatnieks is currently offline dan jatnieksFriend
Messages: 8
Registered: July 2009
Junior Member
In a simple DSL example that uses the STRING terminal defined in Terminals, there is a nice feature that skips the closing terminal, e.g. typing

" => "" // two quotes and the cursor in between
a => "a"
b => "ab"
c => "abc"
" => "abc" // the closing quote is not inserted

In my DSL we aren't using STRING. Instead we have defined two terminals, one for single quoted strings and one for double quoted strings, SINGLE_STRING and DOUBLE_STRING.

The problem is that we have lost the nice closing terminal skipping feature - using the same example as above, the result is instead:

"abc"""

If I name one of my terminal rules STRING then I get the closing terminal skipping behavior for that rule, but not for the other. It seems that the terminal name STRING is treated special?

I've looked into extending DefaultAutoEditStrategyProvider and PartitionEndSkippingEditStrategy as they seem related/involved, but haven't come up with a solution.

Is there a way to do this?

Thanks!
dan
Re: Replacing STRING terminal/skip inserting closing terminal [message #1386662 is a reply to message #1386648] Thu, 19 June 2014 09:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it looks you have already found 99% of the code. the only part there the STRING rule is involved is

acceptor.accept(partitionEndSkippingEditStrategy.get(),TerminalsTokenTypeToPartitionMapper.STRING_LITERAL_PARTITION);


if we have a look at TerminalsTokenTypeToPartitionMapper we see

@Override
	protected String calculateId(String tokenName, int tokenType) {
		if ("RULE_ML_COMMENT".equals(tokenName)) {
			return COMMENT_PARTITION;
		} else if ("RULE_SL_COMMENT".equals(tokenName)) {
			return SL_COMMENT_PARTITION;
		} else if ("RULE_STRING".equals(tokenName)) {
			return STRING_LITERAL_PARTITION;
		}
		return IDocument.DEFAULT_CONTENT_TYPE;
	}


so the only place to customize is TerminalsTokenTypeToPartitionMapper and its clear what todo


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Replacing STRING terminal/skip inserting closing terminal [message #1386717 is a reply to message #1386662] Thu, 19 June 2014 19:29 Go to previous message
dan jatnieks is currently offline dan jatnieksFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,

Ok, I see - I extended TerminalsTokenTypeToPartitionMapper to override calculateId to additionally check for my RULE_SINGLE_STRING and RULE_DOUBLE_STRING returning STRING_LITERAL_PARITION.

The only piece left that gave me some trouble was to know where to bind my MyTerminalsTokenTypeToParitionMapper ... I ended up using this in class MyDSLUiModule:
	public Class<? extends TerminalsTokenTypeToPartitionMapper> bindTerminalsTokenTypeToPartitionMapper() {
		return MyDSLTerminalsTokenTypeToPartitionMapper.class ;
	}

	@Override
	  public Class<? extends AbstractEditStrategyProvider> bindAbstractEditStrategyProvider() {
	    return MyDSLAutoEditStrategyProvider.class;
	  }


Good news is that it's working - thanks Christian!
Previous Topic:Adding function calls to DSL syntax
Next Topic:Implementing createChildren
Goto Forum:
  


Current Time: Thu Apr 25 21:42:02 GMT 2024

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

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

Back to the top