XML Parser: Changed class prefix to "AXml" (standing for AvalonEdit XML) (part 1)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4675 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
This commit is contained in:
David Srbecký 2009-08-14 20:15:58 +00:00
Родитель 79875801b6
Коммит f7aa18b8ba
24 изменённых файлов: 385 добавлений и 355 удалений

Просмотреть файл

@ -315,28 +315,39 @@
<Compile Include="Utils\ThrowUtil.cs" /> <Compile Include="Utils\ThrowUtil.cs" />
<Compile Include="Utils\Win32.cs" /> <Compile Include="Utils\Win32.cs" />
<CodeAnalysisDictionary Include="Properties\CodeAnalysisDictionary.xml" /> <CodeAnalysisDictionary Include="Properties\CodeAnalysisDictionary.xml" />
<Compile Include="XmlParser\AbstractXmlVisitor.cs" /> <Compile Include="XmlParser\AbstractAXmlVisitor.cs" />
<Compile Include="XmlParser\AttributeCollection.cs" /> <Compile Include="XmlParser\AXmlAttribute.cs" />
<Compile Include="XmlParser\Cache.cs" /> <Compile Include="XmlParser\AXmlAttributeCollection.cs" />
<Compile Include="XmlParser\ChildrenCollection.cs" /> <Compile Include="XmlParser\AXmlContainer.cs" />
<Compile Include="XmlParser\AXmlDocument.cs" />
<Compile Include="XmlParser\AXmlElement.cs" />
<Compile Include="XmlParser\AXmlObject.cs" />
<Compile Include="XmlParser\AXmlObjectCollection.cs" />
<Compile Include="XmlParser\AXmlObjectEventArgs.cs" />
<Compile Include="XmlParser\AXmlParser.cs" />
<Compile Include="XmlParser\AXmlTag.cs" />
<Compile Include="XmlParser\AXmlText.cs" />
<Compile Include="XmlParser\Cache.cs">
<DependentUpon>AXmlParser.cs</DependentUpon>
</Compile>
<Compile Include="XmlParser\ExtensionMethods.cs" /> <Compile Include="XmlParser\ExtensionMethods.cs" />
<Compile Include="XmlParser\FilteredCollection.cs" /> <Compile Include="XmlParser\FilteredCollection.cs" />
<Compile Include="XmlParser\IXmlVisitor.cs" /> <Compile Include="XmlParser\IAXmlVisitor.cs" />
<Compile Include="XmlParser\MergedCollection.cs" /> <Compile Include="XmlParser\MergedCollection.cs" />
<Compile Include="XmlParser\RawAttribute.cs" />
<Compile Include="XmlParser\RawContainer.cs" />
<Compile Include="XmlParser\RawDocument.cs" />
<Compile Include="XmlParser\RawElement.cs" />
<Compile Include="XmlParser\RawObject.cs" />
<Compile Include="XmlParser\RawObjectEventArgs.cs" />
<Compile Include="XmlParser\RawTag.cs" />
<Compile Include="XmlParser\RawText.cs" />
<Compile Include="XmlParser\SyntaxError.cs" />
<Compile Include="XmlParser\TagMatchingHeuristics.cs" />
<Compile Include="XmlParser\TagReader.cs" />
<Compile Include="XmlParser\TokenReader.cs" />
<Compile Include="XmlParser\PrettyPrintXmlVisitor.cs" /> <Compile Include="XmlParser\PrettyPrintXmlVisitor.cs" />
<Compile Include="XmlParser\XmlParser.cs" /> <Compile Include="XmlParser\SyntaxError.cs" />
<Compile Include="XmlParser\TagMatchingHeuristics.cs">
<DependentUpon>AXmlParser.cs</DependentUpon>
</Compile>
<Compile Include="XmlParser\TagReader.cs">
<DependentUpon>AXmlParser.cs</DependentUpon>
</Compile>
<Compile Include="XmlParser\TextType.cs">
<DependentUpon>AXmlText.cs</DependentUpon>
</Compile>
<Compile Include="XmlParser\TokenReader.cs">
<DependentUpon>AXmlParser.cs</DependentUpon>
</Compile>
<Resource Include="themes\RightArrow.cur" /> <Resource Include="themes\RightArrow.cur" />
<EmbeddedResource Include="Highlighting\Resources\ASPX.xshd" /> <EmbeddedResource Include="Highlighting\Resources\ASPX.xshd" />
<EmbeddedResource Include="Highlighting\Resources\BAT-Mode.xshd" /> <EmbeddedResource Include="Highlighting\Resources\BAT-Mode.xshd" />

Просмотреть файл

