public static CompilerResult CompileScript(string Filespec, string Options, CompilerParseLineDelegate ParseLine = null)
{
CompilerResult Result = new CompilerResult();
Result.Compiled = false;
Result.Warnings = new List<string>();
Result.Errors = new List<string>();
try
{
//
// Construct the command line for the compiler instance.
//
string CmdLine = CreateCompilerCommandLine(Filespec, Options);
Process CompilerProcess;
ProcessStartInfo StartInfo = new ProcessStartInfo(GetCompilerExe(), CmdLine);
string Line;
//
// Start the compiler process and begin reading stdout until
// end of file is reached. In the absence of any error
// messages observed, the operation is assumed to have
// completed successfully.
//
StartInfo.CreateNoWindow = true;
StartInfo.UseShellExecute = false;
StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
StartInfo.RedirectStandardOutput = true;
StartInfo.WorkingDirectory = ALFA.SystemInfo.GetModuleDirectory();
CompilerProcess = Process.Start(StartInfo);
Result.Compiled = true;
while ((Line = CompilerProcess.StandardOutput.ReadLine()) != null)
{
//
// Parse each line, examining it for a compiler diagnostic
// indicator. Accumulate errors and warnings into their
// respective diagnostic message lists for the caller to
// examine.
//
if (ParseLine != null && ParseLine(Line))
continue;
if (Line.StartsWith("Error:"))
{
Result.Errors.Add(Line);
Result.Compiled = false;
}
else if (Line.Contains("): Error: NSC"))
{
Result.Errors.Add(Line);
Result.Compiled = false;
}
else if (Line.StartsWith("Warning:"))
{
Result.Warnings.Add(Line);
}
else if (Line.Contains("): Warning: NSC"))
{
Result.Warnings.Add(Line);
}
}
CompilerProcess.WaitForExit();
}
catch (Exception e)
{
Result.Errors.Add(String.Format(
"ALFA.ScriptCompiler.CompileScript({0}, {1}): Exception: '{2}'.",
Filespec,
Options,
e));
Result.Compiled = false;
}
return Result;
}