|
|
@@ -52,17 +52,16 @@ namespace System.Web.Compilation
|
|
|
static readonly object textParsedEvent = new object ();
|
|
|
#if NET_2_0
|
|
|
static readonly object parsingCompleteEvent = new object();
|
|
|
-
|
|
|
- byte[] md5checksum;
|
|
|
#endif
|
|
|
AspTokenizer tokenizer;
|
|
|
int beginLine, endLine;
|
|
|
int beginColumn, endColumn;
|
|
|
int beginPosition, endPosition;
|
|
|
string filename;
|
|
|
- string fileText;
|
|
|
string verbatimID;
|
|
|
-
|
|
|
+ string fileText;
|
|
|
+ StringReader fileReader;
|
|
|
+
|
|
|
EventHandlerList events = new EventHandlerList ();
|
|
|
|
|
|
public event ParseErrorHandler Error {
|
|
|
@@ -90,18 +89,20 @@ namespace System.Web.Compilation
|
|
|
public AspParser (string filename, TextReader input)
|
|
|
{
|
|
|
this.filename = filename;
|
|
|
- fileText = input.ReadToEnd ();
|
|
|
-#if NET_2_0
|
|
|
- MD5 md5 = MD5.Create ();
|
|
|
- md5checksum = md5.ComputeHash (Encoding.UTF8.GetBytes (fileText));
|
|
|
-#endif
|
|
|
- StringReader reader = new StringReader (fileText);
|
|
|
- tokenizer = new AspTokenizer (reader);
|
|
|
+ this.fileText = input.ReadToEnd ();
|
|
|
+ this.fileReader = new StringReader (this.fileText);
|
|
|
+ tokenizer = new AspTokenizer (this.fileReader);
|
|
|
}
|
|
|
|
|
|
#if NET_2_0
|
|
|
public byte[] MD5Checksum {
|
|
|
- get { return md5checksum; }
|
|
|
+ get {
|
|
|
+ MD5 checksum = tokenizer.Checksum;
|
|
|
+ if (checksum == null)
|
|
|
+ return new byte[0];
|
|
|
+
|
|
|
+ return checksum.Hash;
|
|
|
+ }
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
@@ -122,12 +123,17 @@ namespace System.Web.Compilation
|
|
|
}
|
|
|
|
|
|
public string FileText {
|
|
|
- get { return fileText; }
|
|
|
+ get {
|
|
|
+ if (fileText != null)
|
|
|
+ return fileText;
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public string PlainText {
|
|
|
get {
|
|
|
- if (beginPosition >= endPosition)
|
|
|
+ if (beginPosition >= endPosition || fileText == null)
|
|
|
return null;
|
|
|
|
|
|
return fileText.Substring (beginPosition, endPosition - beginPosition);
|
|
|
@@ -144,7 +150,7 @@ namespace System.Web.Compilation
|
|
|
verbatimID = value;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
bool Eat (int expected_token)
|
|
|
{
|
|
|
if (tokenizer.get_token () != expected_token) {
|
|
|
@@ -173,60 +179,73 @@ namespace System.Web.Compilation
|
|
|
|
|
|
public void Parse ()
|
|
|
{
|
|
|
+ if (tokenizer == null) {
|
|
|
+ OnError ("AspParser not initialized properly.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
int token;
|
|
|
string id;
|
|
|
TagAttributes attributes;
|
|
|
TagType tagtype = TagType.Text;
|
|
|
StringBuilder text = new StringBuilder ();
|
|
|
|
|
|
- while ((token = tokenizer.get_token ()) != Token.EOF) {
|
|
|
- BeginElement ();
|
|
|
+ try {
|
|
|
+ while ((token = tokenizer.get_token ()) != Token.EOF) {
|
|
|
+ BeginElement ();
|
|
|
|
|
|
- if (tokenizer.Verbatim){
|
|
|
- string end_verbatim = "</" + verbatimID + ">";
|
|
|
- string verbatim_text = GetVerbatim (token, end_verbatim);
|
|
|
+ if (tokenizer.Verbatim){
|
|
|
+ string end_verbatim = "</" + verbatimID + ">";
|
|
|
+ string verbatim_text = GetVerbatim (token, end_verbatim);
|
|
|
|
|
|
- if (verbatim_text == null)
|
|
|
- OnError ("Unexpected EOF processing " + verbatimID);
|
|
|
+ if (verbatim_text == null)
|
|
|
+ OnError ("Unexpected EOF processing " + verbatimID);
|
|
|
|
|
|
- tokenizer.Verbatim = false;
|
|
|
+ tokenizer.Verbatim = false;
|
|
|
|
|
|
- EndElement ();
|
|
|
- endPosition -= end_verbatim.Length;
|
|
|
- OnTextParsed (verbatim_text);
|
|
|
- beginPosition = endPosition;
|
|
|
- endPosition += end_verbatim.Length;
|
|
|
- OnTagParsed (TagType.Close, verbatimID, null);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (token == '<') {
|
|
|
- GetTag (out tagtype, out id, out attributes);
|
|
|
- EndElement ();
|
|
|
- if (tagtype == TagType.ServerComment)
|
|
|
+ EndElement ();
|
|
|
+ endPosition -= end_verbatim.Length;
|
|
|
+ OnTextParsed (verbatim_text);
|
|
|
+ beginPosition = endPosition;
|
|
|
+ endPosition += end_verbatim.Length;
|
|
|
+ OnTagParsed (TagType.Close, verbatimID, null);
|
|
|
continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (token == '<') {
|
|
|
+ GetTag (out tagtype, out id, out attributes);
|
|
|
+ EndElement ();
|
|
|
+ if (tagtype == TagType.ServerComment)
|
|
|
+ continue;
|
|
|
|
|
|
- if (tagtype == TagType.Text)
|
|
|
- OnTextParsed (id);
|
|
|
- else
|
|
|
- OnTagParsed (tagtype, id, attributes);
|
|
|
+ if (tagtype == TagType.Text)
|
|
|
+ OnTextParsed (id);
|
|
|
+ else
|
|
|
+ OnTagParsed (tagtype, id, attributes);
|
|
|
|
|
|
- continue;
|
|
|
- }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- if (tokenizer.Value.Trim () == "" && tagtype == TagType.Directive) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ if (tokenizer.Value.Trim () == "" && tagtype == TagType.Directive) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- text.Length = 0;
|
|
|
- do {
|
|
|
- text.Append (tokenizer.Value);
|
|
|
- token = tokenizer.get_token ();
|
|
|
- } while (token != '<' && token != Token.EOF);
|
|
|
+ text.Length = 0;
|
|
|
+ do {
|
|
|
+ text.Append (tokenizer.Value);
|
|
|
+ token = tokenizer.get_token ();
|
|
|
+ } while (token != '<' && token != Token.EOF);
|
|
|
|
|
|
- tokenizer.put_back ();
|
|
|
- EndElement ();
|
|
|
- OnTextParsed (text.ToString ());
|
|
|
+ tokenizer.put_back ();
|
|
|
+ EndElement ();
|
|
|
+ OnTextParsed (text.ToString ());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (fileReader != null) {
|
|
|
+ fileReader.Close ();
|
|
|
+ fileReader = null;
|
|
|
+ }
|
|
|
+ tokenizer = null;
|
|
|
}
|
|
|
|
|
|
#if NET_2_0
|