public override string ToString()
        {
            RecognitionException re = (RecognitionException)Cause;
            int line    = 0;
            int charPos = -1;

            if (_token != null)
            {
                line    = _token.Line;
                charPos = _token.CharPositionInLine;
                // check the input streams - if different then token is embedded in templateToken and we need to adjust the offset
                if (_templateToken != null && !_templateToken.InputStream.Equals(Token.InputStream))
                {
                    int templateDelimiterSize = 1;
                    if (_templateToken.Type == GroupParser.BIGSTRING || _templateToken.Type == GroupParser.BIGSTRING_NO_NL)
                    {
                        templateDelimiterSize = 2;
                    }

                    line    += _templateToken.Line - 1;
                    charPos += _templateToken.CharPositionInLine + templateDelimiterSize;
                }
            }

            string filepos = string.Format("{0}:{1}", line, charPos);

            if (_sourceName != null)
            {
                return(string.Format("{0} {1}: {2}", _sourceName, filepos, string.Format(Error.Message, Arg, Arg2)));
            }

            return(string.Format("{0}: {1}", filepos, string.Format(Error.Message, Arg, Arg2)));
        }
Esempio n. 2
0
 public override void ReportError( RecognitionException e )
 {
     string header = GetErrorHeader( e );
     string message = GetErrorMessage( e, TokenNames );
     message = string.Format( "{0}: {1}: {2}", "$...$ chunk lexer error", header, message );
     self.Error( message, e );
 }
 public GrammarSyntaxMessage( int msgID,
                             Grammar grammar,
                             IToken offendingToken,
                             RecognitionException exception )
     : this(msgID, grammar, offendingToken, null, exception)
 {
 }
Esempio n. 4
0
        public override string ToString()
        {
            RecognitionException re = (RecognitionException)Cause;
            int line    = re.Line;
            int charPos = re.CharPositionInLine;

            if (_templateToken != null)
            {
                int templateDelimiterSize = 1;
                if (_templateToken.Type == GroupParser.BIGSTRING)
                {
                    templateDelimiterSize = 2;
                }
                line    += _templateToken.Line - 1;
                charPos += _templateToken.CharPositionInLine + templateDelimiterSize;
            }

            string filepos = line + ":" + charPos;

            if (_sourceName != null)
            {
                return(_sourceName + " " + filepos + ": " + string.Format(Error.Message, _message));
            }

            return(filepos + ": " + string.Format(Error.Message, _message));
        }
Esempio n. 5
0
 public override void ReportError(Antlr.Runtime.RecognitionException e)
 {
     _errors.Add(new ErrorInfo
     {
         Text = GetErrorHeader(e) + " " + GetErrorMessage(e, TokenNames)
     });
 }
        public void TestNoWildcardAsRootError() /*throws Exception*/
        {
            ErrorQueue equeue = new ErrorQueue();

            ErrorManager.SetErrorListener(equeue);

            string treeGrammar =
                "tree grammar TP;\n" +
                "options {output=AST;}\n" +
                "a : ^(. INT) \n" +
                "  ;\n";

            Grammar   g     = new Grammar(treeGrammar);
            AntlrTool antlr = newTool();

            antlr.SetOutputDirectory(null);   // write to /dev/null
            CodeGenerator generator = new CodeGenerator(antlr, g, "Java");

            g.CodeGenerator = generator;
            generator.GenRecognizer();

            Assert.AreEqual(1, equeue.errors.Count, "unexpected errors: " + equeue);

            int    expectedMsgID                 = ErrorManager.MSG_WILDCARD_AS_ROOT;
            object expectedArg                   = null;
            RecognitionException expectedExc     = null;
            GrammarSyntaxMessage expectedMessage =
                new GrammarSyntaxMessage(expectedMsgID, g, null, expectedArg, expectedExc);

            checkError(equeue, expectedMessage);
        }
