예제 #1
0
 internal AXmlElement(AXmlObject parent, int startOffset, InternalElement internalObject)
     : base(parent, startOffset, internalObject)
 {
     Log.Assert(internalObject.NestedObjects[0] is InternalTag, "First child of element must be start tag");
 }
        List <InternalObject> CreateElements(ref ImmutableStack <InternalObject> inputObjects)
        {
            List <InternalObject> objects = new List <InternalObject>();

            while (!inputObjects.IsEmpty)
            {
                var obj = inputObjects.Peek();
                var tag = obj as InternalTag;
                if (tag != null && tag.IsStartTag)
                {
                    break;
                }
                inputObjects = inputObjects.Pop();
                if (tag != null && tag.IsEndTag)
                {
                    if (inputObjects.Peek() == StartTagPlaceholder)
                    {
                        objects.Add(tag.AddSyntaxError("Matching opening tag was not found"));
                        inputObjects = inputObjects.Pop();
                    }
                    else
                    {
                        var childElements = CreateElements(ref inputObjects);
                        var startTag      = (InternalTag)inputObjects.Peek();
                        inputObjects = inputObjects.Pop();
                        childElements.Add(startTag);
                        childElements.Reverse();
                        if (tag != EndTagPlaceholder)
                        {
                            // add end tag
                            if (startTag.Name != tag.Name)
                            {
                                childElements.Add(tag.AddSyntaxError("Expected '</" + startTag.Name + ">'. End tag must have same name as start tag."));
                            }
                            else
                            {
                                childElements.Add(tag);
                            }
                        }
                        InternalElement e = new InternalElement(startTag);
                        e.HasEndTag     = (tag != EndTagPlaceholder);
                        e.NestedObjects = new InternalObject[childElements.Count];
                        int pos = 0;
                        for (int i = 0; i < childElements.Count; i++)
                        {
                            e.NestedObjects[i] = childElements[i].SetStartRelativeToParent(pos);
                            pos += e.NestedObjects[i].Length;
                        }
                        e.Length = pos;
                        if (tag == EndTagPlaceholder)
                        {
                            e.SyntaxErrors = new [] { new InternalSyntaxError(pos, pos, "Missing '</" + startTag.Name + ">'") };
                        }
                        objects.Add(e);
                    }
                }
                else
                {
                    objects.Add(obj);
                }
            }
            return(objects);
        }
		internal AXmlElement(AXmlObject parent, int startOffset, InternalElement internalObject)
			: base(parent, startOffset, internalObject)
		{
			Log.Assert(internalObject.NestedObjects[0] is InternalTag, "First child of element must be start tag");
		}
		List<InternalObject> CreateElements(ref ImmutableStack<InternalObject> inputObjects)
		{
			List<InternalObject> objects = new List<InternalObject>();
			while (!inputObjects.IsEmpty) {
				var obj = inputObjects.Peek();
				var tag = obj as InternalTag;
				if (tag != null && tag.IsStartTag)
					break;
				inputObjects = inputObjects.Pop();
				if (tag != null && tag.IsEndTag) {
					if (inputObjects.Peek() == StartTagPlaceholder) {
						objects.Add(tag.AddSyntaxError("Matching opening tag was not found"));
						inputObjects = inputObjects.Pop();
					} else {
						var childElements = CreateElements(ref inputObjects);
						var startTag = (InternalTag)inputObjects.Peek();
						inputObjects = inputObjects.Pop();
						childElements.Add(startTag);
						childElements.Reverse();
						if (tag != EndTagPlaceholder) {
							// add end tag
							if (startTag.Name != tag.Name) {
								childElements.Add(tag.AddSyntaxError("Expected '</" + startTag.Name + ">'. End tag must have same name as start tag."));
							} else {
								childElements.Add(tag);
							}
						}
						InternalElement e = new InternalElement(startTag);
						e.HasEndTag = (tag != EndTagPlaceholder);
						e.NestedObjects = new InternalObject[childElements.Count];
						int pos = 0;
						for (int i = 0; i < childElements.Count; i++) {
							e.NestedObjects[i] = childElements[i].SetStartRelativeToParent(pos);
							pos += e.NestedObjects[i].Length;
						}
						e.Length = pos;
						if (tag == EndTagPlaceholder) {
							e.SyntaxErrors = new [] { new InternalSyntaxError(pos, pos, "Missing '</" + startTag.Name + ">'") };
						}
						objects.Add(e);
					}
				} else {
					objects.Add(obj);
				}
			}
			return objects;
		}