@ -14,12 +14,12 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Name-value pair in a tag /// Name-value pair in a tag
/// </summary> /// </summary>
public class RawAttribute: RawObject public class AXmlAttribute: AXmlObject
{ {
/// <summary> Name with namespace prefix - exactly as in source file </summary> /// <summary> Name with namespace prefix - exactly as in source file </summary>
public string Name { get; internal set; } public string Name { get; internal set; }
@ -43,11 +43,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary> The element containing this attribute </summary> /// <summary> The element containing this attribute </summary>
/// <returns> Null if orphaned </returns> /// <returns> Null if orphaned </returns>
public RawElement ParentElement { public AXmlElement ParentElement {
get { get {
RawTag tag = this.Parent as RawTag; AXmlTag tag = this.Parent as AXmlTag;
if (tag != null) { if (tag != null) {
return tag.Parent as RawElement; return tag.Parent as AXmlElement;
} }
return null; return null;
} }
@ -77,7 +77,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
get { get {
if (string.IsNullOrEmpty(this.Prefix)) return NoNamespace; if (string.IsNullOrEmpty(this.Prefix)) return NoNamespace;
RawElement elem = this.ParentElement; AXmlElement elem = this.ParentElement;
if (elem != null) { if (elem != null) {
return elem.ReslovePrefix(this.Prefix); return elem.ReslovePrefix(this.Prefix);
} }
@ -95,17 +95,17 @@ namespace ICSharpCode.AvalonEdit.XmlParser
#endregion #endregion
/// <inheritdoc/> /// <inheritdoc/>
public override void AcceptVisitor(IXmlVisitor visitor) public override void AcceptVisitor(IAXmlVisitor visitor)
{ {
visitor.VisitAttribute(this); visitor.VisitAttribute(this);
} }
/// <inheritdoc/> /// <inheritdoc/>
internal override void UpdateDataFrom(RawObject source) internal override void UpdateDataFrom(AXmlObject source)
{ {
base.UpdateDataFrom(source); // Check asserts base.UpdateDataFrom(source); // Check asserts
if (this.LastUpdatedFrom == source) return; if (this.LastUpdatedFrom == source) return;
RawAttribute src = (RawAttribute)source; AXmlAttribute src = (AXmlAttribute)source;
if (this.Name != src.Name || if (this.Name != src.Name ||
this.EqualsSign != src.EqualsSign || this.EqualsSign != src.EqualsSign ||
this.QuotedValue != src.QuotedValue || this.QuotedValue != src.QuotedValue ||

Просмотреть файл

@ -8,43 +8,43 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Specailized attribute collection with attribute name caching /// Specailized attribute collection with attribute name caching
/// </summary> /// </summary>
public class AttributeCollection: FilteredCollection<RawAttribute, ChildrenCollection<RawObject>> public class AXmlAttributeCollection: FilteredCollection<AXmlAttribute, AXmlObjectCollection<AXmlObject>>
{ {
/// <summary> Wrap the given collection. Non-attributes are filtered </summary> /// <summary> Wrap the given collection. Non-attributes are filtered </summary>
public AttributeCollection(ChildrenCollection<RawObject> source): base(source) {} public AXmlAttributeCollection(AXmlObjectCollection<AXmlObject> source): base(source) {}
/// <summary> Wrap the given collection. Non-attributes are filtered. Items not matching the condition are filtered. </summary> /// <summary> Wrap the given collection. Non-attributes are filtered. Items not matching the condition are filtered. </summary>
public AttributeCollection(ChildrenCollection<RawObject> source, Predicate<object> condition): base(source, condition) {} public AXmlAttributeCollection(AXmlObjectCollection<AXmlObject> source, Predicate<object> condition): base(source, condition) {}
Dictionary<string, List<RawAttribute>> hashtable = new Dictionary<string, List<RawAttribute>>(); Dictionary<string, List<AXmlAttribute>> hashtable = new Dictionary<string, List<AXmlAttribute>>();
void AddToHashtable(RawAttribute attr) void AddToHashtable(AXmlAttribute attr)
{ {
string localName = attr.LocalName; string localName = attr.LocalName;
if (!hashtable.ContainsKey(localName)) { if (!hashtable.ContainsKey(localName)) {
hashtable[localName] = new List<RawAttribute>(1); hashtable[localName] = new List<AXmlAttribute>(1);
} }
hashtable[localName].Add(attr); hashtable[localName].Add(attr);
} }
void RemoveFromHashtable(RawAttribute attr) void RemoveFromHashtable(AXmlAttribute attr)
{ {
string localName = attr.LocalName; string localName = attr.LocalName;
hashtable[localName].Remove(attr); hashtable[localName].Remove(attr);
} }
static List<RawAttribute> NoAttributes = new List<RawAttribute>(); static List<AXmlAttribute> NoAttributes = new List<AXmlAttribute>();
/// <summary> /// <summary>
/// Get all attributes with given local name. /// Get all attributes with given local name.
/// Hash table is used for lookup so this is cheap. /// Hash table is used for lookup so this is cheap.
/// </summary> /// </summary>
public IEnumerable<RawAttribute> GetByLocalName(string localName) public IEnumerable<AXmlAttribute> GetByLocalName(string localName)
{ {
if (hashtable.ContainsKey(localName)) { if (hashtable.ContainsKey(localName)) {
return hashtable[localName]; return hashtable[localName];
@ -56,7 +56,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <inheritdoc/> /// <inheritdoc/>
protected override void ClearItems() protected override void ClearItems()
{ {
foreach(RawAttribute item in this) { foreach(AXmlAttribute item in this) {
RemoveFromHashtable(item); RemoveFromHashtable(item);
item.Changing -= item_Changing; item.Changing -= item_Changing;
item.Changed -= item_Changed; item.Changed -= item_Changed;
@ -65,7 +65,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void InsertItem(int index, RawAttribute item) protected override void InsertItem(int index, AXmlAttribute item)
{ {
AddToHashtable(item); AddToHashtable(item);
item.Changing += item_Changing; item.Changing += item_Changing;
@ -83,7 +83,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void SetItem(int index, RawAttribute item) protected override void SetItem(int index, AXmlAttribute item)
{ {
throw new NotSupportedException(); throw new NotSupportedException();
} }
@ -91,14 +91,14 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// Every item in the collectoin should be registered to these handlers // Every item in the collectoin should be registered to these handlers
// so that we can handle renames // so that we can handle renames
void item_Changing(object sender, RawObjectEventArgs e) void item_Changing(object sender, AXmlObjectEventArgs e)
{ {
RemoveFromHashtable((RawAttribute)e.Object); RemoveFromHashtable((AXmlAttribute)e.Object);
} }
void item_Changed(object sender, RawObjectEventArgs e) void item_Changed(object sender, AXmlObjectEventArgs e)
{ {
AddToHashtable((RawAttribute)e.Object); AddToHashtable((AXmlAttribute)e.Object);
} }
} }
} }

Просмотреть файл

@ -14,46 +14,46 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Abstact base class for all types that can contain child nodes /// Abstact base class for all types that can contain child nodes
/// </summary> /// </summary>
public abstract class RawContainer: RawObject public abstract class AXmlContainer: AXmlObject
{ {
/// <summary> /// <summary>
/// Children of the node. It is read-only. /// Children of the node. It is read-only.
/// Note that is has CollectionChanged event. /// Note that is has CollectionChanged event.
/// </summary> /// </summary>
public ChildrenCollection<RawObject> Children { get; private set; } public AXmlObjectCollection<AXmlObject> Children { get; private set; }
/// <summary> Create new container </summary> /// <summary> Create new container </summary>
public RawContainer() public AXmlContainer()
{ {
this.Children = new ChildrenCollection<RawObject>(); this.Children = new AXmlObjectCollection<AXmlObject>();
} }
#region Helpper methods #region Helpper methods
ObservableCollection<RawElement> elements; ObservableCollection<AXmlElement> elements;
/// <summary> Gets direcly nested elements (non-recursive) </summary> /// <summary> Gets direcly nested elements (non-recursive) </summary>
public ObservableCollection<RawElement> Elements { public ObservableCollection<AXmlElement> Elements {
get { get {
if (elements == null) { if (elements == null) {
elements = new FilteredCollection<RawElement, ChildrenCollection<RawObject>>(this.Children); elements = new FilteredCollection<AXmlElement, AXmlObjectCollection<AXmlObject>>(this.Children);
} }
return elements; return elements;
} }
} }
internal RawObject FirstChild { internal AXmlObject FirstChild {
get { get {
return this.Children[0]; return this.Children[0];
} }
} }
internal RawObject LastChild { internal AXmlObject LastChild {
get { get {
return this.Children[this.Children.Count - 1]; return this.Children[this.Children.Count - 1];
} }
@ -62,9 +62,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
#endregion #endregion
/// <inheritdoc/> /// <inheritdoc/>
public override IEnumerable<RawObject> GetSelfAndAllChildren() public override IEnumerable<AXmlObject> GetSelfAndAllChildren()
{ {
return new RawObject[] { this }.Flatten(i => i is RawContainer ? ((RawContainer)i).Children : null); return new AXmlObject[] { this }.Flatten(i => i is AXmlContainer ? ((AXmlContainer)i).Children : null);
} }
/// <summary> /// <summary>
@ -72,13 +72,13 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// Goes recursively down the tree. /// Goes recursively down the tree.
/// Specail case if at the end of attribute or text /// Specail case if at the end of attribute or text
/// </summary> /// </summary>
public RawObject GetChildAtOffset(int offset) public AXmlObject GetChildAtOffset(int offset)
{ {
foreach(RawObject child in this.Children) { foreach(AXmlObject child in this.Children) {
if ((child is RawAttribute || child is RawText) && offset == child.EndOffset) return child; if ((child is AXmlAttribute || child is AXmlText) && offset == child.EndOffset) return child;
if (child.StartOffset < offset && offset < child.EndOffset) { if (child.StartOffset < offset && offset < child.EndOffset) {
if (child is RawContainer) { if (child is AXmlContainer) {
return ((RawContainer)child).GetChildAtOffset(offset); return ((AXmlContainer)child).GetChildAtOffset(offset);
} else { } else {
return child; return child;
} }
@ -90,7 +90,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// Only these four methods should be used to modify the collection // Only these four methods should be used to modify the collection
/// <summary> To be used exlucively by the parser </summary> /// <summary> To be used exlucively by the parser </summary>
internal void AddChild(RawObject item) internal void AddChild(AXmlObject item)
{ {
// Childs can be only added to newly parsed items // Childs can be only added to newly parsed items
Assert(this.Parent == null, "I have to be new"); Assert(this.Parent == null, "I have to be new");
@ -100,7 +100,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> To be used exlucively by the parser </summary> /// <summary> To be used exlucively by the parser </summary>
internal void AddChildren(IEnumerable<RawObject> items) internal void AddChildren(IEnumerable<AXmlObject> items)
{ {
// Childs can be only added to newly parsed items // Childs can be only added to newly parsed items
Assert(this.Parent == null, "I have to be new"); Assert(this.Parent == null, "I have to be new");
@ -112,11 +112,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// To be used exclusively by the children update algorithm. /// To be used exclusively by the children update algorithm.
/// Insert child and keep links consistent. /// Insert child and keep links consistent.
/// </summary> /// </summary>
void InsertChild(int index, RawObject item) void InsertChild(int index, AXmlObject item)
{ {
LogDom("Inserting {0} at index {1}", item, index); LogDom("Inserting {0} at index {1}", item, index);
RawDocument document = this.Document; AXmlDocument document = this.Document;
Assert(document != null, "Can not insert to dangling object"); Assert(document != null, "Can not insert to dangling object");
Assert(item.Parent != this, "Can not own item twice"); Assert(item.Parent != this, "Can not own item twice");
@ -132,16 +132,16 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// Cache constraint: /// Cache constraint:
/// If cached item has parent set, then the whole subtree must be consistent /// If cached item has parent set, then the whole subtree must be consistent
/// </remarks> /// </remarks>
void SetParentPointersInTree(RawObject item) void SetParentPointersInTree(AXmlObject item)
{ {
// All items come from the parser cache // All items come from the parser cache
if (item.Parent == null) { if (item.Parent == null) {
// Dangling object - either a new parser object or removed tree (still cached) // Dangling object - either a new parser object or removed tree (still cached)
item.Parent = this; item.Parent = this;
if (item is RawContainer) { if (item is AXmlContainer) {
foreach(RawObject child in ((RawContainer)item).Children) { foreach(AXmlObject child in ((AXmlContainer)item).Children) {
((RawContainer)item).SetParentPointersInTree(child); ((AXmlContainer)item).SetParentPointersInTree(child);
} }
} }
} else if (item.Parent == this) { } else if (item.Parent == this) {
@ -157,7 +157,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// becuase otherwise this item would be included twice => safe to change parents // becuase otherwise this item would be included twice => safe to change parents
DebugAssert(item.Parent.Document == null, "Old parent is part of document as well"); DebugAssert(item.Parent.Document == null, "Old parent is part of document as well");
// Maintain cache constraint by setting parents to null // Maintain cache constraint by setting parents to null
foreach(RawObject ancest in item.GetAncestors().ToList()) { foreach(AXmlObject ancest in item.GetAncestors().ToList()) {
ancest.Parent = null; ancest.Parent = null;
} }
item.Parent = this; item.Parent = this;
@ -171,7 +171,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// </summary> /// </summary>
void RemoveChild(int index) void RemoveChild(int index)
{ {
RawObject removed = this.Children[index]; AXmlObject removed = this.Children[index];
LogDom("Removing {0} at index {1}", removed, index); LogDom("Removing {0} at index {1}", removed, index);
// Null parent pointer // Null parent pointer
@ -187,10 +187,10 @@ namespace ICSharpCode.AvalonEdit.XmlParser
internal override void DebugCheckConsistency(bool allowNullParent) internal override void DebugCheckConsistency(bool allowNullParent)
{ {
base.DebugCheckConsistency(allowNullParent); base.DebugCheckConsistency(allowNullParent);
RawObject prevChild = null; AXmlObject prevChild = null;
int myStartOffset = this.StartOffset; int myStartOffset = this.StartOffset;
int myEndOffset = this.EndOffset; int myEndOffset = this.EndOffset;
foreach(RawObject child in this.Children) { foreach(AXmlObject child in this.Children) {
Assert(child.Length != 0, "Empty child"); Assert(child.Length != 0, "Empty child");
if (!allowNullParent) { if (!allowNullParent) {
Assert(child.Parent != null, "Null parent reference"); Assert(child.Parent != null, "Null parent reference");
@ -206,24 +206,24 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
} }
internal void UpdateTreeFrom(RawContainer srcContainer) internal void UpdateTreeFrom(AXmlContainer srcContainer)
{ {
RemoveChildrenNotIn(srcContainer.Children); RemoveChildrenNotIn(srcContainer.Children);
InsertAndUpdateChildrenFrom(srcContainer.Children); InsertAndUpdateChildrenFrom(srcContainer.Children);
} }
void RemoveChildrenNotIn(IList<RawObject> srcList) void RemoveChildrenNotIn(IList<AXmlObject> srcList)
{ {
Dictionary<int, RawObject> srcChildren = srcList.ToDictionary(i => i.StartOffset); Dictionary<int, AXmlObject> srcChildren = srcList.ToDictionary(i => i.StartOffset);
for(int i = 0; i < this.Children.Count;) { for(int i = 0; i < this.Children.Count;) {
RawObject child = this.Children[i]; AXmlObject child = this.Children[i];
RawObject srcChild; AXmlObject srcChild;
if (srcChildren.TryGetValue(child.StartOffset, out srcChild) && child.CanUpdateDataFrom(srcChild)) { if (srcChildren.TryGetValue(child.StartOffset, out srcChild) && child.CanUpdateDataFrom(srcChild)) {
// Keep only one item with given offset (we might have several due to deletion) // Keep only one item with given offset (we might have several due to deletion)
srcChildren.Remove(child.StartOffset); srcChildren.Remove(child.StartOffset);
if (child is RawContainer) if (child is AXmlContainer)
((RawContainer)child).RemoveChildrenNotIn(((RawContainer)srcChild).Children); ((AXmlContainer)child).RemoveChildrenNotIn(((AXmlContainer)srcChild).Children);
i++; i++;
} else { } else {
RemoveChild(i); RemoveChild(i);
@ -231,7 +231,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
} }
void InsertAndUpdateChildrenFrom(IList<RawObject> srcList) void InsertAndUpdateChildrenFrom(IList<AXmlObject> srcList)
{ {
for(int i = 0; i < srcList.Count; i++) { for(int i = 0; i < srcList.Count; i++) {
// End of our list? // End of our list?
@ -239,13 +239,13 @@ namespace ICSharpCode.AvalonEdit.XmlParser
InsertChild(i, srcList[i]); InsertChild(i, srcList[i]);
continue; continue;
} }
RawObject child = this.Children[i]; AXmlObject child = this.Children[i];
RawObject srcChild = srcList[i]; AXmlObject srcChild = srcList[i];
if (child.CanUpdateDataFrom(srcChild) /* includes offset test */) { if (child.CanUpdateDataFrom(srcChild) /* includes offset test */) {
child.UpdateDataFrom(srcChild); child.UpdateDataFrom(srcChild);
if (child is RawContainer) if (child is AXmlContainer)
((RawContainer)child).InsertAndUpdateChildrenFrom(((RawContainer)srcChild).Children); ((AXmlContainer)child).InsertAndUpdateChildrenFrom(((AXmlContainer)srcChild).Children);
} else { } else {
InsertChild(i, srcChild); InsertChild(i, srcChild);
} }

Просмотреть файл

@ -14,51 +14,51 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// The root object of the XML document /// The root object of the XML document
/// </summary> /// </summary>
public class RawDocument: RawContainer public class AXmlDocument: AXmlContainer
{ {
/// <summary> Parser that produced this document </summary> /// <summary> Parser that produced this document </summary>
internal XmlParser Parser { get; set; } internal AXmlParser Parser { get; set; }
/// <summary> Occurs when object is added to any part of the document </summary> /// <summary> Occurs when object is added to any part of the document </summary>
public event EventHandler<NotifyCollectionChangedEventArgs> ObjectInserted; public event EventHandler<NotifyCollectionChangedEventArgs> ObjectInserted;
/// <summary> Occurs when object is removed from any part of the document </summary> /// <summary> Occurs when object is removed from any part of the document </summary>
public event EventHandler<NotifyCollectionChangedEventArgs> ObjectRemoved; public event EventHandler<NotifyCollectionChangedEventArgs> ObjectRemoved;
/// <summary> Occurs before local data of any object in the document changes </summary> /// <summary> Occurs before local data of any object in the document changes </summary>
public event EventHandler<RawObjectEventArgs> ObjectChanging; public event EventHandler<AXmlObjectEventArgs> ObjectChanging;
/// <summary> Occurs after local data of any object in the document changed </summary> /// <summary> Occurs after local data of any object in the document changed </summary>
public event EventHandler<RawObjectEventArgs> ObjectChanged; public event EventHandler<AXmlObjectEventArgs> ObjectChanged;
internal void OnObjectInserted(int index, RawObject obj) internal void OnObjectInserted(int index, AXmlObject obj)
{ {
if (ObjectInserted != null) if (ObjectInserted != null)
ObjectInserted(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new RawObject[] { obj }.ToList(), index)); ObjectInserted(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, new AXmlObject[] { obj }.ToList(), index));
} }
internal void OnObjectRemoved(int index, RawObject obj) internal void OnObjectRemoved(int index, AXmlObject obj)
{ {
if (ObjectRemoved != null) if (ObjectRemoved != null)
ObjectRemoved(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new RawObject[] { obj }.ToList(), index)); ObjectRemoved(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new AXmlObject[] { obj }.ToList(), index));
} }
internal void OnObjectChanging(RawObject obj) internal void OnObjectChanging(AXmlObject obj)
{ {
if (ObjectChanging != null) if (ObjectChanging != null)
ObjectChanging(this, new RawObjectEventArgs() { Object = obj } ); ObjectChanging(this, new AXmlObjectEventArgs() { Object = obj } );
} }
internal void OnObjectChanged(RawObject obj) internal void OnObjectChanged(AXmlObject obj)
{ {
if (ObjectChanged != null) if (ObjectChanged != null)
ObjectChanged(this, new RawObjectEventArgs() { Object = obj } ); ObjectChanged(this, new AXmlObjectEventArgs() { Object = obj } );
} }
/// <inheritdoc/> /// <inheritdoc/>
public override void AcceptVisitor(IXmlVisitor visitor) public override void AcceptVisitor(IAXmlVisitor visitor)
{ {
visitor.VisitDocument(this); visitor.VisitDocument(this);
} }

Просмотреть файл

@ -14,12 +14,12 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Logical grouping of other nodes together. /// Logical grouping of other nodes together.
/// </summary> /// </summary>
public class RawElement: RawContainer public class AXmlElement: AXmlContainer
{ {
/// <summary> No tags are missing anywhere within this element (recursive) </summary> /// <summary> No tags are missing anywhere within this element (recursive) </summary>
public bool IsProperlyNested { get; set; } public bool IsProperlyNested { get; set; }
@ -29,9 +29,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
public bool HasEndTag { get; set; } public bool HasEndTag { get; set; }
/// <summary> StartTag of an element. </summary> /// <summary> StartTag of an element. </summary>
public RawTag StartTag { public AXmlTag StartTag {
get { get {
return (RawTag)this.Children[0]; return (AXmlTag)this.Children[0];
} }
} }
@ -43,29 +43,29 @@ namespace ICSharpCode.AvalonEdit.XmlParser
#region Helpper methods #region Helpper methods
AttributeCollection attributes; AXmlAttributeCollection attributes;
/// <summary> Gets attributes of the element </summary> /// <summary> Gets attributes of the element </summary>
public AttributeCollection Attributes { public AXmlAttributeCollection Attributes {
get { get {
if (attributes == null) { if (attributes == null) {
attributes = new AttributeCollection(this.StartTag.Children); attributes = new AXmlAttributeCollection(this.StartTag.Children);
} }
return attributes; return attributes;
} }
} }
ObservableCollection<RawObject> attributesAndElements; ObservableCollection<AXmlObject> attributesAndElements;
// TODO: Identity // TODO: Identity
/// <summary> Gets both attributes and elements </summary> /// <summary> Gets both attributes and elements </summary>
public ObservableCollection<RawObject> AttributesAndElements { public ObservableCollection<AXmlObject> AttributesAndElements {
get { get {
if (attributesAndElements == null) { if (attributesAndElements == null) {
attributesAndElements = new MergedCollection<RawObject, ObservableCollection<RawObject>> ( attributesAndElements = new MergedCollection<AXmlObject, ObservableCollection<AXmlObject>> (
// New wrapper with RawObject types // New wrapper with RawObject types
new FilteredCollection<RawObject, ChildrenCollection<RawObject>>(this.StartTag.Children, x => x is RawAttribute), new FilteredCollection<AXmlObject, AXmlObjectCollection<AXmlObject>>(this.StartTag.Children, x => x is AXmlAttribute),
new FilteredCollection<RawObject, ChildrenCollection<RawObject>>(this.Children, x => x is RawElement) new FilteredCollection<AXmlObject, AXmlObjectCollection<AXmlObject>>(this.Children, x => x is AXmlElement)
); );
} }
return attributesAndElements; return attributesAndElements;
@ -111,11 +111,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary> Find the defualt namesapce for this context </summary> /// <summary> Find the defualt namesapce for this context </summary>
public string FindDefaultNamesapce() public string FindDefaultNamesapce()
{ {
RawElement current = this; AXmlElement current = this;
while(current != null) { while(current != null) {
string namesapce = current.GetAttributeValue(NoNamespace, "xmlns"); string namesapce = current.GetAttributeValue(NoNamespace, "xmlns");
if (namesapce != null) return namesapce; if (namesapce != null) return namesapce;
current = current.Parent as RawElement; current = current.Parent as AXmlElement;
} }
return string.Empty; // No namesapce return string.Empty; // No namesapce
} }
@ -132,11 +132,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
if (prefix == "xml") return XmlNamespace; if (prefix == "xml") return XmlNamespace;
if (prefix == "xmlns") return XmlnsNamespace; if (prefix == "xmlns") return XmlnsNamespace;
RawElement current = this; AXmlElement current = this;
while(current != null) { while(current != null) {
string namesapce = current.GetAttributeValue(XmlnsNamespace, prefix); string namesapce = current.GetAttributeValue(XmlnsNamespace, prefix);
if (namesapce != null) return namesapce; if (namesapce != null) return namesapce;
current = current.Parent as RawElement; current = current.Parent as AXmlElement;
} }
return NoNamespace; // Can not find prefix return NoNamespace; // Can not find prefix
} }
@ -160,7 +160,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
public string GetAttributeValue(string @namespace, string localName) public string GetAttributeValue(string @namespace, string localName)
{ {
@namespace = @namespace ?? string.Empty; @namespace = @namespace ?? string.Empty;
foreach(RawAttribute attr in this.Attributes.GetByLocalName(localName)) { foreach(AXmlAttribute attr in this.Attributes.GetByLocalName(localName)) {
DebugAssert(attr.LocalName == localName, "Bad hashtable"); DebugAssert(attr.LocalName == localName, "Bad hashtable");
if (attr.Namespace == @namespace) { if (attr.Namespace == @namespace) {
return attr.Value; return attr.Value;
@ -172,7 +172,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
#endregion #endregion
/// <inheritdoc/> /// <inheritdoc/>
public override void AcceptVisitor(IXmlVisitor visitor) public override void AcceptVisitor(IAXmlVisitor visitor)
{ {
visitor.VisitElement(this); visitor.VisitElement(this);
} }

Просмотреть файл

@ -14,12 +14,12 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Abstact base class for all types /// Abstact base class for all types
/// </summary> /// </summary>
public abstract class RawObject: TextSegment public abstract class AXmlObject: TextSegment
{ {
/// <summary> Empty string. The namespace used if there is no "xmlns" specified </summary> /// <summary> Empty string. The namespace used if there is no "xmlns" specified </summary>
public static readonly string NoNamespace = string.Empty; public static readonly string NoNamespace = string.Empty;
@ -36,15 +36,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// Cache constraint: /// Cache constraint:
/// If cached item has parent set, then the whole subtree must be consistent /// If cached item has parent set, then the whole subtree must be consistent
/// </remarks> /// </remarks>
public RawObject Parent { get; set; } public AXmlObject Parent { get; set; }
/// <summary> Gets the document owning this object or null if orphaned </summary> /// <summary> Gets the document owning this object or null if orphaned </summary>
public RawDocument Document { public AXmlDocument Document {
get { get {
if (this.Parent != null) { if (this.Parent != null) {
return this.Parent.Document; return this.Parent.Document;
} else if (this is RawDocument) { } else if (this is AXmlDocument) {
return (RawDocument)this; return (AXmlDocument)this;
} else { } else {
return null; return null;
} }
@ -52,25 +52,25 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Creates new object </summary> /// <summary> Creates new object </summary>
public RawObject() public AXmlObject()
{ {
this.LastUpdatedFrom = this; this.LastUpdatedFrom = this;
} }
/// <summary> Occurs before the value of any local properties changes. Nested changes do not cause the event to occur </summary> /// <summary> Occurs before the value of any local properties changes. Nested changes do not cause the event to occur </summary>
public event EventHandler<RawObjectEventArgs> Changing; public event EventHandler<AXmlObjectEventArgs> Changing;
/// <summary> Occurs after the value of any local properties changed. Nested changes do not cause the event to occur </summary> /// <summary> Occurs after the value of any local properties changed. Nested changes do not cause the event to occur </summary>
public event EventHandler<RawObjectEventArgs> Changed; public event EventHandler<AXmlObjectEventArgs> Changed;
/// <summary> Raises Changing event </summary> /// <summary> Raises Changing event </summary>
protected void OnChanging() protected void OnChanging()
{ {
LogDom("Changing {0}", this); LogDom("Changing {0}", this);
if (Changing != null) { if (Changing != null) {
Changing(this, new RawObjectEventArgs() { Object = this } ); Changing(this, new AXmlObjectEventArgs() { Object = this } );
} }
RawDocument doc = this.Document; AXmlDocument doc = this.Document;
if (doc != null) { if (doc != null) {
doc.OnObjectChanging(this); doc.OnObjectChanging(this);
} }
@ -81,9 +81,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
{ {
LogDom("Changed {0}", this); LogDom("Changed {0}", this);
if (Changed != null) { if (Changed != null) {
Changed(this, new RawObjectEventArgs() { Object = this } ); Changed(this, new AXmlObjectEventArgs() { Object = this } );
} }
RawDocument doc = this.Document; AXmlDocument doc = this.Document;
if (doc != null) { if (doc != null) {
doc.OnObjectChanged(this); doc.OnObjectChanged(this);
} }
@ -130,15 +130,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Recursively gets self and all nested nodes. </summary> /// <summary> Recursively gets self and all nested nodes. </summary>
public virtual IEnumerable<RawObject> GetSelfAndAllChildren() public virtual IEnumerable<AXmlObject> GetSelfAndAllChildren()
{ {
return new RawObject[] { this }; return new AXmlObject[] { this };
} }
/// <summary> Get all ancestors of this node </summary> /// <summary> Get all ancestors of this node </summary>
public IEnumerable<RawObject> GetAncestors() public IEnumerable<AXmlObject> GetAncestors()
{ {
RawObject curr = this.Parent; AXmlObject curr = this.Parent;
while(curr != null) { while(curr != null) {
yield return curr; yield return curr;
curr = curr.Parent; curr = curr.Parent;
@ -146,7 +146,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Call appropriate visit method on the given visitor </summary> /// <summary> Call appropriate visit method on the given visitor </summary>
public abstract void AcceptVisitor(IXmlVisitor visitor); public abstract void AcceptVisitor(IAXmlVisitor visitor);
/// <summary> The parser tree object this object was updated from </summary> /// <summary> The parser tree object this object was updated from </summary>
internal object LastUpdatedFrom { get; private set; } internal object LastUpdatedFrom { get; private set; }
@ -154,7 +154,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
internal bool IsInCache { get; set; } internal bool IsInCache { get; set; }
/// <summary> Is call to UpdateDataFrom is allowed? </summary> /// <summary> Is call to UpdateDataFrom is allowed? </summary>
internal bool CanUpdateDataFrom(RawObject source) internal bool CanUpdateDataFrom(AXmlObject source)
{ {
return return
this.GetType() == source.GetType() && this.GetType() == source.GetType() &&
@ -163,7 +163,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Copy all data from the 'source' to this object </summary> /// <summary> Copy all data from the 'source' to this object </summary>
internal virtual void UpdateDataFrom(RawObject source) internal virtual void UpdateDataFrom(AXmlObject source)
{ {
Assert(this.GetType() == source.GetType(), "Source has different type"); Assert(this.GetType() == source.GetType(), "Source has different type");
DebugAssert(this.StartOffset == source.StartOffset, "Source has different StartOffset"); DebugAssert(this.StartOffset == source.StartOffset, "Source has different StartOffset");

Просмотреть файл

@ -12,13 +12,14 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Collection that is publicly read-only and has support /// Collection that is publicly read-only and has support
/// for adding/removing multiple items at a time. /// for adding/removing multiple items at a time.
/// </summary> /// </summary>
public class ChildrenCollection<T>: Collection<T>, INotifyCollectionChanged // TODO: Specialize
public class AXmlObjectCollection<T>: Collection<T>, INotifyCollectionChanged
{ {
/// <summary> Occurs when the collection is changed </summary> /// <summary> Occurs when the collection is changed </summary>
public event NotifyCollectionChangedEventHandler CollectionChanged; public event NotifyCollectionChangedEventHandler CollectionChanged;

Просмотреть файл

@ -14,12 +14,12 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> Holds event args for event caused by <see cref="RawObject"/> </summary> /// <summary> Holds event args for event caused by <see cref="AXmlObject"/> </summary>
public class RawObjectEventArgs: EventArgs public class AXmlObjectEventArgs: EventArgs
{ {
/// <summary> The object that caused the event </summary> /// <summary> The object that caused the event </summary>
public RawObject Object { get; set; } public AXmlObject Object { get; set; }
} }
} }

Просмотреть файл

@ -11,7 +11,7 @@ using System.Diagnostics;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Creates object tree from XML document. /// Creates object tree from XML document.
@ -84,10 +84,10 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// the context is appropriate for reading. /// the context is appropriate for reading.
/// ///
/// </remarks> /// </remarks>
public class XmlParser public class AXmlParser
{ {
string input; string input;
RawDocument userDocument; AXmlDocument userDocument;
TextDocument textDocument; TextDocument textDocument;
List<DocumentChangeEventArgs> changesSinceLastParse = new List<DocumentChangeEventArgs>(); List<DocumentChangeEventArgs> changesSinceLastParse = new List<DocumentChangeEventArgs>();
@ -100,10 +100,10 @@ namespace ICSharpCode.AvalonEdit.XmlParser
public bool EntityReferenceIsError { get; set; } public bool EntityReferenceIsError { get; set; }
/// <summary> Create new parser </summary> /// <summary> Create new parser </summary>
public XmlParser(string input) public AXmlParser(string input)
{ {
this.input = input; this.input = input;
this.userDocument = new RawDocument() { Parser = this }; this.userDocument = new AXmlDocument() { Parser = this };
this.EntityReferenceIsError = true; this.EntityReferenceIsError = true;
this.Cache = new Cache(); this.Cache = new Cache();
} }
@ -111,7 +111,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary> /// <summary>
/// Create new parser, but do not parse the text yet. /// Create new parser, but do not parse the text yet.
/// </summary> /// </summary>
public XmlParser(TextDocument textDocument): this(textDocument.Text) public AXmlParser(TextDocument textDocument): this(textDocument.Text)
{ {
this.textDocument = textDocument; this.textDocument = textDocument;
this.textDocument.Changed += delegate(object sender, DocumentChangeEventArgs e) { this.textDocument.Changed += delegate(object sender, DocumentChangeEventArgs e) {
@ -144,7 +144,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary> /// <summary>
/// Incrementaly parse the document /// Incrementaly parse the document
/// </summary> /// </summary>
public RawDocument Parse() public AXmlDocument Parse()
{ {
// Update source text // Update source text
if (textDocument != null) { if (textDocument != null) {
@ -156,11 +156,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
changesSinceLastParse.Clear(); changesSinceLastParse.Clear();
TagReader tagReader = new TagReader(this, input); TagReader tagReader = new TagReader(this, input);
List<RawObject> tags = tagReader.ReadAllTags(); List<AXmlObject> tags = tagReader.ReadAllTags();
RawDocument parsedDocument = new TagMatchingHeuristics(this, input, tags).ReadDocument(); AXmlDocument parsedDocument = new TagMatchingHeuristics(this, input, tags).ReadDocument();
parsedDocument.DebugCheckConsistency(true); parsedDocument.DebugCheckConsistency(true);
tagReader.PrintStringCacheStats(); tagReader.PrintStringCacheStats();
RawObject.LogDom("Updating main DOM tree..."); AXmlObject.LogDom("Updating main DOM tree...");
userDocument.UpdateTreeFrom(parsedDocument); userDocument.UpdateTreeFrom(parsedDocument);
userDocument.DebugCheckConsistency(false); userDocument.DebugCheckConsistency(false);
return userDocument; return userDocument;

Просмотреть файл

@ -14,12 +14,12 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Represents any markup starting with "&lt;" and (hopefully) ending with ">" /// Represents any markup starting with "&lt;" and (hopefully) ending with ">"
/// </summary> /// </summary>
public class RawTag: RawContainer public class AXmlTag: AXmlContainer
{ {
/// <summary> These identify the start of DTD elements </summary> /// <summary> These identify the start of DTD elements </summary>
public static readonly string[] DTDNames = new string[] {"<!DOCTYPE", "<!NOTATION", "<!ELEMENT", "<!ATTLIST", "<!ENTITY"}; public static readonly string[] DTDNames = new string[] {"<!DOCTYPE", "<!NOTATION", "<!ELEMENT", "<!ATTLIST", "<!ENTITY"};
@ -55,24 +55,24 @@ namespace ICSharpCode.AvalonEdit.XmlParser
Assert(OpeningBracket != null, "Null OpeningBracket"); Assert(OpeningBracket != null, "Null OpeningBracket");
Assert(Name != null, "Null Name"); Assert(Name != null, "Null Name");
Assert(ClosingBracket != null, "Null ClosingBracket"); Assert(ClosingBracket != null, "Null ClosingBracket");
foreach(RawObject child in this.Children) { foreach(AXmlObject child in this.Children) {
Assert(child is RawText || child is RawAttribute, "Only attribute or text children allowed"); Assert(child is AXmlText || child is AXmlAttribute, "Only attribute or text children allowed");
} }
base.DebugCheckConsistency(allowNullParent); base.DebugCheckConsistency(allowNullParent);
} }
/// <inheritdoc/> /// <inheritdoc/>
public override void AcceptVisitor(IXmlVisitor visitor) public override void AcceptVisitor(IAXmlVisitor visitor)
{ {
visitor.VisitTag(this); visitor.VisitTag(this);
} }
/// <inheritdoc/> /// <inheritdoc/>
internal override void UpdateDataFrom(RawObject source) internal override void UpdateDataFrom(AXmlObject source)
{ {
base.UpdateDataFrom(source); // Check asserts base.UpdateDataFrom(source); // Check asserts
if (this.LastUpdatedFrom == source) return; if (this.LastUpdatedFrom == source) return;
RawTag src = (RawTag)source; AXmlTag src = (AXmlTag)source;
if (this.OpeningBracket != src.OpeningBracket || if (this.OpeningBracket != src.OpeningBracket ||
this.Name != src.Name || this.Name != src.Name ||
this.ClosingBracket != src.ClosingBracket) this.ClosingBracket != src.ClosingBracket)

Просмотреть файл

@ -14,32 +14,32 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Whitespace or character data /// Whitespace or character data
/// </summary> /// </summary>
public class RawText: RawObject public class AXmlText: AXmlObject
{ {
/// <summary> The context in which the text occured </summary> /// <summary> The context in which the text occured </summary>
public RawTextType Type { get; set; } internal TextType Type { get; set; }
/// <summary> The text exactly as in source </summary> /// <summary> The text exactly as in source </summary>
public string EscapedValue { get; set; } public string EscapedValue { get; set; }
/// <summary> The text with all entity references resloved </summary> /// <summary> The text with all entity references resloved </summary>
public string Value { get; set; } public string Value { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public override void AcceptVisitor(IXmlVisitor visitor) public override void AcceptVisitor(IAXmlVisitor visitor)
{ {
visitor.VisitText(this); visitor.VisitText(this);
} }
/// <inheritdoc/> /// <inheritdoc/>
internal override void UpdateDataFrom(RawObject source) internal override void UpdateDataFrom(AXmlObject source)
{ {
base.UpdateDataFrom(source); // Check asserts base.UpdateDataFrom(source); // Check asserts
if (this.LastUpdatedFrom == source) return; if (this.LastUpdatedFrom == source) return;
RawText src = (RawText)source; AXmlText src = (AXmlText)source;
if (this.EscapedValue != src.EscapedValue || if (this.EscapedValue != src.EscapedValue ||
this.Value != src.Value) this.Value != src.Value)
{ {
@ -56,29 +56,4 @@ namespace ICSharpCode.AvalonEdit.XmlParser
return string.Format("[{0} Text.Length={1}]", base.ToString(), this.EscapedValue.Length); return string.Format("[{0} Text.Length={1}]", base.ToString(), this.EscapedValue.Length);
} }
} }
/// <summary> Identifies the context in which the text occured </summary>
public enum RawTextType
{
/// <summary> Ends with non-whitespace </summary>
WhiteSpace,
/// <summary> Ends with "&lt;"; "]]&gt;" is error </summary>
CharacterData,
/// <summary> Ends with "-->"; "--" is error </summary>
Comment,
/// <summary> Ends with "]]&gt;" </summary>
CData,
/// <summary> Ends with "?>" </summary>
ProcessingInstruction,
/// <summary> Ends with "&lt;" or ">" </summary>
UnknownBang,
/// <summary> Unknown </summary>
Other
}
} }

Просмотреть файл

@ -7,39 +7,39 @@
using System; using System;
using System.Text; using System.Text;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Derive from this class to create visitor for the XML tree /// Derive from this class to create visitor for the XML tree
/// </summary> /// </summary>
public abstract class AbstractXmlVisitor : IXmlVisitor public abstract class AbstractAXmlVisitor : IAXmlVisitor
{ {
/// <summary> Visit RawDocument </summary> /// <summary> Visit RawDocument </summary>
public virtual void VisitDocument(RawDocument document) public virtual void VisitDocument(AXmlDocument document)
{ {
foreach(RawObject child in document.Children) child.AcceptVisitor(this); foreach(AXmlObject child in document.Children) child.AcceptVisitor(this);
} }
/// <summary> Visit RawElement </summary> /// <summary> Visit RawElement </summary>
public virtual void VisitElement(RawElement element) public virtual void VisitElement(AXmlElement element)
{ {
foreach(RawObject child in element.Children) child.AcceptVisitor(this); foreach(AXmlObject child in element.Children) child.AcceptVisitor(this);
} }
/// <summary> Visit RawTag </summary> /// <summary> Visit RawTag </summary>
public virtual void VisitTag(RawTag tag) public virtual void VisitTag(AXmlTag tag)
{ {
foreach(RawObject child in tag.Children) child.AcceptVisitor(this); foreach(AXmlObject child in tag.Children) child.AcceptVisitor(this);
} }
/// <summary> Visit RawAttribute </summary> /// <summary> Visit RawAttribute </summary>
public virtual void VisitAttribute(RawAttribute attribute) public virtual void VisitAttribute(AXmlAttribute attribute)
{ {
} }
/// <summary> Visit RawText </summary> /// <summary> Visit RawText </summary>
public virtual void VisitText(RawText text) public virtual void VisitText(AXmlText text)
{ {
} }

Просмотреть файл

@ -9,7 +9,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Holds all valid parsed items. /// Holds all valid parsed items.
@ -18,7 +18,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
class Cache class Cache
{ {
/// <summary> Previously parsed items as long as they are valid </summary> /// <summary> Previously parsed items as long as they are valid </summary>
TextSegmentCollection<RawObject> parsedItems = new TextSegmentCollection<RawObject>(); TextSegmentCollection<AXmlObject> parsedItems = new TextSegmentCollection<AXmlObject>();
/// <summary> /// <summary>
/// Is used to identify what memory range was touched by object /// Is used to identify what memory range was touched by object
@ -28,7 +28,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
class TouchedMemoryRange: TextSegment class TouchedMemoryRange: TextSegment
{ {
public RawObject TouchedByObject { get; set; } public AXmlObject TouchedByObject { get; set; }
} }
public void UpdateOffsetsAndInvalidate(IEnumerable<DocumentChangeEventArgs> changes) public void UpdateOffsetsAndInvalidate(IEnumerable<DocumentChangeEventArgs> changes)
@ -39,15 +39,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
touchedMemoryRanges.UpdateOffsets(change); touchedMemoryRanges.UpdateOffsets(change);
// Remove any items affected by the change // Remove any items affected by the change
XmlParser.Log("Changed offset {0}", change.Offset); AXmlParser.Log("Changed offset {0}", change.Offset);
// Removing will cause one of the ends to be set to change.Offset // Removing will cause one of the ends to be set to change.Offset
// FindSegmentsContaining includes any segments touching // FindSegmentsContaining includes any segments touching
// so that conviniently takes care of the +1 byte // so that conviniently takes care of the +1 byte
foreach(RawObject obj in parsedItems.FindSegmentsContaining(change.Offset)) { foreach(AXmlObject obj in parsedItems.FindSegmentsContaining(change.Offset)) {
Remove(obj, false); Remove(obj, false);
} }
foreach(TouchedMemoryRange memory in touchedMemoryRanges.FindSegmentsContaining(change.Offset)) { foreach(TouchedMemoryRange memory in touchedMemoryRanges.FindSegmentsContaining(change.Offset)) {
XmlParser.Log("Found that {0} dependeds on memory ({1}-{2})", memory.TouchedByObject, memory.StartOffset, memory.EndOffset); AXmlParser.Log("Found that {0} dependeds on memory ({1}-{2})", memory.TouchedByObject, memory.StartOffset, memory.EndOffset);
Remove(memory.TouchedByObject, true); Remove(memory.TouchedByObject, true);
touchedMemoryRanges.Remove(memory); touchedMemoryRanges.Remove(memory);
} }
@ -55,14 +55,14 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Add object to cache, optionally adding extra memory tracking </summary> /// <summary> Add object to cache, optionally adding extra memory tracking </summary>
public void Add(RawObject obj, int? maxTouchedLocation) public void Add(AXmlObject obj, int? maxTouchedLocation)
{ {
XmlParser.Assert(obj.Length > 0 || obj is RawDocument, string.Format("Invalid object {0}. It has zero length.", obj)); AXmlParser.Assert(obj.Length > 0 || obj is AXmlDocument, string.Format("Invalid object {0}. It has zero length.", obj));
if (obj is RawContainer) { if (obj is AXmlContainer) {
int objStartOffset = obj.StartOffset; int objStartOffset = obj.StartOffset;
int objEndOffset = obj.EndOffset; int objEndOffset = obj.EndOffset;
foreach(RawObject child in ((RawContainer)obj).Children) { foreach(AXmlObject child in ((AXmlContainer)obj).Children) {
XmlParser.Assert(objStartOffset <= child.StartOffset && child.EndOffset <= objEndOffset, "Wrong nesting"); AXmlParser.Assert(objStartOffset <= child.StartOffset && child.EndOffset <= objEndOffset, "Wrong nesting");
} }
} }
parsedItems.Add(obj); parsedItems.Add(obj);
@ -76,14 +76,14 @@ namespace ICSharpCode.AvalonEdit.XmlParser
TouchedByObject = obj TouchedByObject = obj
}; };
touchedMemoryRanges.Add(memRange); touchedMemoryRanges.Add(memRange);
XmlParser.Log("{0} touched memory range ({1}-{2})", obj, memRange.StartOffset, memRange.EndOffset); AXmlParser.Log("{0} touched memory range ({1}-{2})", obj, memRange.StartOffset, memRange.EndOffset);
} }
} }
List<RawObject> FindParents(RawObject child) List<AXmlObject> FindParents(AXmlObject child)
{ {
List<RawObject> parents = new List<RawObject>(); List<AXmlObject> parents = new List<AXmlObject>();
foreach(RawObject parent in parsedItems.FindSegmentsContaining(child.StartOffset)) { foreach(AXmlObject parent in parsedItems.FindSegmentsContaining(child.StartOffset)) {
// Parent is anyone wholy containg the child // Parent is anyone wholy containg the child
if (parent.StartOffset <= child.StartOffset && child.EndOffset <= parent.EndOffset && parent != child) { if (parent.StartOffset <= child.StartOffset && child.EndOffset <= parent.EndOffset && parent != child) {
parents.Add(parent); parents.Add(parent);
@ -93,28 +93,28 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Remove from cache </summary> /// <summary> Remove from cache </summary>
public void Remove(RawObject obj, bool includeParents) public void Remove(AXmlObject obj, bool includeParents)
{ {
if (includeParents) { if (includeParents) {
List<RawObject> parents = FindParents(obj); List<AXmlObject> parents = FindParents(obj);
foreach(RawObject r in parents) { foreach(AXmlObject r in parents) {
if (parsedItems.Remove(r)) { if (parsedItems.Remove(r)) {
r.IsInCache = false; r.IsInCache = false;
XmlParser.Log("Removing cached item {0} (it is parent)", r); AXmlParser.Log("Removing cached item {0} (it is parent)", r);
} }
} }
} }
if (parsedItems.Remove(obj)) { if (parsedItems.Remove(obj)) {
obj.IsInCache = false; obj.IsInCache = false;
XmlParser.Log("Removed cached item {0}", obj); AXmlParser.Log("Removed cached item {0}", obj);
} }
} }
public T GetObject<T>(int offset, int lookaheadCount, Predicate<T> conditon) where T: RawObject, new() public T GetObject<T>(int offset, int lookaheadCount, Predicate<T> conditon) where T: AXmlObject, new()
{ {
RawObject obj = parsedItems.FindFirstSegmentWithStartAfter(offset); AXmlObject obj = parsedItems.FindFirstSegmentWithStartAfter(offset);
while(obj != null && offset <= obj.StartOffset && obj.StartOffset <= offset + lookaheadCount) { while(obj != null && offset <= obj.StartOffset && obj.StartOffset <= offset + lookaheadCount) {
if (obj is T && conditon((T)obj)) { if (obj is T && conditon((T)obj)) {
return (T)obj; return (T)obj;

Просмотреть файл

@ -14,7 +14,7 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
static class ExtensionMethods static class ExtensionMethods
{ {

Просмотреть файл

@ -11,7 +11,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Collection that presents only some items from the wrapped collection. /// Collection that presents only some items from the wrapped collection.

Просмотреть файл

@ -7,26 +7,26 @@
using System; using System;
using System.Text; using System.Text;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Visitor for the XML tree /// Visitor for the XML tree
/// </summary> /// </summary>
public interface IXmlVisitor public interface IAXmlVisitor
{ {
/// <summary> Visit RawDocument </summary> /// <summary> Visit RawDocument </summary>
void VisitDocument(RawDocument document); void VisitDocument(AXmlDocument document);
/// <summary> Visit RawElement </summary> /// <summary> Visit RawElement </summary>
void VisitElement(RawElement element); void VisitElement(AXmlElement element);
/// <summary> Visit RawTag </summary> /// <summary> Visit RawTag </summary>
void VisitTag(RawTag tag); void VisitTag(AXmlTag tag);
/// <summary> Visit RawAttribute </summary> /// <summary> Visit RawAttribute </summary>
void VisitAttribute(RawAttribute attribute); void VisitAttribute(AXmlAttribute attribute);
/// <summary> Visit RawText </summary> /// <summary> Visit RawText </summary>
void VisitText(RawText text); void VisitText(AXmlText text);
} }
} }

Просмотреть файл

@ -10,7 +10,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Two collections in sequence /// Two collections in sequence

Просмотреть файл

@ -7,13 +7,13 @@
using System; using System;
using System.Text; using System.Text;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> /// <summary>
/// Converts the XML tree back to text. /// Converts the XML tree back to text.
/// The text should exactly match the original. /// The text should exactly match the original.
/// </summary> /// </summary>
public class PrettyPrintXmlVisitor: AbstractXmlVisitor public class PrettyPrintAXmlVisitor: AbstractAXmlVisitor
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -27,19 +27,19 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Visit RawDocument </summary> /// <summary> Visit RawDocument </summary>
public override void VisitDocument(RawDocument document) public override void VisitDocument(AXmlDocument document)
{ {
base.VisitDocument(document); base.VisitDocument(document);
} }
/// <summary> Visit RawElement </summary> /// <summary> Visit RawElement </summary>
public override void VisitElement(RawElement element) public override void VisitElement(AXmlElement element)
{ {
base.VisitElement(element); base.VisitElement(element);
} }
/// <summary> Visit RawTag </summary> /// <summary> Visit RawTag </summary>
public override void VisitTag(RawTag tag) public override void VisitTag(AXmlTag tag)
{ {
sb.Append(tag.OpeningBracket); sb.Append(tag.OpeningBracket);
sb.Append(tag.Name); sb.Append(tag.Name);
@ -48,7 +48,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Visit RawAttribute </summary> /// <summary> Visit RawAttribute </summary>
public override void VisitAttribute(RawAttribute attribute) public override void VisitAttribute(AXmlAttribute attribute)
{ {
sb.Append(attribute.Name); sb.Append(attribute.Name);
sb.Append(attribute.EqualsSign); sb.Append(attribute.EqualsSign);
@ -56,7 +56,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
/// <summary> Visit RawText </summary> /// <summary> Visit RawText </summary>
public override void VisitText(RawText text) public override void VisitText(AXmlText text)
{ {
sb.Append(text.EscapedValue); sb.Append(text.EscapedValue);
} }

Просмотреть файл

@ -14,19 +14,19 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
/// <summary> Information about syntax error that occured during parsing </summary> /// <summary> Information about syntax error that occured during parsing </summary>
public class SyntaxError: TextSegment public class SyntaxError: TextSegment
{ {
/// <summary> Object for which the error occured </summary> /// <summary> Object for which the error occured </summary>
public RawObject Object { get; internal set; } public AXmlObject Object { get; internal set; }
/// <summary> Textual description of the error </summary> /// <summary> Textual description of the error </summary>
public string Message { get; internal set; } public string Message { get; internal set; }
/// <summary> Any user data </summary> /// <summary> Any user data </summary>
public object Tag { get; set; } public object Tag { get; set; }
internal SyntaxError Clone(RawObject newOwner) internal SyntaxError Clone(AXmlObject newOwner)
{ {
return new SyntaxError { return new SyntaxError {
Object = newOwner, Object = newOwner,

Просмотреть файл

@ -12,18 +12,18 @@ using System.Text;
using ICSharpCode.AvalonEdit.Utils; using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
class TagMatchingHeuristics class TagMatchingHeuristics
{ {
const int maxConfigurationCount = 10; const int maxConfigurationCount = 10;
XmlParser parser; AXmlParser parser;
Cache cache; Cache cache;
string input; string input;
List<RawObject> tags; List<AXmlObject> tags;
public TagMatchingHeuristics(XmlParser parser, string input, List<RawObject> tags) public TagMatchingHeuristics(AXmlParser parser, string input, List<AXmlObject> tags)
{ {
this.parser = parser; this.parser = parser;
this.cache = parser.Cache; this.cache = parser.Cache;
@ -31,14 +31,14 @@ namespace ICSharpCode.AvalonEdit.XmlParser
this.tags = tags; this.tags = tags;
} }
public RawDocument ReadDocument() public AXmlDocument ReadDocument()
{ {
RawDocument doc = new RawDocument() { Parser = parser }; AXmlDocument doc = new AXmlDocument() { Parser = parser };
XmlParser.Log("Flat stream: {0}", PrintObjects(tags)); AXmlParser.Log("Flat stream: {0}", PrintObjects(tags));
List<RawObject> valid = MatchTags(tags); List<AXmlObject> valid = MatchTags(tags);
XmlParser.Log("Fixed stream: {0}", PrintObjects(valid)); AXmlParser.Log("Fixed stream: {0}", PrintObjects(valid));
IEnumerator<RawObject> validStream = valid.GetEnumerator(); IEnumerator<AXmlObject> validStream = valid.GetEnumerator();
validStream.MoveNext(); // Move to first validStream.MoveNext(); // Move to first
while(true) { while(true) {
// End of stream? // End of stream?
@ -55,25 +55,25 @@ namespace ICSharpCode.AvalonEdit.XmlParser
doc.EndOffset = doc.LastChild.EndOffset; doc.EndOffset = doc.LastChild.EndOffset;
} }
XmlParser.Log("Constructed {0}", doc); AXmlParser.Log("Constructed {0}", doc);
cache.Add(doc, null); cache.Add(doc, null);
return doc; return doc;
} }
RawObject ReadSingleObject(IEnumerator<RawObject> objStream) AXmlObject ReadSingleObject(IEnumerator<AXmlObject> objStream)
{ {
RawObject obj = objStream.Current; AXmlObject obj = objStream.Current;
objStream.MoveNext(); objStream.MoveNext();
return obj; return obj;
} }
RawObject ReadTextOrElement(IEnumerator<RawObject> objStream) AXmlObject ReadTextOrElement(IEnumerator<AXmlObject> objStream)
{ {
RawObject curr = objStream.Current; AXmlObject curr = objStream.Current;
if (curr is RawText || curr is RawElement) { if (curr is AXmlText || curr is AXmlElement) {
return ReadSingleObject(objStream); return ReadSingleObject(objStream);
} else { } else {
RawTag currTag = (RawTag)curr; AXmlTag currTag = (AXmlTag)curr;
if (currTag == StartTagPlaceholder) { if (currTag == StartTagPlaceholder) {
return ReadElement(objStream); return ReadElement(objStream);
} else if (currTag.IsStartOrEmptyTag) { } else if (currTag.IsStartOrEmptyTag) {
@ -84,15 +84,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
} }
RawElement ReadElement(IEnumerator<RawObject> objStream) AXmlElement ReadElement(IEnumerator<AXmlObject> objStream)
{ {
RawElement element = new RawElement(); AXmlElement element = new AXmlElement();
element.IsProperlyNested = true; element.IsProperlyNested = true;
// Read start tag // Read start tag
RawTag startTag = ReadSingleObject(objStream) as RawTag; AXmlTag startTag = ReadSingleObject(objStream) as AXmlTag;
XmlParser.DebugAssert(startTag != null, "Start tag expected"); AXmlParser.DebugAssert(startTag != null, "Start tag expected");
XmlParser.DebugAssert(startTag.IsStartOrEmptyTag || startTag == StartTagPlaceholder, "Start tag expected"); AXmlParser.DebugAssert(startTag.IsStartOrEmptyTag || startTag == StartTagPlaceholder, "Start tag expected");
if (startTag == StartTagPlaceholder) { if (startTag == StartTagPlaceholder) {
element.HasStartOrEmptyTag = false; element.HasStartOrEmptyTag = false;
element.IsProperlyNested = false; element.IsProperlyNested = false;
@ -106,7 +106,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// Read content and end tag // Read content and end tag
if (element.StartTag.IsStartTag || startTag == StartTagPlaceholder) { if (element.StartTag.IsStartTag || startTag == StartTagPlaceholder) {
while(true) { while(true) {
RawTag currTag = objStream.Current as RawTag; // Peek AXmlTag currTag = objStream.Current as AXmlTag; // Peek
if (currTag == EndTagPlaceholder) { if (currTag == EndTagPlaceholder) {
TagReader.OnSyntaxError(element, element.LastChild.EndOffset, element.LastChild.EndOffset, TagReader.OnSyntaxError(element, element.LastChild.EndOffset, element.LastChild.EndOffset,
"Expected '</{0}>'", element.StartTag.Name); "Expected '</{0}>'", element.StartTag.Name);
@ -123,11 +123,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
element.HasEndTag = true; element.HasEndTag = true;
break; break;
} }
RawObject nested = ReadTextOrElement(objStream); AXmlObject nested = ReadTextOrElement(objStream);
if (nested is RawElement) { if (nested is AXmlElement) {
if (!((RawElement)nested).IsProperlyNested) if (!((AXmlElement)nested).IsProperlyNested)
element.IsProperlyNested = false; element.IsProperlyNested = false;
element.AddChildren(Split((RawElement)nested).ToList()); element.AddChildren(Split((AXmlElement)nested).ToList());
} else { } else {
element.AddChild(nested); element.AddChild(nested);
} }
@ -139,20 +139,20 @@ namespace ICSharpCode.AvalonEdit.XmlParser
element.StartOffset = element.FirstChild.StartOffset; element.StartOffset = element.FirstChild.StartOffset;
element.EndOffset = element.LastChild.EndOffset; element.EndOffset = element.LastChild.EndOffset;
XmlParser.Log("Constructed {0}", element); AXmlParser.Log("Constructed {0}", element);
cache.Add(element, null); // Need all elements in cache for offset tracking cache.Add(element, null); // Need all elements in cache for offset tracking
return element; return element;
} }
IEnumerable<RawObject> Split(RawElement elem) IEnumerable<AXmlObject> Split(AXmlElement elem)
{ {
int myIndention = GetIndentLevel(elem); int myIndention = GetIndentLevel(elem);
// If has virtual end and is indented // If has virtual end and is indented
if (!elem.HasEndTag && myIndention != -1) { if (!elem.HasEndTag && myIndention != -1) {
int lastAccepted = 0; // Accept start tag int lastAccepted = 0; // Accept start tag
while (lastAccepted + 1 < elem.Children.Count - 1 /* no end tag */) { while (lastAccepted + 1 < elem.Children.Count - 1 /* no end tag */) {
RawObject nextItem = elem.Children[lastAccepted + 1]; AXmlObject nextItem = elem.Children[lastAccepted + 1];
if (nextItem is RawText) { if (nextItem is AXmlText) {
lastAccepted++; continue; // Accept lastAccepted++; continue; // Accept
} else { } else {
// Include all more indented items // Include all more indented items
@ -168,8 +168,8 @@ namespace ICSharpCode.AvalonEdit.XmlParser
yield return elem; yield return elem;
yield break; yield break;
} }
XmlParser.Log("Splitting {0} - take {1} of {2} nested", elem, lastAccepted, elem.Children.Count - 2); AXmlParser.Log("Splitting {0} - take {1} of {2} nested", elem, lastAccepted, elem.Children.Count - 2);
RawElement topHalf = new RawElement(); AXmlElement topHalf = new AXmlElement();
topHalf.HasStartOrEmptyTag = elem.HasStartOrEmptyTag; topHalf.HasStartOrEmptyTag = elem.HasStartOrEmptyTag;
topHalf.HasEndTag = elem.HasEndTag; topHalf.HasEndTag = elem.HasEndTag;
topHalf.AddChildren(elem.Children.Take(lastAccepted + 1)); // Start tag + nested topHalf.AddChildren(elem.Children.Take(lastAccepted + 1)); // Start tag + nested
@ -178,7 +178,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
TagReader.OnSyntaxError(topHalf, topHalf.LastChild.EndOffset, topHalf.LastChild.EndOffset, TagReader.OnSyntaxError(topHalf, topHalf.LastChild.EndOffset, topHalf.LastChild.EndOffset,
"Expected '</{0}>'", topHalf.StartTag.Name); "Expected '</{0}>'", topHalf.StartTag.Name);
XmlParser.Log("Constructed {0}", topHalf); AXmlParser.Log("Constructed {0}", topHalf);
cache.Add(topHalf, null); cache.Add(topHalf, null);
yield return topHalf; yield return topHalf;
for(int i = lastAccepted + 1; i < elem.Children.Count - 1; i++) { for(int i = lastAccepted + 1; i < elem.Children.Count - 1; i++) {
@ -189,7 +189,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
} }
int GetIndentLevel(RawObject obj) int GetIndentLevel(AXmlObject obj)
{ {
int offset = obj.StartOffset - 1; int offset = obj.StartOffset - 1;
int level = 0; int level = 0;
@ -217,9 +217,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
class Configuration class Configuration
{ {
/// <summary> Unmatched start tags </summary> /// <summary> Unmatched start tags </summary>
public ImmutableStack<RawTag> StartTags { get; set; } public ImmutableStack<AXmlTag> StartTags { get; set; }
/// <summary> Properly nested tags </summary> /// <summary> Properly nested tags </summary>
public ImmutableStack<RawObject> Document { get; set; } public ImmutableStack<AXmlObject> Document { get; set; }
/// <summary> Number of needed modificaitons to the document </summary> /// <summary> Number of needed modificaitons to the document </summary>
public int Cost { get; set; } public int Cost { get; set; }
} }
@ -227,7 +227,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary> /// <summary>
/// Dictionary which stores the cheapest configuration /// Dictionary which stores the cheapest configuration
/// </summary> /// </summary>
class Configurations: Dictionary<ImmutableStack<RawTag>, Configuration> class Configurations: Dictionary<ImmutableStack<AXmlTag>, Configuration>
{ {
public Configurations() public Configurations()
{ {
@ -258,7 +258,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach(var kvp in this) { foreach(var kvp in this) {
sb.Append("\n - '"); sb.Append("\n - '");
foreach(RawTag startTag in kvp.Value.StartTags.Reverse()) { foreach(AXmlTag startTag in kvp.Value.StartTags.Reverse()) {
sb.Append('<'); sb.Append('<');
sb.Append(startTag.Name); sb.Append(startTag.Name);
sb.Append('>'); sb.Append('>');
@ -270,21 +270,21 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
// Tags used to guide the element creation // Tags used to guide the element creation
readonly RawTag StartTagPlaceholder = new RawTag(); readonly AXmlTag StartTagPlaceholder = new AXmlTag();
readonly RawTag EndTagPlaceholder = new RawTag(); readonly AXmlTag EndTagPlaceholder = new AXmlTag();
/// <summary> /// <summary>
/// Add start or end tag placeholders so that the documment is properly nested /// Add start or end tag placeholders so that the documment is properly nested
/// </summary> /// </summary>
List<RawObject> MatchTags(IEnumerable<RawObject> objs) List<AXmlObject> MatchTags(IEnumerable<AXmlObject> objs)
{ {
Configurations configurations = new Configurations(); Configurations configurations = new Configurations();
configurations.Add(new Configuration { configurations.Add(new Configuration {
StartTags = ImmutableStack<RawTag>.Empty, StartTags = ImmutableStack<AXmlTag>.Empty,
Document = ImmutableStack<RawObject>.Empty, Document = ImmutableStack<AXmlObject>.Empty,
Cost = 0, Cost = 0,
}); });
foreach(RawObject obj in objs) { foreach(AXmlObject obj in objs) {
configurations = ProcessObject(configurations, obj); configurations = ProcessObject(configurations, obj);
} }
// Close any remaining start tags // Close any remaining start tags
@ -295,22 +295,22 @@ namespace ICSharpCode.AvalonEdit.XmlParser
conifg.Cost += 1; conifg.Cost += 1;
} }
} }
XmlParser.Log("Configurations after closing all remaining tags:" + configurations.ToString()); AXmlParser.Log("Configurations after closing all remaining tags:" + configurations.ToString());
Configuration bestConfig = configurations.Values.OrderBy(v => v.Cost).First(); Configuration bestConfig = configurations.Values.OrderBy(v => v.Cost).First();
XmlParser.Log("Best configuration has cost {0}", bestConfig.Cost); AXmlParser.Log("Best configuration has cost {0}", bestConfig.Cost);
return bestConfig.Document.Reverse().ToList(); return bestConfig.Document.Reverse().ToList();
} }
/// <summary> Get posible configurations after considering fiven object </summary> /// <summary> Get posible configurations after considering fiven object </summary>
Configurations ProcessObject(Configurations oldConfigs, RawObject obj) Configurations ProcessObject(Configurations oldConfigs, AXmlObject obj)
{ {
XmlParser.Log("Processing {0}", obj); AXmlParser.Log("Processing {0}", obj);
RawTag tag = obj as RawTag; AXmlTag tag = obj as AXmlTag;
XmlParser.Assert(obj is RawTag || obj is RawText || obj is RawElement, obj.GetType().Name + " not expected"); AXmlParser.Assert(obj is AXmlTag || obj is AXmlText || obj is AXmlElement, obj.GetType().Name + " not expected");
if (obj is RawElement) if (obj is AXmlElement)
XmlParser.Assert(((RawElement)obj).IsProperlyNested, "Element not proprly nested"); AXmlParser.Assert(((AXmlElement)obj).IsProperlyNested, "Element not proprly nested");
Configurations newConfigs = new Configurations(); Configurations newConfigs = new Configurations();
@ -342,7 +342,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
int popedCount = 0; int popedCount = 0;
var startTags = oldStartTags; var startTags = oldStartTags;
var doc = oldDocument; var doc = oldDocument;
foreach(RawTag poped in oldStartTags) { foreach(AXmlTag poped in oldStartTags) {
popedCount++; popedCount++;
if (poped.Name == tag.Name) { if (poped.Name == tag.Name) {
newConfigs.Add(new Configuration { // Pop 'x' items (cost x-1) - last one is matching newConfigs.Add(new Configuration { // Pop 'x' items (cost x-1) - last one is matching
@ -370,32 +370,32 @@ namespace ICSharpCode.AvalonEdit.XmlParser
newConfigs.Values.OrderBy(v => v.Cost).Take(maxConfigurationCount) newConfigs.Values.OrderBy(v => v.Cost).Take(maxConfigurationCount)
); );
XmlParser.Log("Best new configurations:" + bestNewConfigurations.ToString()); AXmlParser.Log("Best new configurations:" + bestNewConfigurations.ToString());
return bestNewConfigurations; return bestNewConfigurations;
} }
#region Helper methods #region Helper methods
string PrintObjects(IEnumerable<RawObject> objs) string PrintObjects(IEnumerable<AXmlObject> objs)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach(RawObject obj in objs) { foreach(AXmlObject obj in objs) {
if (obj is RawTag) { if (obj is AXmlTag) {
if (obj == StartTagPlaceholder) { if (obj == StartTagPlaceholder) {
sb.Append("#StartTag#"); sb.Append("#StartTag#");
} else if (obj == EndTagPlaceholder) { } else if (obj == EndTagPlaceholder) {
sb.Append("#EndTag#"); sb.Append("#EndTag#");
} else { } else {
sb.Append(((RawTag)obj).OpeningBracket); sb.Append(((AXmlTag)obj).OpeningBracket);
sb.Append(((RawTag)obj).Name); sb.Append(((AXmlTag)obj).Name);
sb.Append(((RawTag)obj).ClosingBracket); sb.Append(((AXmlTag)obj).ClosingBracket);
} }
} else if (obj is RawElement) { } else if (obj is AXmlElement) {
sb.Append('['); sb.Append('[');
sb.Append(PrintObjects(((RawElement)obj).Children)); sb.Append(PrintObjects(((AXmlElement)obj).Children));
sb.Append(']'); sb.Append(']');
} else if (obj is RawText) { } else if (obj is AXmlText) {
sb.Append('~'); sb.Append('~');
} else { } else {
throw new Exception("Should not be here: " + obj); throw new Exception("Should not be here: " + obj);

Просмотреть файл

@ -11,27 +11,27 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
class TagReader: TokenReader class TagReader: TokenReader
{ {
XmlParser parser; AXmlParser parser;
Cache cache; Cache cache;
string input; string input;
public TagReader(XmlParser parser, string input): base(input) public TagReader(AXmlParser parser, string input): base(input)
{ {
this.parser = parser; this.parser = parser;
this.cache = parser.Cache; this.cache = parser.Cache;
this.input = input; this.input = input;
} }
bool TryReadFromCacheOrNew<T>(out T res) where T: RawObject, new() bool TryReadFromCacheOrNew<T>(out T res) where T: AXmlObject, new()
{ {
return TryReadFromCacheOrNew(out res, t => true); return TryReadFromCacheOrNew(out res, t => true);
} }
bool TryReadFromCacheOrNew<T>(out T res, Predicate<T> condition) where T: RawObject, new() bool TryReadFromCacheOrNew<T>(out T res, Predicate<T> condition) where T: AXmlObject, new()
{ {
T cached = cache.GetObject<T>(this.CurrentLocation, 0, condition); T cached = cache.GetObject<T>(this.CurrentLocation, 0, condition);
if (cached != null) { if (cached != null) {
@ -44,9 +44,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
} }
void OnParsed(RawObject obj) void OnParsed(AXmlObject obj)
{ {
XmlParser.Log("Parsed {0}", obj); AXmlParser.Log("Parsed {0}", obj);
cache.Add(obj, this.MaxTouchedLocation > this.CurrentLocation ? (int?)this.MaxTouchedLocation : null); cache.Add(obj, this.MaxTouchedLocation > this.CurrentLocation ? (int?)this.MaxTouchedLocation : null);
} }
@ -54,22 +54,22 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// Read all tags in the document in a flat sequence. /// Read all tags in the document in a flat sequence.
/// It also includes the text between tags and possibly some properly nested Elements from cache. /// It also includes the text between tags and possibly some properly nested Elements from cache.
/// </summary> /// </summary>
public List<RawObject> ReadAllTags() public List<AXmlObject> ReadAllTags()
{ {
List<RawObject> stream = new List<RawObject>(); List<AXmlObject> stream = new List<AXmlObject>();
while(true) { while(true) {
if (IsEndOfFile()) { if (IsEndOfFile()) {
break; break;
} else if (TryPeek('<')) { } else if (TryPeek('<')) {
RawElement elem; AXmlElement elem;
if (TryReadFromCacheOrNew(out elem, e => e.IsProperlyNested)) { if (TryReadFromCacheOrNew(out elem, e => e.IsProperlyNested)) {
stream.Add(elem); stream.Add(elem);
} else { } else {
stream.Add(ReadTag()); stream.Add(ReadTag());
} }
} else { } else {
stream.AddRange(ReadText(RawTextType.CharacterData)); stream.AddRange(ReadText(TextType.CharacterData));
} }
} }
@ -79,11 +79,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary> /// <summary>
/// Context: "&lt;" /// Context: "&lt;"
/// </summary> /// </summary>
RawTag ReadTag() AXmlTag ReadTag()
{ {
AssertHasMoreData(); AssertHasMoreData();
RawTag tag; AXmlTag tag;
if (TryReadFromCacheOrNew(out tag)) return tag; if (TryReadFromCacheOrNew(out tag)) return tag;
tag.StartOffset = this.CurrentLocation; tag.StartOffset = this.CurrentLocation;
@ -111,7 +111,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// Chech for all forbiden 'name' charcters first - see ReadName // Chech for all forbiden 'name' charcters first - see ReadName
if (IsEndOfFile()) break; if (IsEndOfFile()) break;
if (TryPeekWhiteSpace()) { if (TryPeekWhiteSpace()) {
tag.AddChildren(ReadText(RawTextType.WhiteSpace)); tag.AddChildren(ReadText(TextType.WhiteSpace));
continue; // End of file might be next continue; // End of file might be next
} }
if (TryPeek('<')) break; if (TryPeek('<')) break;
@ -124,15 +124,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
tag.AddChildren(ReadContentOfDTD()); tag.AddChildren(ReadContentOfDTD());
} else { } else {
int start = this.CurrentLocation; int start = this.CurrentLocation;
IEnumerable<RawObject> text; IEnumerable<AXmlObject> text;
if (tag.IsComment) { if (tag.IsComment) {
text = ReadText(RawTextType.Comment); text = ReadText(TextType.Comment);
} else if (tag.IsCData) { } else if (tag.IsCData) {
text = ReadText(RawTextType.CData); text = ReadText(TextType.CData);
} else if (tag.IsProcessingInstruction) { } else if (tag.IsProcessingInstruction) {
text = ReadText(RawTextType.ProcessingInstruction); text = ReadText(TextType.ProcessingInstruction);
} else if (tag.IsUnknownBang) { } else if (tag.IsUnknownBang) {
text = ReadText(RawTextType.UnknownBang); text = ReadText(TextType.UnknownBang);
} else { } else {
throw new Exception(string.Format("Unknown opening bracket '{0}'", tag.OpeningBracket)); throw new Exception(string.Format("Unknown opening bracket '{0}'", tag.OpeningBracket));
} }
@ -175,8 +175,8 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
// Attribute name may not apper multiple times // Attribute name may not apper multiple times
var duplicates = tag.Children.OfType<RawAttribute>().GroupBy(attr => attr.Name).SelectMany(g => g.Skip(1)); var duplicates = tag.Children.OfType<AXmlAttribute>().GroupBy(attr => attr.Name).SelectMany(g => g.Skip(1));
foreach(RawAttribute attr in duplicates) { foreach(AXmlAttribute attr in duplicates) {
OnSyntaxError(tag, attr.StartOffset, attr.EndOffset, "Attribute with name '{0}' already exists", attr.Name); OnSyntaxError(tag, attr.StartOffset, attr.EndOffset, "Attribute with name '{0}' already exists", attr.Name);
} }
@ -205,7 +205,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} else if (TryRead("[CDATA[")) { } else if (TryRead("[CDATA[")) {
return "<![CDATA["; return "<![CDATA[";
} else { } else {
foreach(string dtdName in RawTag.DTDNames) { foreach(string dtdName in AXmlTag.DTDNames) {
// the dtdName includes "<!" // the dtdName includes "<!"
if (TryRead(dtdName.Remove(0, 2))) return dtdName; if (TryRead(dtdName.Remove(0, 2))) return dtdName;
} }
@ -243,7 +243,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
return true; return true;
} }
IEnumerable<RawObject> ReadContentOfDTD() IEnumerable<AXmlObject> ReadContentOfDTD()
{ {
int start = this.CurrentLocation; int start = this.CurrentLocation;
while(true) { while(true) {
@ -279,11 +279,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary> /// <summary>
/// Context: name or "=\'\"" /// Context: name or "=\'\""
/// </summary> /// </summary>
RawAttribute ReadAttribulte() AXmlAttribute ReadAttribulte()
{ {
AssertHasMoreData(); AssertHasMoreData();
RawAttribute attr; AXmlAttribute attr;
if (TryReadFromCacheOrNew(out attr)) return attr; if (TryReadFromCacheOrNew(out attr)) return attr;
attr.StartOffset = this.CurrentLocation; attr.StartOffset = this.CurrentLocation;
@ -407,15 +407,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
} }
RawText MakeText(int start, int end) AXmlText MakeText(int start, int end)
{ {
XmlParser.DebugAssert(end > start, "Empty text"); AXmlParser.DebugAssert(end > start, "Empty text");
RawText text = new RawText() { AXmlText text = new AXmlText() {
StartOffset = start, StartOffset = start,
EndOffset = end, EndOffset = end,
EscapedValue = GetText(start, end), EscapedValue = GetText(start, end),
Type = RawTextType.Other Type = TextType.Other
}; };
OnParsed(text); OnParsed(text);
@ -431,11 +431,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// It can also return empty set for no appropriate text input. /// It can also return empty set for no appropriate text input.
/// Make sure you enumerate it only once /// Make sure you enumerate it only once
/// </summary> /// </summary>
IEnumerable<RawObject> ReadText(RawTextType type) IEnumerable<AXmlObject> ReadText(TextType type)
{ {
bool lookahead = false; bool lookahead = false;
while(true) { while(true) {
RawText text; AXmlText text;
if (TryReadFromCacheOrNew(out text, t => t.Type == type)) { if (TryReadFromCacheOrNew(out text, t => t.Type == type)) {
// Cached text found // Cached text found
yield return text; yield return text;
@ -451,10 +451,10 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// we hit that chache point. It is expensive so it is off for the first run // we hit that chache point. It is expensive so it is off for the first run
if (lookahead) { if (lookahead) {
// Note: Must fit entity // Note: Must fit entity
RawObject nextFragment = cache.GetObject<RawText>(this.CurrentLocation + maxEntityLength, lookAheadLenght - maxEntityLength, t => t.Type == type); AXmlObject nextFragment = cache.GetObject<AXmlText>(this.CurrentLocation + maxEntityLength, lookAheadLenght - maxEntityLength, t => t.Type == type);
if (nextFragment != null) { if (nextFragment != null) {
fragmentEnd = Math.Min(nextFragment.StartOffset, this.InputLength); fragmentEnd = Math.Min(nextFragment.StartOffset, this.InputLength);
XmlParser.Log("Parsing only text ({0}-{1}) because later text was already processed", this.CurrentLocation, fragmentEnd); AXmlParser.Log("Parsing only text ({0}-{1}) because later text was already processed", this.CurrentLocation, fragmentEnd);
} }
} }
lookahead = true; lookahead = true;
@ -463,9 +463,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
int start = this.CurrentLocation; int start = this.CurrentLocation;
// Try move to the terminator given by the context // Try move to the terminator given by the context
if (type == RawTextType.WhiteSpace) { if (type == TextType.WhiteSpace) {
TryMoveToNonWhiteSpace(fragmentEnd); TryMoveToNonWhiteSpace(fragmentEnd);
} else if (type == RawTextType.CharacterData) { } else if (type == TextType.CharacterData) {
while(true) { while(true) {
if (!TryMoveToAnyOf(new char[] {'<', ']'}, fragmentEnd)) break; // End of fragment if (!TryMoveToAnyOf(new char[] {'<', ']'}, fragmentEnd)) break; // End of fragment
if (TryPeek('<')) break; if (TryPeek('<')) break;
@ -478,7 +478,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
throw new Exception("Infinite loop"); throw new Exception("Infinite loop");
} }
} else if (type == RawTextType.Comment) { } else if (type == TextType.Comment) {
// Do not report too many errors // Do not report too many errors
bool errorReported = false; bool errorReported = false;
while(true) { while(true) {
@ -490,20 +490,20 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
TryMoveNext(); TryMoveNext();
} }
} else if (type == RawTextType.CData) { } else if (type == TextType.CData) {
while(true) { while(true) {
// We can not use use TryMoveTo("]]>", fragmentEnd) because it may incorectly accept "]" at the end of fragment // We can not use use TryMoveTo("]]>", fragmentEnd) because it may incorectly accept "]" at the end of fragment
if (!TryMoveTo(']', fragmentEnd)) break; // End of fragment if (!TryMoveTo(']', fragmentEnd)) break; // End of fragment
if (TryPeek("]]>")) break; if (TryPeek("]]>")) break;
TryMoveNext(); TryMoveNext();
} }
} else if (type == RawTextType.ProcessingInstruction) { } else if (type == TextType.ProcessingInstruction) {
while(true) { while(true) {
if (!TryMoveTo('?', fragmentEnd)) break; // End of fragment if (!TryMoveTo('?', fragmentEnd)) break; // End of fragment
if (TryPeek("?>")) break; if (TryPeek("?>")) break;
TryMoveNext(); TryMoveNext();
} }
} else if (type == RawTextType.UnknownBang) { } else if (type == TextType.UnknownBang) {
TryMoveToAnyOf(new char[] {'<', '>'}, fragmentEnd); TryMoveToAnyOf(new char[] {'<', '>'}, fragmentEnd);
} else { } else {
throw new Exception("Uknown type " + type); throw new Exception("Uknown type " + type);
@ -528,7 +528,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
text.EscapedValue = GetText(start, this.CurrentLocation); text.EscapedValue = GetText(start, this.CurrentLocation);
if (type == RawTextType.CharacterData) { if (type == TextType.CharacterData) {
text.Value = Dereference(text, text.EscapedValue, start); text.Value = Dereference(text, text.EscapedValue, start);
} else { } else {
text.Value = text.EscapedValue; text.Value = text.EscapedValue;
@ -548,15 +548,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
#region Helper methods #region Helper methods
void OnSyntaxError(RawObject obj, string message, params object[] args) void OnSyntaxError(AXmlObject obj, string message, params object[] args)
{ {
OnSyntaxError(obj, this.CurrentLocation, this.CurrentLocation + 1, message, args); OnSyntaxError(obj, this.CurrentLocation, this.CurrentLocation + 1, message, args);
} }
public static void OnSyntaxError(RawObject obj, int start, int end, string message, params object[] args) public static void OnSyntaxError(AXmlObject obj, int start, int end, string message, params object[] args)
{ {
if (end <= start) end = start + 1; if (end <= start) end = start + 1;
XmlParser.Log("Syntax error ({0}-{1}): {2}", start, end, string.Format(message, args)); AXmlParser.Log("Syntax error ({0}-{1}): {2}", start, end, string.Format(message, args));
obj.AddSyntaxError(new SyntaxError() { obj.AddSyntaxError(new SyntaxError() {
Object = obj, Object = obj,
StartOffset = start, StartOffset = start,
@ -601,7 +601,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
} }
} }
string Dereference(RawObject owner, string text, int textLocation) string Dereference(AXmlObject owner, string text, int textLocation)
{ {
StringBuilder sb = null; // The dereferenced text so far (all up to 'curr') StringBuilder sb = null; // The dereferenced text so far (all up to 'curr')
int curr = 0; int curr = 0;

Просмотреть файл

@ -0,0 +1,43 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary> Identifies the context in which the text occured </summary>
enum TextType
{
/// <summary> Ends with non-whitespace </summary>
WhiteSpace,
/// <summary> Ends with "&lt;"; "]]&gt;" is error </summary>
CharacterData,
/// <summary> Ends with "-->"; "--" is error </summary>
Comment,
/// <summary> Ends with "]]&gt;" </summary>
CData,
/// <summary> Ends with "?>" </summary>
ProcessingInstruction,
/// <summary> Ends with "&lt;" or ">" </summary>
UnknownBang,
/// <summary> Unknown </summary>
Other
}
}

Просмотреть файл

@ -9,7 +9,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace ICSharpCode.AvalonEdit.XmlParser namespace ICSharpCode.AvalonEdit.Xml
{ {
class TokenReader class TokenReader
{ {
@ -48,7 +48,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
protected void AssertIsEndOfFile() protected void AssertIsEndOfFile()
{ {
XmlParser.Assert(IsEndOfFile(), "End of file expected at this point"); AXmlParser.Assert(IsEndOfFile(), "End of file expected at this point");
} }
protected bool HasMoreData() protected bool HasMoreData()
@ -58,7 +58,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
protected void AssertHasMoreData() protected void AssertHasMoreData()
{ {
XmlParser.Assert(HasMoreData(), "Unexpected end of file"); AXmlParser.Assert(HasMoreData(), "Unexpected end of file");
} }
protected bool TryMoveNext() protected bool TryMoveNext()
@ -300,7 +300,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
public void PrintStringCacheStats() public void PrintStringCacheStats()
{ {
XmlParser.Log("String cache: Requested {0} ({1} bytes); Actaully stored {2} ({3} bytes); {4}% stored", stringCacheRequestedCount, stringCacheRequestedSize, stringCacheStoredCount, stringCacheStoredSize, stringCacheRequestedSize == 0 ? 0 : stringCacheStoredSize * 100 / stringCacheRequestedSize); AXmlParser.Log("String cache: Requested {0} ({1} bytes); Actaully stored {2} ({3} bytes); {4}% stored", stringCacheRequestedCount, stringCacheRequestedSize, stringCacheStoredCount, stringCacheStoredSize, stringCacheRequestedSize == 0 ? 0 : stringCacheStoredSize * 100 / stringCacheRequestedSize);
} }
} }
} }