Esempio n. 7
0
 public GrammarSyntaxMessage(int msgID,
                             Grammar grammar,
                             IToken offendingToken,
                             RecognitionException exception)
     : this(msgID, grammar, offendingToken, null, exception)
 {
 }
Esempio n. 8
0
        public override string ToString()
        {
            RecognitionException re = (RecognitionException)Cause;
            int line    = 0;
            int charPos = -1;

            if (token != null)
            {
                line    = token.Line;
                charPos = token.CharPositionInLine;
                if (templateToken != null)
                {
                    int templateDelimiterSize = 1;
                    if (templateToken.Type == GroupParser.BIGSTRING)
                    {
                        templateDelimiterSize = 2;
                    }
                    line    += templateToken.Line - 1;
                    charPos += templateToken.CharPositionInLine + templateDelimiterSize;
                }
            }

            string filepos = string.Format("{0}:{1}", line, charPos);

            if (srcName != null)
            {
                return(string.Format("{0} {1}: {2}", srcName, filepos, string.Format(Error.Message, Arg, Arg2)));
            }

            return(string.Format("{0}: {1}", filepos, string.Format(Error.Message, Arg, Arg2)));
        }
Esempio n. 9
0
        public override string ToString()
        {
            RecognitionException re = (RecognitionException)Cause;
            int line    = 0;
            int charPos = -1;

            if (token != null)
            {
                line    = token.Line;
                charPos = token.CharPositionInLine;
            }
            else if (re != null)
            {
                line    = re.Line;
                charPos = re.CharPositionInLine;
            }

            string filepos = line + ":" + charPos;

            if (srcName != null)
            {
                return(srcName + " " + filepos + ": " + string.Format(Error.Message, Arg, Arg2));
            }

            return(filepos + ": " + string.Format(Error.Message, Arg, Arg2));
        }
Esempio n. 10
0
 public void RecognitionException(RecognitionException e)
 {
     for (int i = 0; i < listeners.Count; i++)
     {
         IDebugEventListener listener = (IDebugEventListener)listeners[i];
         listener.RecognitionException(e);
     }
 }
Esempio n. 11
0
        public override void ReportError(RecognitionException e)
        {
            string header  = GetErrorHeader(e);
            string message = GetErrorMessage(e, TokenNames);

            message = string.Format("{0}: {1}: {2}", "$...$ chunk lexer error", header, message);
            self.Error(message, e);
        }
Esempio n. 12
0
        public virtual void SyntaxError(ErrorType etype,
                                        string fileName,
                                        Antlr.Runtime.IToken token,
                                        Antlr.Runtime.RecognitionException antlrException,
                                        params object[] args)
        {
            ANTLRMessage msg = new GrammarSyntaxMessage(etype, fileName, token, antlrException, args);

            Emit(etype, msg);
        }
Esempio n. 13
0
        override public void RecognitionException(RecognitionException e)
        {
            if (backtracking > 0)
            {
                return;
            }
            ParseTree ruleNode  = (ParseTree)callStack.Peek();
            ParseTree errorNode = Create(e);

            ruleNode.AddChild(errorNode);
        }
Esempio n. 14
0
 public GrammarSyntaxMessage( int msgID,
                             Grammar grammar,
                             IToken offendingToken,
                             Object arg,
                             RecognitionException exception )
     : base(msgID, arg, null)
 {
     this.offendingToken = offendingToken;
     this.exception = exception;
     this.g = grammar;
 }
Esempio n. 15
0
 public GrammarSyntaxMessage(int msgID,
                             Grammar grammar,
                             IToken offendingToken,
                             Object arg,
                             RecognitionException exception)
     : base(msgID, arg, null)
 {
     this.offendingToken = offendingToken;
     this.exception      = exception;
     this.g = grammar;
 }
Esempio n. 16
0
 public static void SyntaxError(int msgID,
                                Grammar grammar,
                                IToken token,
                                Object arg,
                                RecognitionException re)
 {
     GetErrorState().errors++;
     GetErrorState().errorMsgIDs.Add(msgID);
     GetErrorListener().Error(
         new GrammarSyntaxMessage(msgID, grammar, token, arg, re)
         );
 }
