Skip to main content



      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 09:53 Go to next message
Eclipse UserFriend
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 15:01 Go to previous messageGo to next message
Eclipse UserFriend
You better allow the _ in the terminal rule and do a check + a quickfix for the value.

[Updated on: Mon, 15 June 2015 15:03] by Moderator

Re: quick fix for terminal rules in xtext [message #1698467 is a reply to message #1698453] Mon, 15 June 2015 15:44 Go to previous messageGo to next message
Eclipse UserFriend
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;
	}
	
}
Re: quick fix for terminal rules in xtext [message #1698561 is a reply to message #1698467] Tue, 16 June 2015 08:26 Go to previous messageGo to next message
Eclipse UserFriend
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 08:28 Go to previous messageGo to next message
Eclipse UserFriend
have a look for sem. highlighting
Re: quick fix for terminal rules in xtext [message #1698565 is a reply to message #1698563] Tue, 16 June 2015 08:47 Go to previous message
Eclipse UserFriend
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: Thu Jul 10 04:42:15 EDT 2025

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

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

Back to the top