Esempio n. 1
0
        AXmlObject ReadTextOrElement(IEnumerator <AXmlObject> objStream)
        {
            AXmlObject curr = objStream.Current;

            if (curr is AXmlText || curr is AXmlElement)
            {
                return(ReadSingleObject(objStream));
            }
            else
            {
                AXmlTag currTag = (AXmlTag)curr;
                if (currTag == StartTagPlaceholder)
                {
                    return(ReadElement(objStream));
                }
                else if (currTag.IsStartOrEmptyTag)
                {
                    return(ReadElement(objStream));
                }
                else
                {
                    return(ReadSingleObject(objStream));
                }
            }
        }
Esempio n. 2
0
 /// <summary> Visit RawTag </summary>
 public override void VisitTag(AXmlTag tag)
 {
     sb.Append(tag.OpeningBracket);
     sb.Append(tag.Name);
     base.VisitTag(tag);
     sb.Append(tag.ClosingBracket);
 }
Esempio n. 3
0
 /// <summary> Visit RawTag </summary>
 public virtual void VisitTag(AXmlTag tag)
 {
     foreach (AXmlObject child in tag.Children)
     {
         child.AcceptVisitor(this);
     }
 }
		/// <summary> Visit RawTag </summary>
		public override void VisitTag(AXmlTag tag)
		{
			sb.Append(tag.OpeningBracket);
			sb.Append(tag.Name);
			base.VisitTag(tag);
			sb.Append(tag.ClosingBracket);
		}
		/// <summary> Visit RawTag </summary>
		public override void VisitTag(AXmlTag tag)
		{
			if (tag.IsStartOrEmptyTag) {
				sb.Append('<');
				sb.Append(tag.Name);
				foreach(AXmlAttribute attr in tag.Children.OfType<AXmlAttribute>().OrderBy(a => a.Name)) {
					VisitAttribute(attr);
				}
				sb.Append('>');
				if (tag.IsEmptyTag) {
					// Use explicit start-end pair
					sb.AppendFormat("</{0}>", tag.Name);
				}
			} else if (tag.IsEndTag) {
				sb.AppendFormat("</{0}>", tag.Name);
			} else if (tag.IsProcessingInstruction) {
				sb.Append("<?");
				sb.Append(tag.Name);
				foreach(AXmlText text in tag.Children.OfType<AXmlText>()) {
					sb.Append(text.Value);
				}
				if (tag.Children.Count == 0)
					sb.Append(' ');
				sb.Append("?>");
			} else if (tag.IsCData) {
				foreach(AXmlText text in tag.Children.OfType<AXmlText>()) {
					sb.Append(Escape(text.Value));
				}
			}
		}
Esempio n. 6
0
 /// <summary> Visit RawDocument </summary>
 public override void VisitDocument(AXmlDocument document)
 {
     foreach (AXmlObject child in document.Children)
     {
         AXmlTag tag = child as AXmlTag;
         // Only procssing instructions or elements
         if (tag != null && tag.IsProcessingInstruction && tag.Name != "xml")
         {
             VisitTag(tag);
         }
         else if (child is AXmlElement)
         {
             VisitElement((AXmlElement)child);
         }
     }
 }
 /// <summary> Visit RawTag </summary>
 public override void VisitTag(AXmlTag tag)
 {
     if (tag.IsStartOrEmptyTag)
     {
         sb.Append('<');
         sb.Append(tag.Name);
         foreach (AXmlAttribute attr in tag.Children.OfType <AXmlAttribute>().OrderBy(a => a.Name))
         {
             VisitAttribute(attr);
         }
         sb.Append('>');
         if (tag.IsEmptyTag)
         {
             // Use explicit start-end pair
             sb.AppendFormat("</{0}>", tag.Name);
         }
     }
     else if (tag.IsEndTag)
     {
         sb.AppendFormat("</{0}>", tag.Name);
     }
     else if (tag.IsProcessingInstruction)
     {
         sb.Append("<?");
         sb.Append(tag.Name);
         foreach (AXmlText text in tag.Children.OfType <AXmlText>())
         {
             sb.Append(text.Value);
         }
         if (tag.Children.Count == 0)
         {
             sb.Append(' ');
         }
         sb.Append("?>");
     }
     else if (tag.IsCData)
     {
         foreach (AXmlText text in tag.Children.OfType <AXmlText>())
         {
             sb.Append(Escape(text.Value));
         }
     }
 }
		public override void VisitTag(AXmlTag tag)
		{
			if (tag.IsComment) {
				StringBuilder sb = new StringBuilder();
				
				foreach(AXmlText text in tag.Children.OfType<AXmlText>()) {
					sb.Append(text.Value);
				}
				
				string value = sb.ToString();
				
				foreach (string commentTag in lexerTags) {
					if (value.Contains(commentTag)) {
						CompilationUnit.TagComments.Add(new TagComment(value, CreateRegion(tag.StartOffset, tag.EndOffset)));
						break;
					}
				}
			}
			
			base.VisitTag(tag);
		}