Esempio n. 17
0
 public override void ReportError( RecognitionException e )
 {
     StringTemplateGroup group = self.Group;
     if ( group == StringTemplate.defaultGroup )
     {
         self.Error( "template parse error; template context is " + self.GetEnclosingInstanceStackString(), e );
     }
     else
     {
         self.Error( "template parse error in group " + self.Group.Name + " line " + self.GroupFileLine + "; template context is " + self.GetEnclosingInstanceStackString(), e );
     }
 }
Esempio n. 18
0
 public override void ReportError(RecognitionException e)
 {
     if (groupI != null)
     {
         groupI.Error("template group interface parse error", e);
     }
     else
     {
         Console.Error.WriteLine("template group interface parse error: " + e);
         e.PrintStackTrace(Console.Error);
     }
 }
Esempio n. 19
0
 public override void ReportError( RecognitionException e )
 {
     if ( groupI != null )
     {
         groupI.Error( "template group interface parse error", e );
     }
     else
     {
         Console.Error.WriteLine( "template group interface parse error: " + e );
         e.PrintStackTrace( Console.Error );
     }
 }
Esempio n. 20
0
 public override void DisplayRecognitionError(string[] tokenNames,
                                     RecognitionException e)
 {
     string msg = GetParserErrorMessage(this, e);
     if (paraphrases.Count > 0)
     {
         string paraphrase = paraphrases.Peek();
         msg = msg + " while " + paraphrase;
     }
     //List stack = getRuleInvocationStack(e, this.getClass().getName());
     //msg += ", rule stack = " + stack;
     tool.errMgr.SyntaxError(ErrorType.SYNTAX_ERROR, SourceName, e.Token, e, msg);
 }
Esempio n. 21
0
        public override void ReportError(RecognitionException e)
        {
            StringTemplateGroup group = self.Group;

            if (group == StringTemplate.defaultGroup)
            {
                self.Error("template parse error; template context is " + self.GetEnclosingInstanceStackString(), e);
            }
            else
            {
                self.Error("template parse error in group " + self.Group.Name + " line " + self.GroupFileLine + "; template context is " + self.GetEnclosingInstanceStackString(), e);
            }
        }
Esempio n. 22
0
        public override void DisplayRecognitionError(string[] tokenNames,
                                                     RecognitionException e)
        {
            string msg = GetParserErrorMessage(this, e);

            if (paraphrases.Count > 0)
            {
                string paraphrase = paraphrases.Peek();
                msg = msg + " while " + paraphrase;
            }
            //List stack = getRuleInvocationStack(e, this.getClass().getName());
            //msg += ", rule stack = " + stack;
            tool.errMgr.SyntaxError(ErrorType.SYNTAX_ERROR, SourceName, e.Token, e, msg);
        }
        public override void DisplayRecognitionError(string[] tokenNames, Antlr.Runtime.RecognitionException e)
        {
            var sb = new StringBuilder();

            sb.AppendLine("There was a problem with the json input during syntactical analysis and it cannot be parsed. Here is some more info:");
            sb.AppendLine("----");

            sb.AppendLine(e.Message);
            sb.AppendLine("region: " + e.Input.ToString());
            sb.AppendLine("line: " + e.Line);
            sb.AppendLine("col: " + e.CharPositionInLine);

            throw new JsonException(sb.ToString(), e);
        }
Esempio n. 24
0
 public GrammarSyntaxMessage(ErrorType etype,
                             string fileName,
                             IToken offendingToken,
                             RecognitionException antlrException,
                             params object[] args)
     : base(etype, antlrException, offendingToken, args)
 {
     this.fileName       = fileName;
     this.offendingToken = offendingToken;
     if (offendingToken != null)
     {
         line         = offendingToken.Line;
         charPosition = offendingToken.CharPositionInLine;
     }
 }
