[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-patches
Subject:    [Mono-patches] r109405 - in
From:       "Michael Hutchinson (m.j.hutchinson () gmail ! com)"
Date:       2008-07-31 23:22:16
Message-ID: 20080731232216.E3CAA9472C () mono-cvs ! ximian ! com
[Download RAW message or body]

Author: mhutch
Date: 2008-07-31 19:22:16 -0400 (Thu, 31 Jul 2008)
New Revision: 109405

Modified:
   branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/ChangeLog
   branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/Parser.cs
  branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XDom.cs
  branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeState.cs
  branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeValueState.cs
  branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCDataState.cs
  branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCommentState.cs
  branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlDocTypeState.cs
  branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlProcessingInstructionState.cs
 Log:
* MonoDevelop.Xml.StateEngine/XmlAttributeValueState.cs,
  MonoDevelop.Xml.StateEngine/XmlAttributeState.cs: Use a
  MalformedTagState for recovery.
* MonoDevelop.Xml.StateEngine/XmlCommentState.cs,
  MonoDevelop.Xml.StateEngine/XmlDocTypeState.cs,
  MonoDevelop.Xml.StateEngine/XmlCDataState.cs,
  MonoDevelop.Xml.StateEngine/XmlProcessingInstructionState.cs:
  Insert nodes when state begins (instead of end) so that we can use
  them in paths.
* MonoDevelop.Xml.StateEngine/Parser.cs: Track previous state.
* MonoDevelop.Xml.StateEngine/XDom.cs: Add support for getting a
  "friendly" representation of the node for a user-visible path.

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/ChangeLog
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/ChangeLog	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/ChangeLog	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -1,3 +1,18 @@
+2008-07-31  Michael Hutchinson <mhutchinson@novell.com> 
+
+	* MonoDevelop.Xml.StateEngine/XmlAttributeValueState.cs,
+	  MonoDevelop.Xml.StateEngine/XmlAttributeState.cs: Use a
+	  MalformedTagState for recovery.
+	* MonoDevelop.Xml.StateEngine/XmlCommentState.cs,
+	  MonoDevelop.Xml.StateEngine/XmlDocTypeState.cs,
+	  MonoDevelop.Xml.StateEngine/XmlCDataState.cs,
+	  MonoDevelop.Xml.StateEngine/XmlProcessingInstructionState.cs:
+	  Insert nodes when state begins (instead of end) so that we can use
+	  them in paths.
+	* MonoDevelop.Xml.StateEngine/Parser.cs: Track previous state.
+	* MonoDevelop.Xml.StateEngine/XDom.cs: Add support for getting a
+	  "friendly" representation of the node for a user-visible path.
+
 2008-07-30  Michael Hutchinson <mhutchinson@novell.com> 
 
 	* MonoDevelop.Xml.StateEngine/XmlClosingTagState.cs,

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/Parser.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/Parser.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/Parser.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -38,6 +38,7 @@
 	{
 		RootState rootState;
 		State currentState;
+		State previousState;
 		bool buildTree;
 		
 		int position;
@@ -51,6 +52,7 @@
 		{
 			this.rootState = rootState;
 			this.currentState = rootState;
+			this.previousState = rootState;
 			this.buildTree = buildTree;
 			Reset ();
 		}
@@ -61,6 +63,7 @@
 			
 			rootState = copyFrom.rootState;
 			currentState = copyFrom.currentState;
+			previousState = copyFrom.previousState;
 			
 			position = copyFrom.position;
 			stateTag = copyFrom.stateTag;
@@ -87,7 +90,8 @@
 		
 		public void Reset ()
 		{
-			currentState = rootState;
+			currentState = rootState;
+			previousState = rootState;
 			position = 0;
 			stateTag = 0;
 			keywordBuilder = new StringBuilder ();
@@ -115,6 +119,7 @@
 						return;
 					
 					// state changed; reset stuff
+					previousState = currentState;
 					currentState = nextState;
 					stateTag = 0;
 					currentStateLength = 0;
@@ -128,11 +133,13 @@
 					if (rollback == null)
 						return;
 					
-					//"complex" rollbacks require actually moving backwards
+					//"complex" rollbacks require actually skipping backwards.
+					//Note the previous state is invalid for this operation.
 					else if (rollback.Length > 0) {
-						position -= rollback.Length;
+						position -= (rollback.Length + 1);
 						foreach (char rollChar in rollback)
 							Push (rollChar);
+						position++;
 					}
 				}
 				throw new InvalidOperationException ("Too many state changes for char '" + c + \
"'. Current state is " + currentState.ToString () + "."); @@ -215,6 +222,10 @@
 			get { return keywordBuilder; }
 		}
 		
+		State IParseContext.PreviousState {
+			get { return previousState; }
+		}
+		
 		public int CurrentStateLength { get { return currentStateLength; } }
 		public NodeStack Nodes { get { return nodes; } }
 		
@@ -278,6 +289,7 @@
 		StringBuilder KeywordBuilder { get; }
 		int CurrentStateLength { get; }
 		int Position { get; }
+		State PreviousState { get; }
 		NodeStack Nodes { get; }
 		bool BuildTree { get; }
 		void LogError (string message);

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XDom.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XDom.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XDom.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -114,6 +114,10 @@
 		}
 		
 		protected XObject () {}