Esempio n. 9
0
        /// <summary> Raises Changed event </summary>
        protected void OnChanged()
        {
            AXmlParser.Log("Changed {0}", this);
            if (Changed != null)
            {
                Changed(this, new AXmlObjectEventArgs()
                {
                    Object = this
                });
            }
            AXmlDocument doc = this.Document;

            if (doc != null)
            {
                doc.OnObjectChanged(this);
            }
            // As a convenience, also rasie an event for the parent element
            AXmlTag me = this as AXmlTag;

            if (me != null && (me.IsStartOrEmptyTag || me.IsEndTag) && me.Parent is AXmlElement)
            {
                me.Parent.OnChanged();
            }
        }
Esempio n. 10
0
        /// <inheritdoc/>
        internal override bool UpdateDataFrom(AXmlObject source)
        {
            if (!base.UpdateDataFrom(source))
            {
                return(false);
            }
            AXmlTag src = (AXmlTag)source;

            if (this.OpeningBracket != src.OpeningBracket ||
                this.Name != src.Name ||
                this.ClosingBracket != src.ClosingBracket)
            {
                OnChanging();
                this.OpeningBracket = src.OpeningBracket;
                this.Name           = src.Name;
                this.ClosingBracket = src.ClosingBracket;
                OnChanged();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 11
0
		/// <summary> Visit RawTag </summary>
		public virtual void VisitTag(AXmlTag tag)
		{
			foreach(AXmlObject child in tag.Children) child.AcceptVisitor(this);
		}
Esempio n. 12
0
        /// <summary> Get posible configurations after considering fiven object </summary>
        Configurations ProcessObject(Configurations oldConfigs, AXmlObject obj)
        {
            AXmlParser.Log("Processing {0}", obj);

            AXmlTag tag = obj as AXmlTag;

            AXmlParser.Assert(obj is AXmlTag || obj is AXmlText || obj is AXmlElement, obj.GetType().Name + " not expected");
            if (obj is AXmlElement)
            {
                AXmlParser.Assert(((AXmlElement)obj).IsProperlyNested, "Element not proprly nested");
            }

            Configurations newConfigs = new Configurations();

            foreach (var kvp in oldConfigs)
            {
                Configuration oldConfig    = kvp.Value;
                var           oldStartTags = oldConfig.StartTags;
                var           oldDocument  = oldConfig.Document;
                int           oldCost      = oldConfig.Cost;

                if (tag != null && tag.IsStartTag)
                {
                    newConfigs.Add(new Configuration {                                        // Push start-tag (cost 0)
                        StartTags = oldStartTags.Push(tag),
                        Document  = oldDocument.Push(tag),
                        Cost      = oldCost,
                    });
                }
                else if (tag != null && tag.IsEndTag)
                {
                    newConfigs.Add(new Configuration {                                        // Ignore (cost 1)
                        StartTags = oldStartTags,
                        Document  = oldDocument.Push(StartTagPlaceholder).Push(tag),
                        Cost      = oldCost + 1,
                    });
                    if (!oldStartTags.IsEmpty && oldStartTags.Peek().Name != tag.Name)
                    {
                        newConfigs.Add(new Configuration {                                        // Pop 1 item (cost 1) - not mathcing
                            StartTags = oldStartTags.Pop(),
                            Document  = oldDocument.Push(tag),
                            Cost      = oldCost + 1,
                        });
                    }
                    int popedCount = 0;
                    var startTags  = oldStartTags;
                    var doc        = oldDocument;
                    foreach (AXmlTag poped in oldStartTags)
                    {
                        popedCount++;
                        if (poped.Name == tag.Name)
                        {
                            newConfigs.Add(new Configuration {                                         // Pop 'x' items (cost x-1) - last one is matching
                                StartTags = startTags.Pop(),
                                Document  = doc.Push(tag),
                                Cost      = oldCost + popedCount - 1,
                            });
                        }
                        startTags = startTags.Pop();
                        doc       = doc.Push(EndTagPlaceholder);
                    }
                }
                else
                {
                    // Empty tag  or  other tag type  or  text  or  properly nested element
                    newConfigs.Add(new Configuration {                                        // Ignore (cost 0)
                        StartTags = oldStartTags,
                        Document  = oldDocument.Push(obj),
                        Cost      = oldCost,
                    });
                }
            }

            // Log("New configurations:" + newConfigs.ToString());

            Configurations bestNewConfigurations = new Configurations(
                newConfigs.Values.OrderBy(v => v.Cost).Take(maxConfigurationCount)
                );

            // AXmlParser.Log("Best new configurations:" + bestNewConfigurations.ToString());

            return(bestNewConfigurations);
        }
Esempio n. 13
0
        AXmlElement ReadElement(IEnumerator <AXmlObject> objStream)
        {
            AXmlElement element = new AXmlElement();

            element.IsProperlyNested = true;

            // Read start tag
            AXmlTag startTag = ReadSingleObject(objStream) as AXmlTag;

            AXmlParser.DebugAssert(startTag != null, "Start tag expected");
            AXmlParser.DebugAssert(startTag.IsStartOrEmptyTag || startTag == StartTagPlaceholder, "Start tag expected");
            if (startTag == StartTagPlaceholder)
            {
                element.HasStartOrEmptyTag = false;
                element.IsProperlyNested   = false;
                TagReader.OnSyntaxError(element, objStream.Current.StartOffset, objStream.Current.EndOffset,
                                        "Matching openning tag was not found");
            }
            else
            {
                element.HasStartOrEmptyTag = true;
                element.AddChild(startTag);
            }

            // Read content and end tag
            if (startTag == StartTagPlaceholder ||             // Check first in case the start tag is null
                element.StartTag.IsStartTag)
            {
                while (true)
                {
                    AXmlTag currTag = objStream.Current as AXmlTag;                     // Peek
                    if (currTag == EndTagPlaceholder)
                    {
                        TagReader.OnSyntaxError(element, element.LastChild.EndOffset, element.LastChild.EndOffset,
                                                "Expected '</{0}>'", element.StartTag.Name);
                        ReadSingleObject(objStream);
                        element.HasEndTag        = false;
                        element.IsProperlyNested = false;
                        break;
                    }
                    else if (currTag != null && currTag.IsEndTag)
                    {
                        if (element.HasStartOrEmptyTag && currTag.Name != element.StartTag.Name)
                        {
                            TagReader.OnSyntaxError(element, currTag.StartOffset + 2, currTag.StartOffset + 2 + currTag.Name.Length,
                                                    "Expected '{0}'.  End tag must have same name as start tag.", element.StartTag.Name);
                        }
                        element.AddChild(ReadSingleObject(objStream));
                        element.HasEndTag = true;
                        break;
                    }
                    AXmlObject nested = ReadTextOrElement(objStream);
                    if (nested is AXmlElement)
                    {
                        if (!((AXmlElement)nested).IsProperlyNested)
                        {
                            element.IsProperlyNested = false;
                        }
                        element.AddChildren(Split((AXmlElement)nested).ToList());
                    }
                    else
                    {
                        element.AddChild(nested);
                    }
                }
            }
            else
            {
                element.HasEndTag = false;
            }

            element.StartOffset = element.FirstChild.StartOffset;
            element.EndOffset   = element.LastChild.EndOffset;

            AXmlParser.Assert(element.HasStartOrEmptyTag || element.HasEndTag, "Must have at least start or end tag");

            AXmlParser.Log("Constructed {0}", element);
            trackedSegments.AddParsedObject(element, null);             // Need all elements in cache for offset tracking
            return(element);
        }