Esempio n. 25
0
 public override void ReportError(RecognitionException e)
 {
     if (_group != null)
     {
         string header  = GetErrorHeader(e);
         string message = GetErrorMessage(e, TokenNames);
         message = string.Format("{0}: {1}: {2}", "template group parse error", header, message);
         _group.Error(message, e);
     }
     else
     {
         Console.Error.WriteLine("template group parse error: " + e);
         e.PrintStackTrace(Console.Error);
     }
 }
Esempio n. 26
0
 public override void ReportError( RecognitionException e )
 {
     if ( _group != null )
     {
         string header = GetErrorHeader( e );
         string message = GetErrorMessage( e, TokenNames );
         message = string.Format( "{0}: {1}: {2}", "template group parse error", header, message );
         _group.Error( message, e );
     }
     else
     {
         Console.Error.WriteLine( "template group parse error: " + e );
         e.PrintStackTrace( Console.Error );
     }
 }
Esempio n. 27
0
 public GrammarSyntaxMessage(ErrorType etype,
                             string fileName,
                             IToken offendingToken,
                             RecognitionException antlrException,
                             params object[] args)
     : base(etype, antlrException, offendingToken, args)
 {
     this.fileName = fileName;
     this.offendingToken = offendingToken;
     if (offendingToken != null)
     {
         line = offendingToken.Line;
         charPosition = offendingToken.CharPositionInLine;
     }
 }
Esempio n. 28
0
        public override void RecognitionException(RecognitionException e)
        {
            StringBuilder buf = new StringBuilder(50);

            buf.Append("exception\t");
            buf.Append(e.GetType().FullName);
            // dump only the data common to all exceptions for now
            buf.Append("\t");
            buf.Append(e.Index);
            buf.Append("\t");
            buf.Append(e.Line);
            buf.Append("\t");
            buf.Append(e.CharPositionInLine);
            Transmit(buf.ToString());
        }
Esempio n. 29
0
 public virtual string GetParserErrorMessage(Parser parser, RecognitionException e)
 {
     string msg;
     if (e is NoViableAltException)
     {
         string name = parser.GetTokenErrorDisplay(e.Token);
         msg = name + " came as a complete surprise to me";
     }
     else if (e is v4ParserException)
     {
         msg = ((v4ParserException)e).msg;
     }
     else
     {
         msg = parser.GetErrorMessage(e, parser.TokenNames);
     }
     return msg;
 }
Esempio n. 30
0
        public virtual string GetParserErrorMessage(Parser parser, RecognitionException e)
        {
            string msg;

            if (e is NoViableAltException)
            {
                string name = parser.GetTokenErrorDisplay(e.Token);
                msg = name + " came as a complete surprise to me";
            }
            else if (e is v4ParserException)
            {
                msg = ((v4ParserException)e).msg;
            }
            else
            {
                msg = parser.GetErrorMessage(e, parser.TokenNames);
            }
            return(msg);
        }
Esempio n. 31
0
        public override void ReportError(RecognitionException ex)
        {
            IToken token = null;

            if (ex is MismatchedTokenException)
            {
                token = ((MismatchedTokenException)ex).Token;
            }
            else if (ex is NoViableAltException)
            {
                token = ((NoViableAltException)ex).Token;
            }
            ErrorManager.SyntaxError(
                ErrorManager.MSG_SYNTAX_ERROR,
                grammar,
                token,
                "codegen: " + ex.ToString(),
                ex);
        }
Esempio n. 32
0
		override public void RecognitionException(RecognitionException e) 
		{
			if ( backtracking>0 ) return;
			ParseTree ruleNode = (ParseTree)callStack.Peek();
			ParseTree errorNode = Create(e);
			ruleNode.AddChild(errorNode);
		}
Esempio n. 33
0
 public void RecognitionException(RecognitionException e)
 {
     listener.RecognitionException(e);
 }
