Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Auto edit for multi line comments
Auto edit for multi line comments [message #694615] Sat, 09 July 2011 01:37 Go to next message
Dénes Harmath is currently offline Dénes HarmathFriend
Messages: 157
Registered: July 2009
Senior Member
Hi all,

unfortunately my grammar's comment terminal rules look like this:
terminal SL_COMMENT: "%" !("\n" | "\r")* ("\r"? "\n")?;

terminal ML_COMMENT: "%{" -> "%}";

so they have a common prefix. I think this causes the following problem:
Here's my auto edit strategy provider:
	private static void accept(IEditStrategyAcceptor acceptor, IAutoEditStrategy strategy) {
		acceptor.accept(strategy, IDocument.DEFAULT_CONTENT_TYPE);
		acceptor.accept(strategy, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
		acceptor.accept(strategy, TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION);
	}

	public static final String[][] BLOCK_KEYWORD_PAIRS = { { "{", "}" }, //$NON-NLS-1$ //$NON-NLS-2$
		{ "%{", "%}" }, //$NON-NLS-1$ //$NON-NLS-2$
		{ "<<", ">>" } }; //$NON-NLS-1$ //$NON-NLS-2$

	@Override
	protected void configure(IEditStrategyAcceptor acceptor) {
		accept(acceptor, defaultIndentLineAutoEditStrategy.get());
		for (String[] blockKeywordPair : BLOCK_KEYWORD_PAIRS) {
			accept(acceptor, singleLineTerminals.newInstance(blockKeywordPair[0], blockKeywordPair[1]));
			accept(acceptor, multiLineTerminals.newInstance(blockKeywordPair[0], null, blockKeywordPair[1]));
		}
		final String[][] brackets = new String[][] { { "[", "]" }, //$NON-NLS-1$ //$NON-NLS-2$
			{ "\\(", "\\)" }, //$NON-NLS-1$ //$NON-NLS-2$
			{ "(", ")" } }; //$NON-NLS-1$ //$NON-NLS-2$
		for (String[] blockKeywordPair : brackets) {
			accept(acceptor, singleLineTerminals.newInstance(blockKeywordPair[0], blockKeywordPair[1]));
		}
		accept(acceptor, partitionInsert.newInstance("\"", "\"")); //$NON-NLS-1$ //$NON-NLS-2$
	}


Unfortunately, when I type %{, only } is inserted, not %}. How can I circumvent this?

Thanks in advance,
thSoft
Re: Auto edit for multi line comments [message #694661 is a reply to message #694615] Sat, 09 July 2011 06:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what about simple changing the precedence (order) of the stuff in the BLOCK_KEYWORD_PAIRS array.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto edit for multi line comments [message #694808 is a reply to message #694661] Sat, 09 July 2011 20:53 Go to previous message
Dénes Harmath is currently offline Dénes HarmathFriend
Messages: 157
Registered: July 2009
Senior Member
Hmm, this solved it, but strangely only if the document is not empty. I'll file a bug. Thanks!
Previous Topic:Cannot find meta model when reusing parts of XBase
Next Topic:Toggle "Link with editor" in Outline
Goto Forum:
  


Current Time: Fri Apr 19 12:42:42 GMT 2024

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

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

Back to the top