SyntaxErrorMessageProvider custom implementation [message #1770757] |
Wed, 16 August 2017 20:15 |
Udeshika Sewwandi Messages: 118 Registered: March 2017 |
Senior Member |
|
|
Hi,
I want to customize the syntax error messages provided by the framework. So I tried extending SyntaxErrorMessageProvider class in order to give an error for user defined terms as follows.
public class MyDslErrorMessageProvider extends SyntaxErrorMessageProvider {
@Override
public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
//SyntaxErrorMessage syntaxError1=new SyntaxErrorMessage("Name should start with a letter", IssueCodes.AMBIGUOUS_FEATURE_CALL);
if(context.getRecognitionException() instanceof RecognitionException){
return new SyntaxErrorMessage("Name should start with a letter", IssueCodes.AMBIGUOUS_FEATURE_CALL);
}
return super.getSyntaxErrorMessage(context);
}
@Override
public SyntaxErrorMessage getSyntaxErrorMessage(IValueConverterErrorContext context) {
// TODO Auto-generated method stub
return null;
}
}
But when I run this message is shown at all errorneous places in the editor. How can I show the message only in needed places?
Thank you.
[Updated on: Wed, 16 August 2017 20:17] Report message to a moderator
|
|
|
|
|
Re: SyntaxErrorMessageProvider custom implementation [message #1770867 is a reply to message #1770859] |
Fri, 18 August 2017 06:01 |
|
Hi,
i do not understand nor can reproduce.
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
import com.google.inject.Inject
import org.antlr.runtime.RecognitionException
import org.eclipse.xtext.GrammarUtil
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage
import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider
import org.xtext.example.mydsl2.services.MyDslGrammarAccess
class MyDslErrorMessageProvider extends SyntaxErrorMessageProvider {
@Inject MyDslGrammarAccess ga
override SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
if (context.getRecognitionException() instanceof RecognitionException) {
val unexpectedText = context?.recognitionException?.token?.text
if (GrammarUtil::getAllKeywords(ga.grammar).contains(unexpectedText)) {
return new SyntaxErrorMessage('''"«unexpectedText»" is a reserved keyword which is not allowed as Identifier.''',
"bääääääh")
}
}
return super.getSyntaxErrorMessage(context)
}
override SyntaxErrorMessage getSyntaxErrorMessage(IValueConverterErrorContext context) {
// TODO Auto-generated method stub
return null
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Re: SyntaxErrorMessageProvider custom implementation [message #1771107 is a reply to message #1770916] |
Tue, 22 August 2017 05:02 |
Udeshika Sewwandi Messages: 118 Registered: March 2017 |
Senior Member |
|
|
Hi,
In my grammar the rule that initially runs is like,
Model:
a*((=>b|=>c|=>d)=>(';'(=>b|=>c|=>d))*=>(';' e ';'?))
;
When the rule is in this format, all the errors that are relevant to a particular model are shown at the beginning of the line as I mentioned earlier. But when there are no alternatives and the rule is like,
Model:
a*((b)=>(';'(b))*=>(';' e ';'?))
;
Errors are shown in the expected way. Is this thing happening due to the predicates that are used or due to alternatives?
Thank you.
[Updated on: Tue, 22 August 2017 05:13] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03597 seconds