Пример #1
0
        /// <summary>
        /// It is public for now because I need it unit tested...  This code is pretty fagile.
        /// I am looking to get XML output rather than parsing the cmd lines one at a time...
        /// </summary>
        /// <param name="error"></param>
        public void ParseError(string error)
        {
            if (error.Length == 0)
            {
                // We are done...  Set the state back to running so that we can detect new errors/warnings.
                CompilerState = ECompileState.Running;
                return;
            }

            int start = 0, end = 0;

            if (CompilerState == ECompileState.Running)
            {
                //
                // Check for errors...
                //
                if ((start = error.IndexOf(": ERROR - ")) != -1)
                {
                    string message = error.Substring(start + ": ERROR - ".Length);

                    end = start - 1; // Skip over ':'
                    start = error.LastIndexOf(':', end);
                    string line = error.Substring(start + 1, end - start);
                    string file = error.Substring(0, start);

                    Error e = new Error(file, message, Int32.Parse(line), -1, Error.ESeverity.High);
                    Errors.Add(e);
                    CompilerState = ECompileState.ProcessingError;
                }
                //
                // Check for warnings...
                //
                else if ((start = error.IndexOf(": WARNING - ")) != -1)
                {
                    string message = error.Substring(start + ": WARNING - ".Length);

                    end = start - 1; // Skip over ':'
                    start = error.LastIndexOf(':', end);
                    string line = error.Substring(start + 1, end - start);
                    string file = error.Substring(0, start);

                    Error e = new Error(file, message, Int32.Parse(line), -1, Error.ESeverity.Low);
                    Warnings.Add(e);
                    CompilerState = ECompileState.ProcessingWarning;
                }
                else if (error.StartsWith(Errors.Count.ToString() + " error(s)") == false)
                {
                    Failures.Add(error);
                }
            }
            //
            // Little check sum that helps us determine if we have the right number of errors as
            // well as when we need to reset the state of the compiler
            //
            else if (error.StartsWith(Errors.Count.ToString() + " error(s)") == true)
            {
                // We are done...  Set the state back to running so that we can detect new errors/warnings.
                CompilerState = ECompileState.Running;
            }
            //
            // Process everything else...
            //
            else
            {
                switch (CompilerState)
                {
                    case ECompileState.ProcessingError:
                        {
                            if (error[error.Length - 1] == '^')
                                Errors.Last().CharNo = error.Length - 1;
                            else
                                Errors.Last().Line += error;
                            break;
                        }
                    case ECompileState.ProcessingWarning:
                        {
                            if (error[error.Length - 1] == '^')
                                Warnings.Last().CharNo = error.Length - 1;
                            else
                                Warnings.Last().Line += error;
                            break;
                        }
                    default:
                        {
                            Failures.Add(error);
                            break;
                        }
                }
            }
        }
Пример #2
0
        public Result Compile(CompilerOptions options)
        {
            OutputScript = String.Empty;
            Errors.Clear();
            Warnings.Clear();
            Failures.Clear();

            string command = CMDCompilerOptions.Instance.Configure(options);

            if (command != String.Empty)
            {
                var file = createConfigFile(command);
                CompilerState = ECompileState.Running;
                Java.Run("-jar \"" + CMDCompiler.Closure + "\"" + " --flagfile=\"" + file + "\"", compile_OutputDataReceived, compile_ErrorDataReceived);
                File.Delete(file);
                CompilerState = ECompileState.Finished;
            }

            return Result.fromCMD(this, options);;
        }