using System;
using System.Reflection;
using System.Diagnostics;
using System.Text;
using System.IO;
using AnticipatingMinds.Genesis.CodeDOM;
using AnticipatingMinds.Genesis.CodeDOM.Utilities;
using System.Collections.Specialized;
using System.Threading;
using System.CodeDom.Compiler;
using System.Collections;
using System.Security.Permissions;
//Add threading and meat formultithreading. Background/foreground parsing.
//Leave only events and one function that actually does parse.
namespace AnticipatingMinds.Genesis.CodeParser{
public class ParsingErrorEventArgs : EventArgs
{
public ParsingErrorEventArgs(CompilerError erorr)
{
this.parserError = erorr;
}
public CompilerError Error
{
get
{
return parserError;
}
}
private CompilerError parserError;
}
public delegate void ParsingErrorEventHandler(object sender, ParsingErrorEventArgs e);
public class ParsingProgressEventArgs : EventArgs
{
public ParsingProgressEventArgs(byte percentsCompleted)
{
this.percentsCompleted = percentsCompleted;
}
public byte PercentsCompleted
{
get
{
return percentsCompleted;
}
}
private byte percentsCompleted = 0;
}
public delegate void ParsingProgressEventHandler(object sender, ParsingProgressEventArgs e);
public class ParsingStartedEventArgs : EventArgs
{
public ParsingStartedEventArgs(string fileName)
{
this.fileName = fileName;
}
public string FileName
{
get
{
return fileName;
}
}
private string fileName;
}
public delegate void ParsingStartedEventHandler(object sender, ParsingStartedEventArgs e);
public class ParsingEndedEventArgs : EventArgs
{
public ParsingEndedEventArgs(CodeCompileUnit compiledCodeGraph,CompilerErrorCollection parsingErrors)
{
this.compiledCodeGraph = compiledCodeGraph;
this.parsingErrors = parsingErrors;
}
public CodeCompileUnit CompiledCodeGraph
{
get
{
return compiledCodeGraph;
}
}
public CompilerErrorCollection Errors
{
get
{
return parsingErrors;
}
}
private CodeCompileUnit compiledCodeGraph;
private CompilerErrorCollection parsingErrors;
}
public delegate void ParsingEndedEventHandler(object sender, ParsingEndedEventArgs e);
[System.Security.Permissions.StrongNameIdentityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand,
PublicKey=
"00240000048000009400000006020000002400005253413100040000010001009D309779C258129573FC313836474C75C4CE9F4" +
"107524FA0B9A6DB2E52754459C5A8946E4CBD5B98ACDB2413C5AFD38C1DF00C9A946713E867237B47F9D9CC473D4A853EACBEAB" +
"799EC0A271B468D4B6D52301A414A7772F05FEBD2BA7D0A2835F0D45E401C3C37F9E7B991D29F07DA88E20BB3839A34A2739AB6" +
"56B5204C8BC")]
public abstract class CodeParser
{
protected CodeParser(string sourceCode,string fileName,CodeAssembly codeAssembly)
{
this.sourceCode = sourceCode;
this.fileName = fileName;
this.codeAssembly = codeAssembly;
}
public virtual event ParsingErrorEventHandler ParsingError;
public virtual event ParsingProgressEventHandler ParsingProgress;
public virtual event ParsingStartedEventHandler ParsingStarted;
public virtual event ParsingEndedEventHandler ParsingEnded;
public abstract CodeAssemblyFile Parse(ManualResetEvent cancelEvent);
protected void OnParsingError(CompilerError error)
{
if(ParsingError != null)
ParsingError(this,new ParsingErrorEventArgs(error));
}
protected void OnParsingProgress(byte percentsCompleted)
{
if(ParsingProgress != null)
ParsingProgress(this,new ParsingProgressEventArgs(percentsCompleted));
}
protected void OnParsingStarted(string fileName)
{
if(ParsingStarted != null)
ParsingStarted(this,new ParsingStartedEventArgs(fileName));
}
protected void OnParsingEnded(CodeCompileUnit compiledCodeGraph,CompilerErrorCollection parsingErrors)
{
if(ParsingEnded != null)
ParsingEnded(this,new ParsingEndedEventArgs(compiledCodeGraph,parsingErrors));
}
public abstract CompilerErrorCollection Errors
{
get;
}
public string SourceCode
{
get
{
return sourceCode;
}
}
public string FileName
{
get
{
return fileName;
}
}
public CodeAssembly CodeAssembly
{
get
{
return codeAssembly;
}
}
private static string[] emptyStringArray = new string[0];
private string sourceCode;
private string fileName;
private CodeAssembly codeAssembly;
};
}
|