Esempio n. 34
0
 public override void ReportError(Antlr.Runtime.RecognitionException e)
 {
     throw new UnexpectedTokenSaqlException(e);
 }
Esempio n. 35
0
 public static void SyntaxError( int msgID,
                                Grammar grammar,
                                IToken token,
                                Object arg,
                                RecognitionException re )
 {
     GetErrorState().errors++;
     GetErrorState().errorMsgIDs.Add( msgID );
     GetErrorListener().Error(
         new GrammarSyntaxMessage( msgID, grammar, token, arg, re )
     );
 }
Esempio n. 36
0
 public override void ReportError( RecognitionException ex )
 {
     IToken token = null;
     if ( ex is MismatchedTokenException )
     {
         token = ( (MismatchedTokenException)ex ).Token;
     }
     else if ( ex is NoViableAltException )
     {
         token = ( (NoViableAltException)ex ).Token;
     }
     ErrorManager.SyntaxError(
         ErrorManager.MSG_SYNTAX_ERROR,
         grammar,
         token,
         "codegen: " + ex.ToString(),
         ex );
 }
Esempio n. 37
0
 public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e)
 {
     string msg = GetErrorMessage(e, tokenNames);
     tool.errMgr.SyntaxError(ErrorType.SYNTAX_ERROR, SourceName, e.Token, e, msg);
 }
Esempio n. 38
0
 public GrammarASTErrorNode(ITokenStream input, IToken start, IToken stop,
                            RecognitionException e)
 {
     @delegate = new CommonErrorNode(input, start, stop, e);
 }
 public override object ErrorNode(Antlr.Runtime.ITokenStream input, Antlr.Runtime.IToken start, Antlr.Runtime.IToken stop, Antlr.Runtime.RecognitionException e)
 {
     return(new LSLErrorNode(input, start, stop, e));
 }
Esempio n. 40
0
 public void RecognitionException(Antlr.Runtime.RecognitionException e)
 {
     Console.WriteLine("RecognitionException {0} {1} {2}", e.Line, e.Message, e.Index);
 }
 public override void ReportError( RecognitionException e )
 {
     self.Error( "<...> chunk lexer error", e );
 }
Esempio n. 42
0
 public void RecognitionException(RecognitionException e)
 {
     for (int i = 0; i < listeners.Count; i++)
     {
         IDebugEventListener listener = (IDebugEventListener)listeners[i];
         listener.RecognitionException(e);
     }
 }
Esempio n. 43
0
 public override void RecognitionException(RecognitionException e)
 {
     numberReportedErrors++;
 }
Esempio n. 44
0
        public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e)
        {
            string msg = GetErrorMessage(e, tokenNames);

            tool.errMgr.SyntaxError(ErrorType.SYNTAX_ERROR, SourceName, e.Token, e, msg);
        }
Esempio n. 45
0
 public override void RecognitionException(RecognitionException e)
 {
     numberReportedErrors++;
 }
Esempio n. 46
0
		public void RecognitionException(RecognitionException e) { listener.RecognitionException(e); }
 public override void ReportError(RecognitionException e)
 {
     self.Error("<...> chunk lexer error", e);
 }
Esempio n. 48
0
 public GrammarASTErrorNode(ITokenStream input, IToken start, IToken stop,
                            RecognitionException e)
 {
     @delegate = new CommonErrorNode(input, start, stop, e);
 }
Esempio n. 49
0
		public override void RecognitionException(RecognitionException e)
		{
			StringBuilder buf = new StringBuilder(50);
			buf.Append("exception\t");
			buf.Append(e.GetType().FullName);
			// dump only the data common to all exceptions for now
			buf.Append("\t");
			buf.Append(e.Index);
			buf.Append("\t");
			buf.Append(e.Line);
			buf.Append("\t");
			buf.Append(e.CharPositionInLine);
			Transmit(buf.ToString());
		}
 public ParseErrorEventArgs(Antlr.Runtime.RecognitionException exception)
 {
     this.exception = exception;
 }