+		
+		public virtual string FriendlyPathRepresentation {
+			get { return GetType ().ToString (); }
+		}
 	}
 	
 	public abstract class XNode : XObject
@@ -302,7 +306,6 @@
 			foreach (XNode child in Nodes)
 				child.BuildTreeString (builder, indentLevel + 1);
 		}
-
 	}
 	
 	public class XElement : XContainer, IAttributedXObject
@@ -401,6 +404,10 @@
 			builder.Append (' ', indentLevel * 2);
 			builder.AppendLine ("]");
 		}
+		
+		public override string FriendlyPathRepresentation {
+			get { return name.FullName; }
+		}
 
 	}
 	
@@ -466,7 +473,12 @@
 			return string.Format (
 				"[XAttribute Name='{0}' Location='{1}' Value='{2}']", name.FullName, \
this.Position, this.valu);  }
+		
+		public override string FriendlyPathRepresentation {
+			get { return "@" + name.FullName; }
+		}
 
+
 	}
 	
 	public class XAttributeCollection : IEnumerable<XAttribute>
@@ -539,6 +551,11 @@
 		
 		protected XCData () {}
 		protected override XObject NewInstance () { return new XCData (); }
+		
+		public override string FriendlyPathRepresentation {
+			get { return "<![CDATA[ ]]>"; }
+		}
+
 	}
 	
 	public class XComment : XNode
@@ -548,6 +565,10 @@
 		
 		protected XComment () {}
 		protected override XObject NewInstance () { return new XComment (); }
+		
+		public override string FriendlyPathRepresentation {
+			get { return "<!-- -->"; }
+		}
 	}
 	
 	public class XProcessingInstruction : XNode
@@ -557,6 +578,10 @@
 		
 		protected XProcessingInstruction () {}
 		protected override XObject NewInstance () { return new XProcessingInstruction (); \
} +		
+		public override string FriendlyPathRepresentation {
+			get { return "<? ?>"; }
+		}
 	}
 	
 	public class XDocType : XNode 
@@ -566,6 +591,10 @@
 		
 		protected XDocType () {}
 		protected override XObject NewInstance () { return new XDocType (); }
+		
+		public override string FriendlyPathRepresentation {
+			get { return "<!DOCTYPE>"; }
+		}
 	}
 	
 	public class XClosingTag : XNode, INamedXObject
@@ -603,12 +632,21 @@
 			//immutable types
 			name = copyFromAtt.name;
 		}
