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\Win32.cs" />
<CodeAnalysisDictionary Include="Properties\CodeAnalysisDictionary.xml" />
<Compile Include="XmlParser\AbstractXmlVisitor.cs" />
<Compile Include="XmlParser\AttributeCollection.cs" />
<Compile Include="XmlParser\Cache.cs" />
<Compile Include="XmlParser\ChildrenCollection.cs" />
<Compile Include="XmlParser\AbstractAXmlVisitor.cs" />
<Compile Include="XmlParser\AXmlAttribute.cs" />
<Compile Include="XmlParser\AXmlAttributeCollection.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\FilteredCollection.cs" />
<Compile Include="XmlParser\IXmlVisitor.cs" />
<Compile Include="XmlParser\IAXmlVisitor.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\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" />
<EmbeddedResource Include="Highlighting\Resources\ASPX.xshd" />
<EmbeddedResource Include="Highlighting\Resources\BAT-Mode.xshd" />

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

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

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

@ -8,43 +8,43 @@
using System;
using System.Collections.Generic;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Specailized attribute collection with attribute name caching
/// </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>
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>
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;
if (!hashtable.ContainsKey(localName)) {
hashtable[localName] = new List<RawAttribute>(1);
hashtable[localName] = new List<AXmlAttribute>(1);
}
hashtable[localName].Add(attr);
}
void RemoveFromHashtable(RawAttribute attr)
void RemoveFromHashtable(AXmlAttribute attr)
{
string localName = attr.LocalName;
hashtable[localName].Remove(attr);
}
static List<RawAttribute> NoAttributes = new List<RawAttribute>();
static List<AXmlAttribute> NoAttributes = new List<AXmlAttribute>();
/// <summary>
/// Get all attributes with given local name.
/// Hash table is used for lookup so this is cheap.
/// </summary>
public IEnumerable<RawAttribute> GetByLocalName(string localName)
public IEnumerable<AXmlAttribute> GetByLocalName(string localName)
{
if (hashtable.ContainsKey(localName)) {
return hashtable[localName];
@ -56,7 +56,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <inheritdoc/>
protected override void ClearItems()
{
foreach(RawAttribute item in this) {
foreach(AXmlAttribute item in this) {
RemoveFromHashtable(item);
item.Changing -= item_Changing;
item.Changed -= item_Changed;
@ -65,7 +65,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <inheritdoc/>
protected override void InsertItem(int index, RawAttribute item)
protected override void InsertItem(int index, AXmlAttribute item)
{
AddToHashtable(item);
item.Changing += item_Changing;
@ -83,7 +83,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <inheritdoc/>
protected override void SetItem(int index, RawAttribute item)
protected override void SetItem(int index, AXmlAttribute item)
{
throw new NotSupportedException();
}
@ -91,14 +91,14 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// Every item in the collectoin should be registered to these handlers
// 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;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Abstact base class for all types that can contain child nodes
/// </summary>
public abstract class RawContainer: RawObject
public abstract class AXmlContainer: AXmlObject
{
/// <summary>
/// Children of the node. It is read-only.
/// Note that is has CollectionChanged event.
/// </summary>
public ChildrenCollection<RawObject> Children { get; private set; }
public AXmlObjectCollection<AXmlObject> Children { get; private set; }
/// <summary> Create new container </summary>
public RawContainer()
public AXmlContainer()
{
this.Children = new ChildrenCollection<RawObject>();
this.Children = new AXmlObjectCollection<AXmlObject>();
}
#region Helpper methods
ObservableCollection<RawElement> elements;
ObservableCollection<AXmlElement> elements;
/// <summary> Gets direcly nested elements (non-recursive) </summary>
public ObservableCollection<RawElement> Elements {
public ObservableCollection<AXmlElement> Elements {
get {
if (elements == null) {
elements = new FilteredCollection<RawElement, ChildrenCollection<RawObject>>(this.Children);
elements = new FilteredCollection<AXmlElement, AXmlObjectCollection<AXmlObject>>(this.Children);
}
return elements;
}
}
internal RawObject FirstChild {
internal AXmlObject FirstChild {
get {
return this.Children[0];
}
}
internal RawObject LastChild {
internal AXmlObject LastChild {
get {
return this.Children[this.Children.Count - 1];
}
@ -62,9 +62,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
#endregion
/// <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>
@ -72,13 +72,13 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// Goes recursively down the tree.
/// Specail case if at the end of attribute or text
/// </summary>
public RawObject GetChildAtOffset(int offset)
public AXmlObject GetChildAtOffset(int offset)
{
foreach(RawObject child in this.Children) {
if ((child is RawAttribute || child is RawText) && offset == child.EndOffset) return child;
foreach(AXmlObject child in this.Children) {
if ((child is AXmlAttribute || child is AXmlText) && offset == child.EndOffset) return child;
if (child.StartOffset < offset && offset < child.EndOffset) {
if (child is RawContainer) {
return ((RawContainer)child).GetChildAtOffset(offset);
if (child is AXmlContainer) {
return ((AXmlContainer)child).GetChildAtOffset(offset);
} else {
return child;
}
@ -90,7 +90,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// Only these four methods should be used to modify the collection
/// <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
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>
internal void AddChildren(IEnumerable<RawObject> items)
internal void AddChildren(IEnumerable<AXmlObject> items)
{
// Childs can be only added to newly parsed items
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.
/// Insert child and keep links consistent.
/// </summary>
void InsertChild(int index, RawObject item)
void InsertChild(int index, AXmlObject item)
{
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(item.Parent != this, "Can not own item twice");
@ -132,16 +132,16 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// Cache constraint:
/// If cached item has parent set, then the whole subtree must be consistent
/// </remarks>
void SetParentPointersInTree(RawObject item)
void SetParentPointersInTree(AXmlObject item)
{
// All items come from the parser cache
if (item.Parent == null) {
// Dangling object - either a new parser object or removed tree (still cached)
item.Parent = this;
if (item is RawContainer) {
foreach(RawObject child in ((RawContainer)item).Children) {
((RawContainer)item).SetParentPointersInTree(child);
if (item is AXmlContainer) {
foreach(AXmlObject child in ((AXmlContainer)item).Children) {
((AXmlContainer)item).SetParentPointersInTree(child);
}
}
} 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
DebugAssert(item.Parent.Document == null, "Old parent is part of document as well");
// 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;
}
item.Parent = this;
@ -171,7 +171,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// </summary>
void RemoveChild(int index)
{
RawObject removed = this.Children[index];
AXmlObject removed = this.Children[index];
LogDom("Removing {0} at index {1}", removed, index);
// Null parent pointer
@ -187,10 +187,10 @@ namespace ICSharpCode.AvalonEdit.XmlParser
internal override void DebugCheckConsistency(bool allowNullParent)
{
base.DebugCheckConsistency(allowNullParent);
RawObject prevChild = null;
AXmlObject prevChild = null;
int myStartOffset = this.StartOffset;
int myEndOffset = this.EndOffset;
foreach(RawObject child in this.Children) {
foreach(AXmlObject child in this.Children) {
Assert(child.Length != 0, "Empty child");
if (!allowNullParent) {
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);
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;) {
RawObject child = this.Children[i];
RawObject srcChild;
AXmlObject child = this.Children[i];
AXmlObject 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)
srcChildren.Remove(child.StartOffset);
if (child is RawContainer)
((RawContainer)child).RemoveChildrenNotIn(((RawContainer)srcChild).Children);
if (child is AXmlContainer)
((AXmlContainer)child).RemoveChildrenNotIn(((AXmlContainer)srcChild).Children);
i++;
} else {
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++) {
// End of our list?
@ -239,13 +239,13 @@ namespace ICSharpCode.AvalonEdit.XmlParser
InsertChild(i, srcList[i]);
continue;
}
RawObject child = this.Children[i];
RawObject srcChild = srcList[i];
AXmlObject child = this.Children[i];
AXmlObject srcChild = srcList[i];
if (child.CanUpdateDataFrom(srcChild) /* includes offset test */) {
child.UpdateDataFrom(srcChild);
if (child is RawContainer)
((RawContainer)child).InsertAndUpdateChildrenFrom(((RawContainer)srcChild).Children);
if (child is AXmlContainer)
((AXmlContainer)child).InsertAndUpdateChildrenFrom(((AXmlContainer)srcChild).Children);
} else {
InsertChild(i, srcChild);
}

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

@ -14,51 +14,51 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// The root object of the XML document
/// </summary>
public class RawDocument: RawContainer
public class AXmlDocument: AXmlContainer
{
/// <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>
public event EventHandler<NotifyCollectionChangedEventArgs> ObjectInserted;
/// <summary> Occurs when object is removed from any part of the document </summary>
public event EventHandler<NotifyCollectionChangedEventArgs> ObjectRemoved;
/// <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>
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)
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)
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)
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)
ObjectChanged(this, new RawObjectEventArgs() { Object = obj } );
ObjectChanged(this, new AXmlObjectEventArgs() { Object = obj } );
}
/// <inheritdoc/>
public override void AcceptVisitor(IXmlVisitor visitor)
public override void AcceptVisitor(IAXmlVisitor visitor)
{
visitor.VisitDocument(this);
}

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

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

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

@ -14,12 +14,12 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Abstact base class for all types
/// </summary>
public abstract class RawObject: TextSegment
public abstract class AXmlObject: TextSegment
{
/// <summary> Empty string. The namespace used if there is no "xmlns" specified </summary>
public static readonly string NoNamespace = string.Empty;
@ -36,15 +36,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// Cache constraint:
/// If cached item has parent set, then the whole subtree must be consistent
/// </remarks>
public RawObject Parent { get; set; }
public AXmlObject Parent { get; set; }
/// <summary> Gets the document owning this object or null if orphaned </summary>
public RawDocument Document {
public AXmlDocument Document {
get {
if (this.Parent != null) {
return this.Parent.Document;
} else if (this is RawDocument) {
return (RawDocument)this;
} else if (this is AXmlDocument) {
return (AXmlDocument)this;
} else {
return null;
}
@ -52,25 +52,25 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <summary> Creates new object </summary>
public RawObject()
public AXmlObject()
{
this.LastUpdatedFrom = this;
}
/// <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>
public event EventHandler<RawObjectEventArgs> Changed;
public event EventHandler<AXmlObjectEventArgs> Changed;
/// <summary> Raises Changing event </summary>
protected void OnChanging()
{
LogDom("Changing {0}", this);
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) {
doc.OnObjectChanging(this);
}
@ -81,9 +81,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
{
LogDom("Changed {0}", this);
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) {
doc.OnObjectChanged(this);
}
@ -130,15 +130,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <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>
public IEnumerable<RawObject> GetAncestors()
public IEnumerable<AXmlObject> GetAncestors()
{
RawObject curr = this.Parent;
AXmlObject curr = this.Parent;
while(curr != null) {
yield return curr;
curr = curr.Parent;
@ -146,7 +146,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <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>
internal object LastUpdatedFrom { get; private set; }
@ -154,7 +154,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
internal bool IsInCache { get; set; }
/// <summary> Is call to UpdateDataFrom is allowed? </summary>
internal bool CanUpdateDataFrom(RawObject source)
internal bool CanUpdateDataFrom(AXmlObject source)
{
return
this.GetType() == source.GetType() &&
@ -163,7 +163,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <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");
DebugAssert(this.StartOffset == source.StartOffset, "Source has different StartOffset");

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

@ -12,13 +12,14 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Collection that is publicly read-only and has support
/// for adding/removing multiple items at a time.
/// </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>
public event NotifyCollectionChangedEventHandler CollectionChanged;

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

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

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

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

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

@ -14,32 +14,32 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Whitespace or character data
/// </summary>
public class RawText: RawObject
public class AXmlText: AXmlObject
{
/// <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>
public string EscapedValue { get; set; }
/// <summary> The text with all entity references resloved </summary>
public string Value { get; set; }
/// <inheritdoc/>
public override void AcceptVisitor(IXmlVisitor visitor)
public override void AcceptVisitor(IAXmlVisitor visitor)
{
visitor.VisitText(this);
}
/// <inheritdoc/>
internal override void UpdateDataFrom(RawObject source)
internal override void UpdateDataFrom(AXmlObject source)
{
base.UpdateDataFrom(source); // Check asserts
if (this.LastUpdatedFrom == source) return;
RawText src = (RawText)source;
AXmlText src = (AXmlText)source;
if (this.EscapedValue != src.EscapedValue ||
this.Value != src.Value)
{
@ -56,29 +56,4 @@ namespace ICSharpCode.AvalonEdit.XmlParser
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.Text;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Derive from this class to create visitor for the XML tree
/// </summary>
public abstract class AbstractXmlVisitor : IXmlVisitor
public abstract class AbstractAXmlVisitor : IAXmlVisitor
{
/// <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>
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>
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>
public virtual void VisitAttribute(RawAttribute attribute)
public virtual void VisitAttribute(AXmlAttribute attribute)
{
}
/// <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 ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Holds all valid parsed items.
@ -18,7 +18,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
class Cache
{
/// <summary> Previously parsed items as long as they are valid </summary>
TextSegmentCollection<RawObject> parsedItems = new TextSegmentCollection<RawObject>();
TextSegmentCollection<AXmlObject> parsedItems = new TextSegmentCollection<AXmlObject>();
/// <summary>
/// Is used to identify what memory range was touched by object
@ -28,7 +28,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
class TouchedMemoryRange: TextSegment
{
public RawObject TouchedByObject { get; set; }
public AXmlObject TouchedByObject { get; set; }
}
public void UpdateOffsetsAndInvalidate(IEnumerable<DocumentChangeEventArgs> changes)
@ -39,15 +39,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
touchedMemoryRanges.UpdateOffsets(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
// FindSegmentsContaining includes any segments touching
// 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);
}
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);
touchedMemoryRanges.Remove(memory);
}
@ -55,14 +55,14 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <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));
if (obj is RawContainer) {
AXmlParser.Assert(obj.Length > 0 || obj is AXmlDocument, string.Format("Invalid object {0}. It has zero length.", obj));
if (obj is AXmlContainer) {
int objStartOffset = obj.StartOffset;
int objEndOffset = obj.EndOffset;
foreach(RawObject child in ((RawContainer)obj).Children) {
XmlParser.Assert(objStartOffset <= child.StartOffset && child.EndOffset <= objEndOffset, "Wrong nesting");
foreach(AXmlObject child in ((AXmlContainer)obj).Children) {
AXmlParser.Assert(objStartOffset <= child.StartOffset && child.EndOffset <= objEndOffset, "Wrong nesting");
}
}
parsedItems.Add(obj);
@ -76,14 +76,14 @@ namespace ICSharpCode.AvalonEdit.XmlParser
TouchedByObject = obj
};
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>();
foreach(RawObject parent in parsedItems.FindSegmentsContaining(child.StartOffset)) {
List<AXmlObject> parents = new List<AXmlObject>();
foreach(AXmlObject parent in parsedItems.FindSegmentsContaining(child.StartOffset)) {
// Parent is anyone wholy containg the child
if (parent.StartOffset <= child.StartOffset && child.EndOffset <= parent.EndOffset && parent != child) {
parents.Add(parent);
@ -93,28 +93,28 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
/// <summary> Remove from cache </summary>
public void Remove(RawObject obj, bool includeParents)
public void Remove(AXmlObject obj, bool 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)) {
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)) {
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) {
if (obj is T && conditon((T)obj)) {
return (T)obj;

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

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

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

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

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

@ -7,26 +7,26 @@
using System;
using System.Text;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Visitor for the XML tree
/// </summary>
public interface IXmlVisitor
public interface IAXmlVisitor
{
/// <summary> Visit RawDocument </summary>
void VisitDocument(RawDocument document);
void VisitDocument(AXmlDocument document);
/// <summary> Visit RawElement </summary>
void VisitElement(RawElement element);
void VisitElement(AXmlElement element);
/// <summary> Visit RawTag </summary>
void VisitTag(RawTag tag);
void VisitTag(AXmlTag tag);
/// <summary> Visit RawAttribute </summary>
void VisitAttribute(RawAttribute attribute);
void VisitAttribute(AXmlAttribute attribute);
/// <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.Specialized;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
/// <summary>
/// Two collections in sequence

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

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

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

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

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

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

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

@ -11,27 +11,27 @@ using System.Globalization;
using System.Linq;
using System.Text;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
class TagReader: TokenReader
{
XmlParser parser;
AXmlParser parser;
Cache cache;
string input;
public TagReader(XmlParser parser, string input): base(input)
public TagReader(AXmlParser parser, string input): base(input)
{
this.parser = parser;
this.cache = parser.Cache;
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);
}
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);
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);
}
@ -54,22 +54,22 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// 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.
/// </summary>
public List<RawObject> ReadAllTags()
public List<AXmlObject> ReadAllTags()
{
List<RawObject> stream = new List<RawObject>();
List<AXmlObject> stream = new List<AXmlObject>();
while(true) {
if (IsEndOfFile()) {
break;
} else if (TryPeek('<')) {
RawElement elem;
AXmlElement elem;
if (TryReadFromCacheOrNew(out elem, e => e.IsProperlyNested)) {
stream.Add(elem);
} else {
stream.Add(ReadTag());
}
} else {
stream.AddRange(ReadText(RawTextType.CharacterData));
stream.AddRange(ReadText(TextType.CharacterData));
}
}
@ -79,11 +79,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary>
/// Context: "&lt;"
/// </summary>
RawTag ReadTag()
AXmlTag ReadTag()
{
AssertHasMoreData();
RawTag tag;
AXmlTag tag;
if (TryReadFromCacheOrNew(out tag)) return tag;
tag.StartOffset = this.CurrentLocation;
@ -111,7 +111,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
// Chech for all forbiden 'name' charcters first - see ReadName
if (IsEndOfFile()) break;
if (TryPeekWhiteSpace()) {
tag.AddChildren(ReadText(RawTextType.WhiteSpace));
tag.AddChildren(ReadText(TextType.WhiteSpace));
continue; // End of file might be next
}
if (TryPeek('<')) break;
@ -124,15 +124,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
tag.AddChildren(ReadContentOfDTD());
} else {
int start = this.CurrentLocation;
IEnumerable<RawObject> text;
IEnumerable<AXmlObject> text;
if (tag.IsComment) {
text = ReadText(RawTextType.Comment);
text = ReadText(TextType.Comment);
} else if (tag.IsCData) {
text = ReadText(RawTextType.CData);
text = ReadText(TextType.CData);
} else if (tag.IsProcessingInstruction) {
text = ReadText(RawTextType.ProcessingInstruction);
text = ReadText(TextType.ProcessingInstruction);
} else if (tag.IsUnknownBang) {
text = ReadText(RawTextType.UnknownBang);
text = ReadText(TextType.UnknownBang);
} else {
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
var duplicates = tag.Children.OfType<RawAttribute>().GroupBy(attr => attr.Name).SelectMany(g => g.Skip(1));
foreach(RawAttribute attr in duplicates) {
var duplicates = tag.Children.OfType<AXmlAttribute>().GroupBy(attr => attr.Name).SelectMany(g => g.Skip(1));
foreach(AXmlAttribute attr in duplicates) {
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[")) {
return "<![CDATA[";
} else {
foreach(string dtdName in RawTag.DTDNames) {
foreach(string dtdName in AXmlTag.DTDNames) {
// the dtdName includes "<!"
if (TryRead(dtdName.Remove(0, 2))) return dtdName;
}
@ -243,7 +243,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
return true;
}
IEnumerable<RawObject> ReadContentOfDTD()
IEnumerable<AXmlObject> ReadContentOfDTD()
{
int start = this.CurrentLocation;
while(true) {
@ -279,11 +279,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// <summary>
/// Context: name or "=\'\""
/// </summary>
RawAttribute ReadAttribulte()
AXmlAttribute ReadAttribulte()
{
AssertHasMoreData();
RawAttribute attr;
AXmlAttribute attr;
if (TryReadFromCacheOrNew(out attr)) return attr;
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,
EndOffset = end,
EscapedValue = GetText(start, end),
Type = RawTextType.Other
Type = TextType.Other
};
OnParsed(text);
@ -431,11 +431,11 @@ namespace ICSharpCode.AvalonEdit.XmlParser
/// It can also return empty set for no appropriate text input.
/// Make sure you enumerate it only once
/// </summary>
IEnumerable<RawObject> ReadText(RawTextType type)
IEnumerable<AXmlObject> ReadText(TextType type)
{
bool lookahead = false;
while(true) {
RawText text;
AXmlText text;
if (TryReadFromCacheOrNew(out text, t => t.Type == type)) {
// Cached text found
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
if (lookahead) {
// 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) {
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;
@ -463,9 +463,9 @@ namespace ICSharpCode.AvalonEdit.XmlParser
int start = this.CurrentLocation;
// Try move to the terminator given by the context
if (type == RawTextType.WhiteSpace) {
if (type == TextType.WhiteSpace) {
TryMoveToNonWhiteSpace(fragmentEnd);
} else if (type == RawTextType.CharacterData) {
} else if (type == TextType.CharacterData) {
while(true) {
if (!TryMoveToAnyOf(new char[] {'<', ']'}, fragmentEnd)) break; // End of fragment
if (TryPeek('<')) break;
@ -478,7 +478,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
throw new Exception("Infinite loop");
}
} else if (type == RawTextType.Comment) {
} else if (type == TextType.Comment) {
// Do not report too many errors
bool errorReported = false;
while(true) {
@ -490,20 +490,20 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
TryMoveNext();
}
} else if (type == RawTextType.CData) {
} else if (type == TextType.CData) {
while(true) {
// 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 (TryPeek("]]>")) break;
TryMoveNext();
}
} else if (type == RawTextType.ProcessingInstruction) {
} else if (type == TextType.ProcessingInstruction) {
while(true) {
if (!TryMoveTo('?', fragmentEnd)) break; // End of fragment
if (TryPeek("?>")) break;
TryMoveNext();
}
} else if (type == RawTextType.UnknownBang) {
} else if (type == TextType.UnknownBang) {
TryMoveToAnyOf(new char[] {'<', '>'}, fragmentEnd);
} else {
throw new Exception("Uknown type " + type);
@ -528,7 +528,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
}
text.EscapedValue = GetText(start, this.CurrentLocation);
if (type == RawTextType.CharacterData) {
if (type == TextType.CharacterData) {
text.Value = Dereference(text, text.EscapedValue, start);
} else {
text.Value = text.EscapedValue;
@ -548,15 +548,15 @@ namespace ICSharpCode.AvalonEdit.XmlParser
#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);
}
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;
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() {
Object = obj,
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')
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.Linq;
namespace ICSharpCode.AvalonEdit.XmlParser
namespace ICSharpCode.AvalonEdit.Xml
{
class TokenReader
{
@ -48,7 +48,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
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()
@ -58,7 +58,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
protected void AssertHasMoreData()
{
XmlParser.Assert(HasMoreData(), "Unexpected end of file");
AXmlParser.Assert(HasMoreData(), "Unexpected end of file");
}
protected bool TryMoveNext()
@ -300,7 +300,7 @@ namespace ICSharpCode.AvalonEdit.XmlParser
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);
}
}
}