Inheritance: System.Exception
Exemplo n.º 1
0
 public static SyntaxErrorException BadSourceError(byte badByte, SourceSpan span, string path)
 {
     SyntaxErrorException res = new SyntaxErrorException(
         String.Format("Non-ASCII character '\\x{0:x2}' in file {2} on line {1}, but no encoding declared;",
             badByte,
             span.Start.Line,
             path
         ),
         path,
         null,
         null,
         span,
         ErrorCodes.SyntaxError,
         Severity.FatalError
     );
     return res;
 }
		public void Init()
		{
			mockCompiler = new MockPythonCompiler();
			compiler = new DummyPythonCompilerTask(mockCompiler, @"C:\Projects\MyProject");
			compiler.TargetType = "Exe";
			compiler.OutputAssembly = "test.exe";
			
			TaskItem sourceFile = new TaskItem(@"D:\Projects\MyProject\test.py");
			compiler.Sources = new ITaskItem[] {sourceFile};
			
			SourceUnit source = DefaultContext.DefaultPythonContext.CreateSourceUnit(NullTextContentProvider.Null, @"test", SourceCodeKind.InteractiveCode);
			
			SyntaxErrorException ex = new SyntaxErrorException("Error", null, SourceSpan.None, 1000, Severity.FatalError);
			mockCompiler.ThrowExceptionAtCompile = ex;
			
			success = compiler.Execute();
		}
Exemplo n.º 3
0
        internal static void ThrowSyntaxErrorException(Microsoft.Scripting.SyntaxErrorException e,
                                                       string defaultVirtualPath, int defaultLine)
        {
            // Try to get a virtual path
            string virtualPath = Misc.GetVirtualPathFromPhysicalPath(e.GetSymbolDocumentName());
            int    line;

            // If we couldn't get one, use the passed in path
            if (virtualPath == null)
            {
                virtualPath = defaultVirtualPath;
                line        = defaultLine;
            }
            else
            {
                line = e.Line;
            }

            Misc.ThrowException(null /*message*/, e, virtualPath, line);
        }
Exemplo n.º 4
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.Contains(PythonContext._syntaxErrorNoCaret)) ? 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;

            AssociateException(e, se);

            return se;
        }
Exemplo n.º 5
0
 public SyntaxErrorExceptionPrettyWrapper(string message, SyntaxErrorException innerException)
     : base(message, innerException)
 {
     _innerException = innerException;
 }
Exemplo n.º 6
0
 internal static void ThrowSyntaxErrorException(Microsoft.Scripting.SyntaxErrorException e)
 {
     ThrowSyntaxErrorException(e, null, 1);
 }
Exemplo n.º 7
0
		/// <summary>
		/// Matches the syntax exception SourcePath against filenames being compiled. The 
		/// syntax exception only contains the file name without its path and without its file extension.
		/// </summary>
		string GetFileName(SyntaxErrorException ex, ITaskItem[] sources)
		{
			if (ex.SourcePath == null) {
				return null;
			}
			
			string sourcePath = ex.SourcePath.Replace('\\', '.');
			foreach (ITaskItem item in sources) {
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item.ItemSpec);
				if (fileNameWithoutExtension == sourcePath) {
					return item.ItemSpec;
				}
			}
			string fileName = sourcePath + ".py";
			return Path.Combine(GetCurrentFolder(), fileName);
		}
Exemplo n.º 8
0
		void LogSyntaxError(SyntaxErrorException ex)
		{
			string fileName = GetFileName(ex, sources);
			LogError(ex.Message, ex.ErrorCode.ToString(), fileName, ex.Line, ex.Column, ex.RawSpan.End.Line, ex.RawSpan.End.Column);
		}
 /// <summary> シンタックスエラーを処理 </summary>
 /// <param name="ex"></param>
 private void ProcessScriptSyntaxError(SyntaxErrorException ex)
 {
     ProcessScriptExceptionAndExit(
         ex,
         string.Format("\n ファイル名:\"{0}\" \n 位置: 第{1}行, 第{2}列",
             ex.SourcePath,
             ex.Line,
             ex.Column
             )
         );
 }
Exemplo n.º 10
0
 public static SyntaxErrorException SyntaxError(string message, SourceUnit sourceUnit, SourceSpan span, int errorCode)
 {
     var res = new SyntaxErrorException(message, sourceUnit, span, errorCode, Severity.FatalError);
     return res;
 }
Exemplo n.º 11
0
 public RubySyntaxExceptionHelper(SyntaxErrorException exception)
 {
     this.exception = exception;
 }
Exemplo n.º 12
0
 private void WriteSyntaxException(SyntaxErrorException exception)
 {
     Writer.WriteLine("Error: " + exception.Message);
 }