+		
+		public override string FriendlyPathRepresentation {
+			get { return "/" + name.FullName; }
+		}
+
 	}
 	
 	public class XDocument : XContainer
 	{
 		public XDocument () : base (0) {}
 		protected override XObject NewInstance () { return new XDocument (); }
+		
+		public override string FriendlyPathRepresentation {
+			get { throw new InvalidOperationException ("Should not display document in path \
bar."); } +		}
 	}
 	
 	public interface INamedXObject

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeState.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeState.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeState.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -38,21 +38,27 @@
 	{
 		XmlNameState XmlNameState;
 		XmlAttributeValueState XmlAttributeValueState;
+		XmlMalformedTagState MalformedTagState;
 		
 		const int NAMING = 0;
 		const int GETTINGEQ = 1;
 		const int GETTINGVAL = 2;
 		
 		public XmlAttributeState ()
-			: this (new XmlNameState (), new XmlAttributeValueState ())
+			: this (new XmlNameState (), new XmlAttributeValueState (), new \
XmlMalformedTagState ())  {}
 		
-		public XmlAttributeState (XmlNameState nameState, XmlAttributeValueState \
valueState) +		public XmlAttributeState (
+			XmlNameState nameState,
+			XmlAttributeValueState valueState,
+			XmlMalformedTagState malformedTagState)
 		{
 			this.XmlNameState = nameState;
 			this.XmlAttributeValueState = valueState;
+			this.MalformedTagState = malformedTagState;
 			Adopt (this.XmlNameState);
-			Adopt (this.XmlAttributeValueState);
+			Adopt (this.XmlAttributeValueState);
+			Adopt (this.MalformedTagState);
 		}
 
 		public override State PushChar (char c, IParseContext context, ref string \
rollback) @@ -60,11 +66,12 @@
 			XAttribute att = context.Nodes.Peek () as XAttribute;
 			
 			if (c == '<') {
-				context.LogError ("Attribute ended unexpectedly with '<' character.");
-				if (att != null)
-					context.Nodes.Pop ();
+				//MalformedTagState handles errors and cleanup
+				//context.LogError ("Attribute ended unexpectedly with '<' character.");
+				//if (att != null)
+				//	context.Nodes.Pop ();
 				rollback = string.Empty;
-				return this.Parent;
+				return MalformedTagState;
 			}
 			
 			//state has just been entered
@@ -73,7 +80,7 @@
 				//starting a new attribute?
 				if (att == null) {
 					Debug.Assert (context.StateTag == NAMING);
-					att = new XAttribute (context.Position);
+					att = new XAttribute (context.Position - 1);
 					context.Nodes.Push (att);
 					rollback = string.Empty;
 					return XmlNameState;
@@ -84,7 +91,7 @@
 					} else {
 						//Got value, so end attribute
 						context.Nodes.Pop ();
-						att.End (context.Position);
+						att.End (context.Position - 1);
 						IAttributedXObject element = (IAttributedXObject) context.Nodes.Peek ();
 						element.Attributes.AddAttribute (att);
 						rollback = string.Empty;
@@ -94,11 +101,12 @@
 			}
 			
 			if (c == '>') {
-				context.LogWarning ("Attribute ended unexpectedly with '>' character.");
-				if (att != null)
-					context.Nodes.Pop ();
+				//MalformedTagState handles errors and cleanup
+				//context.LogWarning ("Attribute ended unexpectedly with '>' character.");
+				//if (att != null)
+				//	context.Nodes.Pop ();
 				rollback = string.Empty;
-				return this.Parent;
+				return MalformedTagState;
 			}
 			
 			if (context.StateTag == GETTINGEQ) {
@@ -117,11 +125,12 @@
 				}
 			}
 			
-			context.LogError ("Unexpected character '" + c + "' in attribute.");
-			if (att != null)
-				context.Nodes.Pop ();
+			//MalformedTagState handles errors and cleanup
+			//context.LogError ("Unexpected character '" + c + "' in attribute.");
+			//if (att != null)
+			//	context.Nodes.Pop ();
 			rollback = string.Empty;
-			return Parent;
+			return MalformedTagState;
 		}
 	}
 }

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeValueState.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeValueState.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlAttributeValueState.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -38,6 +38,17 @@
 		const int UNDELIMITED = 1;
 		const int SINGLEQUOTE = 2;
 		const int DOUBLEQUOTE = 3;
+		
+		XmlMalformedTagState MalformedTagState;
+		
+		public XmlAttributeValueState () : this (new XmlMalformedTagState ())
+		{}
+		
+		public XmlAttributeValueState (XmlMalformedTagState malformedTagState)
+		{
+			this.MalformedTagState = malformedTagState;
+			Adopt (this.MalformedTagState);
+		}
 		
 		public override State PushChar (char c, IParseContext context, ref string \
rollback)  {
@@ -56,16 +67,18 @@
 					context.LogWarning ("Unquoted attribute value");
 					context.StateTag = UNDELIMITED;
 				} else {
-					context.LogWarning ("Unexpected character '" + c + "' getting attribute \
value"); +					//MalformedTagState handles error reporting
+					//context.LogWarning ("Unexpected character '" + c + "' getting attribute \
value");  rollback = string.Empty;
-					return Parent;
+					return MalformedTagState;
 				}
 			}
 			
 			if (c == '<') {
-				context.LogError  ("Attribute value ended unexpectedly.");
+				//MalformedTagState handles error reporting
+				//context.LogError  ("Attribute value ended unexpectedly.");
 				rollback = string.Empty;
-				return this.Parent;
+				return MalformedTagState;
 			}
 			
 			//special handling for "undelimited" values
