public static string CreateBooCode(CompilerErrorCollection errors,
                CompilerWarningCollection warnings,
                Module module,
                IList<ICSharpCode.NRefactory.ISpecial> specials)
        {
            using (StringWriter w = new StringWriter())
            {
                foreach (CompilerError error in errors)
                {
                    w.WriteLine("ERROR: " + error.ToString());
                }
                if (errors.Count > 0)
                    w.WriteLine();
                foreach (CompilerWarning warning in warnings)
                {
                    w.WriteLine("# WARNING: " + warning.ToString());
                }

                if (warnings.Count > 0)
                    w.WriteLine();

                BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w);
                printer.OnModule(module);
                printer.Finish();
                return w.ToString();
            }
        }
		protected override void ConvertFile(FileProjectItem sourceItem, FileProjectItem targetItem)
		{
			FixExtensionOfExtraProperties(targetItem, ".cs", ".boo");
			FixExtensionOfExtraProperties(targetItem, ".vb", ".boo");
			
			string ext = Path.GetExtension(sourceItem.FileName);
			if (".cs".Equals(ext, StringComparison.OrdinalIgnoreCase) || ".vb".Equals(ext, StringComparison.OrdinalIgnoreCase)) {
				Module module;
				IList<ICSharpCode.NRefactory.ISpecial> specials;
				CompileUnit compileUnit = new CompileUnit();
				using (StringReader r = new StringReader(ParserService.GetParseableFileContent(sourceItem.FileName))) {
					module = Parser.ParseModule(compileUnit, r, ConvertBuffer.ApplySettings(sourceItem.VirtualName, errors, warnings), out specials);
				}
				if (module == null) {
					conversionLog.AppendLine("Could not parse '" + sourceItem.FileName + "', see error list for details.");
					base.ConvertFile(sourceItem, targetItem);
				} else {
					using (StringWriter w = new StringWriter()) {
						BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w);
						printer.OnModule(module);
						printer.Finish();
						
						targetItem.Include = Path.ChangeExtension(targetItem.Include, ".boo");
						File.WriteAllText(targetItem.FileName, w.ToString());
					}
				}
			} else {
				base.ConvertFile(sourceItem, targetItem);
			}
		}
Exemple #3
0
		bool ConvertFileInternal(string input, string output)
		{
			string directory = Path.GetDirectoryName(output);
			if (directory.Length > 0) {
				if (!Directory.Exists(directory)) {
					Directory.CreateDirectory(directory);
				}
			}
			bool isFailed = false;
			if (!overwriteFiles && File.Exists(output)) {
				FailFile(ref isFailed, input, "The output file '{0}' already exists.", output);
				return false;
			}
			try {
				CompilerErrorCollection errors = new CompilerErrorCollection();
				CompilerWarningCollection warnings = new CompilerWarningCollection();
				Module module;
				IList<ICSharpCode.NRefactory.Parser.ISpecial> specials;
				CompileUnit compileUnit = new CompileUnit();
				using (StreamReader r = OpenFile(input)) {
					module = Parser.ParseModule(compileUnit, r, ApplySettings(input, errors, warnings), out specials);
				}
				foreach (CompilerError error in errors) {
					FailFile(ref isFailed, input, error.ToString());
				}
				if (!isFailed && warnings.Count > 0) {
					Console.WriteLine(input + ":");
					foreach (CompilerWarning warning in warnings) {
						Console.WriteLine("  " + warning.ToString());
					}
				}
				using (StreamWriter w = new StreamWriter(output, false, Encoding.UTF8)) {
					foreach (CompilerError error in errors) {
						w.WriteLine("ERROR: " + error.ToString());
					}
					if (errors.Count > 0)
						w.WriteLine();
					foreach (CompilerWarning warning in warnings) {
						w.WriteLine("# WARNING: " + warning.ToString());
					}
					if (warnings.Count > 0)
						w.WriteLine();
					BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w);
					if (module != null) {
						printer.OnModule(module);
					}
					printer.Finish();
				}
			} catch (Exception ex) {
				FailFile(ref isFailed, input, ex);
			}
			return !isFailed;
		}