Ejemplo n.º 1
0
        public static ThemaCompilerContext Compile(string code, Action <ThemaProject> prepareProject = null)
        {
            var project = new ThemaProject {
                ErrorLevel = ErrorLevel.Error, UseEcoOptimization = true, UseEcoProcess = true
            };

            project.SetSelfLog(LogLevel.Debug);
            project.NonResolvedProcessThemaRefIsError = true;
            project.CustomCompiler           = new ApplyEcoProcesses();
            project.DirectSource["main.bxl"] = code;
            if (null != prepareProject)
            {
                prepareProject(project);
            }
            var compiler = new ThemaCompiler();

            var context = compiler.Compile(project);

            Console.WriteLine(project.GetLog());
            foreach (var e in context.Errors)
            {
                Console.WriteLine(e);
            }
            return(context);
        }
		/// <summary>
		/// </summary>
		/// <param name="args"> </param>
		/// <exception cref="Exception"></exception>
		public void Run(string[] args) {
			//	Contract.Requires<ArgumentException>(args!=null && args.Length!=0);
			var project = new ThemaProject();
			var projfile = Path.GetFullPath(args[0]);
			var dir = Path.GetDirectoryName(projfile);
			if (null == dir) {
				throw new Exception("не могу определить рабочую директорию");
			}
			Environment.CurrentDirectory = dir;
			var projfilexml = Application.Current.Bxl.Parse(File.ReadAllText(projfile), Path.GetFileName(projfile));
			IList<string> targets = new List<string>();
			if (args.Length > 1) {
				for (var i = 1; i < args.Length; i++) {
					targets.Add(args[i]);
				}
			}
			project.ConfigureFromXml(projfilexml, string.Join(",", targets.ToArray()));

			Console.WriteLine("Project loaded from " + projfile);
			var compiler = new ThemaCompiler();
			Console.WriteLine("Start of compilation");
			Result = compiler.Compile(project);

			if (ErrorLevel.Warning <= project.ErrorLevel) {
				Console.ForegroundColor = ConsoleColor.Yellow;
				foreach (var warn in Result.Errors.Where(x => x.Level <= ErrorLevel.Warning)) {
					Console.WriteLine(warn);
				}
				Console.ResetColor();
			}
			Console.ForegroundColor = ConsoleColor.Red;
			foreach (var error in Result.Errors.Where(x => x.Level > ErrorLevel.Warning)) {
				Console.WriteLine(error);
			}
			Console.ResetColor();

			if (Result.IsComplete) {
				Console.ForegroundColor = ConsoleColor.Green;
				Console.WriteLine("compilation complete");
			}
			else {
				Console.ForegroundColor = ConsoleColor.Red;
				Console.WriteLine("compilation failed!");
			}
			Console.ResetColor();
		}
Ejemplo n.º 3
0
        protected ThemaCompilerContext execute <T>(ThemaProject proj = null, LogLevel level = LogLevel.Trace)
            where T : IThemaCompilerSetup, new()
        {
            sw                  = new StringWriter();
            proj                = proj ?? getDefaultProject();
            proj.UserLog        = proj.UserLog ?? BaseTextWriterLogWriter.CreateLog("default", sw, level);
            proj.CustomCompiler = proj.CustomCompiler ?? new T();
            var compiler = new ThemaCompiler();
            var result   = compiler.Compile(proj);

            Console.WriteLine(sw.ToString());
            foreach (var e in result.Errors)
            {
                Console.WriteLine(e);
            }
            return(result);
        }
Ejemplo n.º 4
0
		public static ThemaCompilerContext Compile(string code, Action<ThemaProject> prepareProject = null) {
			var project = new ThemaProject {ErrorLevel = ErrorLevel.Error, UseEcoOptimization = true, UseEcoProcess = true};
			project.SetSelfLog(LogLevel.Debug);
			project.NonResolvedProcessThemaRefIsError = true;
			project.CustomCompiler = new ApplyEcoProcesses();
			project.DirectSource["main.bxl"] = code;
			if (null != prepareProject) {
				prepareProject(project);
			}
			var compiler = new ThemaCompiler();

			var context = compiler.Compile(project);
			Console.WriteLine(project.GetLog());
			foreach (var e in context.Errors) {
				Console.WriteLine(e);
			}
			return context;
		}