@@ -76,7 +89,9 @@
 				} else if (char.IsWhiteSpace (c) || c == '>' || c == '\\') {
 					att.Value = context.KeywordBuilder.ToString ();
 				} else {
-					context.LogWarning ("Unexpected character '" + c + "' getting attribute \
value"); +					//MalformedTagState handles error reporting
+					//context.LogWarning ("Unexpected character '" + c + "' getting attribute \
value"); +					return MalformedTagState;
 				}
 				rollback = string.Empty;
 				return Parent;

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCDataState.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCDataState.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCDataState.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -40,6 +40,11 @@
 		
 		public override State PushChar (char c, IParseContext context, ref string \
rollback)  {
+			if (context.CurrentStateLength == 1) {
+				int start = context.Position - "<![CDATA[".Length - 1;
+				context.Nodes.Push (new XCData (start));
+			}
+			
 			if (c == ']') {
 				//make sure we know when there are two ']' chars together
 				if (context.StateTag == NOMATCH)
@@ -50,9 +55,11 @@
 			} else if (c == '>' && context.StateTag == DOUBLE_BRACKET) {
 				// if the ']]' is followed by a '>', the state has ended
 				// so attach a node to the DOM and end the state
+				XCData cdata = (XCData) context.Nodes.Pop ();
+				
 				if (context.BuildTree) {
-					int start = context.Position - (context.CurrentStateLength + \
                "<![CDATA[".Length);
-					((XContainer) context.Nodes.Peek ()).AddChildNode (new XCData (start, \
context.Position)); +					cdata.End (context.Position);
+					((XContainer) context.Nodes.Peek ()).AddChildNode (cdata); 
 				}
 				return Parent;
 			} else {

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCommentState.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCommentState.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlCommentState.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -40,6 +40,11 @@
 		
 		public override State PushChar (char c, IParseContext context, ref string \
rollback)  {
+			if (context.CurrentStateLength == 1) {
+				int start = context.Position - "<!--".Length - 1;
+				context.Nodes.Push (new XComment (start));
+			}
+			
 			if (c == '-') {
 				//make sure we know when there are two '-' chars together
 				if (context.StateTag == NOMATCH)
@@ -51,10 +56,13 @@
 				if (c == '>') {
 					// if the '--' is followed by a '>', the state has ended
 					// so attach a node to the DOM and end the state
+					XComment comment = (XComment) context.Nodes.Pop ();
+					
 					if (context.BuildTree) {
-						int start = context.Position - (context.CurrentStateLength + "<!--".Length);
-						((XContainer) context.Nodes.Peek ()).AddChildNode (new XComment (start, \
context.Position)); +						comment.End (context.Position);
+						((XContainer) context.Nodes.Peek ()).AddChildNode (comment);
 					}
+					
 					rollback = string.Empty;
 					return Parent;
 				} else {

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlDocTypeState.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlDocTypeState.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlDocTypeState.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -36,15 +36,22 @@
 	{
 		public override State PushChar (char c, IParseContext context, ref string \
rollback)  {
+			if (context.CurrentStateLength == 1) {
+				int start = context.Position - "<!DOCTYPE".Length - 1;
+				context.Nodes.Push (new XDocType (start));
+			}
+			
 			if (c == '>' ||  c == '<') {
+				XDocType doc = (XDocType) context.Nodes.Pop ();
+				
 				if (c == '<') {
 					rollback = string.Empty;
 					context.LogError ("Doctype ended prematurely.");
 				}
 				
 				if (context.BuildTree) {
-					int start = context.Position - (context.CurrentStateLength + 9); // <!DOCTYPE \
                is 9 chars
-					((XContainer) context.Nodes.Peek ()).AddChildNode (new XDocType (start, \
context.Position));  +					doc.End (context.Position);
+					((XContainer) context.Nodes.Peek ()).AddChildNode (doc); 
 				}
 				return Parent;
 			}

Modified: branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlProcessingInstructionState.cs
 ===================================================================
--- branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlProcessingInstructionState.cs	2008-07-31 \
                23:17:02 UTC (rev 109404)
+++ branches/mkrueger/monodevelop/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.Xml.StateEngine/XmlProcessingInstructionState.cs	2008-07-31 \
23:22:16 UTC (rev 109405) @@ -39,6 +39,11 @@
 		
 		public override State PushChar (char c, IParseContext context, ref string \
rollback)  {
+			if (context.CurrentStateLength == 1) {
+				int start = context.Position - "<?".Length - 1;
+				context.Nodes.Push (new XProcessingInstruction (start));
+			}
+			
 			if (c == '?') {
 				if (context.StateTag == NOMATCH) {
 					context.StateTag = QUESTION;
@@ -47,11 +52,12 @@
 			} else if (c == '>' && context.StateTag == QUESTION) {
 				// if the '?' is followed by a '>', the state has ended
 				// so attach a node to the DOM and end the state
+				XProcessingInstruction xpi = (XProcessingInstruction) context.Nodes.Pop ();
+				
 				if (context.BuildTree) {
-					int start = context.Position - (context.CurrentStateLength + "<?".Length);
-					((XContainer) context.Nodes.Peek ()).AddChildNode (
-						new XProcessingInstruction (start, context.Position));
-				}
+					xpi.End (context.Position);
+					((XContainer) context.Nodes.Peek ()).AddChildNode (xpi); 
+				}
 				return Parent;
 			} else {
 				context.StateTag = NOMATCH;

_______________________________________________
Mono-patches maillist  -  Mono-patches@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-patches


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic