Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Automatic Validation ( NoViableAltException)
Automatic Validation ( NoViableAltException) [message #1016371] Wed, 06 March 2013 09:33 Go to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi all,

I can't understand NoViableAltException .Which situations getting this error.

Default error message for this exception :no viable alternative at input 'datatype'

Best Regards
Re: Automatic Validation ( NoViableAltException) [message #1016487 is a reply to message #1016371] Wed, 06 March 2013 16:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this comes from antlr. here is what the antlr4 (xtext uses antlr 3) javadoc says
Indicates that the parser could not decide which of two or more paths to take based upon the remaining input. It tracks the starting token of the offending input and also knows where the parser was in the various paths when the error. 


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Automatic Validation ( NoViableAltException) [message #1016544 is a reply to message #1016371] Wed, 06 March 2013 20:35 Go to previous messageGo to next message
junior developer is currently offline junior developerFriend
Messages: 354
Registered: January 2013
Senior Member
Hi Christian,


My validation code for this error:
public class MyDsl1SyntaxErrorMessageProvider extends
SyntaxErrorMessageProvider {

@Override
public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {

if (context.getRecognitionException() != null
&& context.getRecognitionException().token != null) {
//for no viable alternative at input 'datatype' error
if (context.getRecognitionException() instanceof NoViableAltException ){
return new SyntaxErrorMessage("?????you must enter string??????? ", null);
}
}
return super.getSyntaxErrorMessage(context);
}
Defined rule my grammar :
Model:
(datatype += DataType)*
&(type += Type)*

DataType returns DataType:
'datatype' name=ID
;
Test1 DSL output :
datatype 3 // if I enter a integer value ,I receive "no viable alternative at input '3'" default error (I changed it own message)
datatype String
datatype int

Test2 DSL output: this In this scenario ,call datatype 6 but I do not an error hence I receive error only datatype 3 .I do not understand why ?

datatype 3 // if I enter a integer value ,I receive "no viable alternative at input '3'" default error (I changed it own message)

datatype 6 //I must receive same error ("you must enter string")this section but ı only receive error first line

datatype int


I hope explain my problem

Best regards
Re: Automatic Validation ( NoViableAltException) [message #1016551 is a reply to message #1016544] Wed, 06 March 2013 21:09 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
guess you have to look into the IParserErrorContext to see where you are
as said before in the other topic: your question and needs are very specific so
you may have to digg yourself (e.g. using debugger)
to find a solution since it is not a general problem.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Strange behavior of INT
Next Topic:Another cross-referencing question
Goto Forum:
  


Current Time: Fri Apr 19 07:00:03 GMT 2024

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

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

Back to the top