Exemplo n.º 1
0
        /// <summary>
        /// Converts the DLR SyntaxErrorException into a Python new-style SyntaxError instance.
        /// </summary>
        private static BaseException /*!*/ SyntaxErrorToPython(SyntaxErrorException /*!*/ e)
        {
            PythonExceptions._SyntaxError se;
            if (e.GetType() == typeof(IndentationException))
            {
                se = new _SyntaxError(IndentationError);
            }
            else if (e.GetType() == typeof(TabException))
            {
                se = new _SyntaxError(TabError);
            }
            else
            {
                se = new _SyntaxError();
            }

            string sourceLine = PythonContext.GetSourceLine(e);
            string fileName   = e.GetSymbolDocumentName();
            object column     = (e.Column == 0 || e.Data[PythonContext._syntaxErrorNoCaret] != null) ? null : (object)e.Column;

            se.args = PythonTuple.MakeTuple(e.Message, PythonTuple.MakeTuple(fileName, e.Line, column, sourceLine));

            se.filename = fileName;
            se.lineno   = e.Line;
            se.offset   = column;
            se.text     = sourceLine;
            se.msg      = e.Message;

            e.SetPythonException(se);

            return(se);
        }