Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » quick fix for terminal rules in xtext(terminal rule quickfixes)
quick fix for terminal rules in xtext [message #1698130] Thu, 11 June 2015 13:53 Go to next message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
my DSL grammer look like (only necessary part is displayed )

  assemblerProgram: // standard way of defining model
	content += CommandLine+
    ;

    CommandLine: 
	ControlInstructions | Pointaddress ;

    Pointaddress:
	name = POINTINGADD

    terminal POINTINGADD:('_')('a'..'z'|'A'..'Z')? ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;

where POINTINGADD is a terminal rule which say that name should starts with "_".

Now I want to implement a quick fix for this terminal rule. is it possible? and which way should I go?

thanks in advance.

Re: quick fix for terminal rules in xtext [message #1698453 is a reply to message #1698130] Mon, 15 June 2015 19:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
You better allow the _ in the terminal rule and do a check + a quickfix for the value.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 15 June 2015 19:03]

Report message to a moderator

Re: quick fix for terminal rules in xtext [message #1698467 is a reply to message #1698453] Mon, 15 June 2015 19:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
p.s. you could use a SyntaxErrorMessageProvider to create the code necessary for the quickfix, but depending on the situation it may be pita to find out that you are in the quickfix situation

public class MyDslSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {

	public static final String YOUR_ERROR_CODE = "YOUR_ERROR_CODE";
	
	@Override
	public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
		if (/* find out */) {
			return new SyntaxErrorMessage(context.getDefaultMessage(), YOUR_ERROR_CODE);
		}
		SyntaxErrorMessage syntaxErrorMessage = super.getSyntaxErrorMessage(context);
	
		return syntaxErrorMessage;
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: quick fix for terminal rules in xtext [message #1698561 is a reply to message #1698467] Tue, 16 June 2015 12:26 Go to previous messageGo to next message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
Thanks Christian, I have followed your first Approach. First I used terminal rule ID (which is not strict about '_') and then in MyDslValidator i performed a check and throwing an error if not starting with '_'. then I am performing quickfix on it. The error and quick fix are working, but now the problem is custom coloring. Initially when I was using a terminal rule, I used the following AntlrTokenToAttributeIdMapper code for custom coloring:

import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultAntlrTokenToAttributeIdMapper;

public class AntlrTokenToAttributeIdMapper extends DefaultAntlrTokenToAttributeIdMapper {
@Override
protected String calculateId(String tokenName, int tokenType) {
if(tokenName.equals("RULE_POINTINGADD")){
return SmcHighlightingConfiguration.POINTINGADDRESS_ID;
}
return super.calculateId(tokenName, tokenType);
}
}


*where POINTINGADDRESS_ID is defined in SmcHighlightingConfiguration.
But now I am not sure how to give the custom color to it. Because it is no more a terminal rule.
Re: quick fix for terminal rules in xtext [message #1698563 is a reply to message #1698561] Tue, 16 June 2015 12:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
have a look for sem. highlighting

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: quick fix for terminal rules in xtext [message #1698565 is a reply to message #1698563] Tue, 16 June 2015 12:47 Go to previous message
Mohsin waqas is currently offline Mohsin waqasFriend
Messages: 33
Registered: June 2015
Member
I have applied sem.highlighting concept and its working now. I have applied HighlightingCalculator and its working. Thanks Smile
In cross-referencing it (custom coloring) is not working but otherwise its working.
Previous Topic:Saving DSL script triggers the application main program.
Next Topic:Constraints on Xbase
Goto Forum:
  


Current Time: Tue Mar 19 04:27:54 GMT 2024

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

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

Back to the top