aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Graphics/mid-tank.png
blob: 4da752a4292c1b4b5c46481344c0630164ec63a8 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 30 00 00 00 77 08 06 00 00 00 45 5f c3 .PNG........IHDR...0...w.....E_.
0020 53 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 00 09 70 48 59 73 00 00 0e c1 00 00 0e S....gAMA......a.....pHYs.......
0040 c1 01 b8 91 6b ed 00 00 00 18 74 45 58 74 53 6f 66 74 77 61 72 65 00 70 61 69 6e 74 2e 6e 65 74 ....k.....tEXtSoftware.paint.net
0060 20 34 2e 30 2e 39 6c 33 7e 4e 00 00 07 f2 49 44 41 54 78 5e ed db fd ab 4d 4f 1b 06 70 91 24 89 .4.0.9l3~N....IDATx^....MO..p.$.
0080 24 89 24 49 24 49 22 49 12 49 12 49 92 48 92 44 92 24 92 24 24 49 24 49 7e f7 0f c8 9f 38 df f3 $.$I$I"I.I.I.H.D.$.$$I$I~....8..
00a0 99 b3 ef d5 9c b1 f6 d9 db 76 b6 e7 f0 cc d4 d5 5a 6b de d6 75 cd dc 2f b3 76 e7 2c f9 c5 92 fe .........v......Zk..u../.v.,....
00c0 10 a6 56 d2 9e 3d 7b d2 91 23 47 d2 f1 e3 c7 d3 85 0b 17 d2 fb f7 ef d3 f3 e7 cf f3 8b 7f fc f8 ..V..={..#G.....................
00e0 91 b6 6d db 96 3e 7f fe 9c be 7f ff 9e 76 ee dc 99 9e 3c 79 92 be 7d fb 96 be 7e fd 9a 56 ac 58 ..m..>.......v....<y..}...~..V.X
0100 91 ce 9f 3f 9f 2e 5e bc 98 1e 3e 7c 98 3e 7c f8 90 6e dd ba 95 e7 da b5 6b 57 ba 7c f9 f2 f4 05 ...?..^...>|.>|..n......kW.|....
0120 9c 3d 7b 36 dd b9 73 27 dd bb 77 2f 83 80 57 af 5e c5 8b c7 c2 a1 43 87 d2 d3 a7 4f b3 80 bb 77 .={6..s'..w/..W.^.....C....O...w
0140 ef a6 03 07 0e a4 35 6b d6 a4 73 e7 ce 45 9f a9 95 b4 6c d9 b2 b4 7a f5 ea b4 79 f3 e6 b4 65 cb ......5k..s..E....l...z...y...e.
0160 96 f4 f1 e3 c7 2c e2 c1 83 07 1d c1 95 2b 57 e6 eb aa 55 ab 72 9f ad 5b b7 66 2c 5f be 3c ad 5b .....,.......+W...U.r..[.f,_.<.[
0180 b7 ae 13 4e 80 dd d8 b7 6f 5f de d9 13 27 4e 4c 5f 00 52 1b 37 6e cc 5b 1e 02 de bd 7b 97 be 7c ...N....o_...'NL_.R.7n.[....{..|
01a0 f9 92 4d 41 9f 0d 1b 36 e4 2b b2 bb 77 ef 4e fb f7 ef cf 24 ad f2 99 33 67 f2 98 b7 6f df 76 02 ..MA...6.+..w.N....$...3g...o.v.
01c0 ec 80 f6 3f b2 03 25 4a 01 ec fe f0 e1 c3 d9 ee f7 ee dd 9b d6 af 5f 9f c9 ba 27 e4 fa f5 eb 79 ...?..%J.............._...'....y
01e0 cc a9 53 a7 32 f1 10 c0 ee cd b3 7d fb f6 bc 4b 83 b9 a7 56 3a f2 e0 85 9c 13 11 57 02 8e 1e 3d ..S.2......}...K...V:......W...=
0200 9a 89 6b 63 2a ee 89 d2 87 09 79 d6 f7 d3 a7 4f f9 ca 89 f9 c4 c1 83 07 f3 2e 0c e6 5e 90 32 87 ..kc*.....y....O............^.2.
0220 6c 80 19 b0 ff 70 bc 1b 37 6e a4 ab 57 af e6 ab 08 a4 6e d3 a6 4d b9 af 55 65 4e fc 06 41 75 9e l....p..7n..W.....n..M..UeN..Au.
0240 43 a8 68 66 87 98 a3 b1 6b d7 ae 9d f3 ae 0a 63 97 6e 90 49 03 c5 f6 66 42 4c c4 3d c2 da ad b2 C.hf....k......c.n.I...fBL.=....
0260 7a 84 d4 b3 6d 61 56 d4 62 db 56 de 33 8c 20 3a 0a 23 4b b6 49 84 ac 8c e7 80 38 0e a2 10 58 69 z...maV.b.V.3..:.#K.I.....8...Xi
0280 db 0f a2 88 36 44 f5 7d f9 f2 65 36 0f f7 4c 83 09 bd 79 f3 26 43 d8 65 4e da 88 0e a8 83 78 5e ....6D.}..e6..L...y.&C.eN.....x^
02a0 ba 74 69 f7 ee 02 23 4b 3a 7d fa 74 da b1 63 47 86 e7 88 f9 44 45 22 3b 76 ec 58 36 23 2b aa 2d .ti...#K:}.t..cG....DE";v.X6#+.-
02c0 04 18 6b 0c b3 d2 6e 8e f0 81 10 c0 81 11 14 d1 e4 01 42 5d ed 14 a7 be 7d fb 76 ae 73 35 17 84 ..k...n...........B]....}.v.s5..
02e0 59 ce 60 64 c9 e4 4a 01 26 07 f7 35 10 95 d8 08 b0 7a 21 80 cd 23 e8 c5 76 52 94 42 3c a2 0f 01 Y.`d..J.&..5.....z!..#..vR.B<...
0300 04 1b 8b ac 0c 5d ce a9 2e 76 10 0a b3 1b 59 32 09 0e 08 9e 23 f3 c6 b6 07 6c b1 b0 48 9c 78 af .....]...v....Y2....#....l..H.x.
0320 dd b3 36 bb 54 f6 0d a2 e0 5e 1d 01 56 39 42 6c 89 5a 00 b3 1e dc 8f 2c 79 eb 6d 7b 69 42 6c 5b ..6.T....^..V9Bl.Z.....,y.m{iBl[
0340 3d e7 75 f6 91 cc 22 44 6a 27 c0 aa 86 80 88 3a 91 95 ad b0 85 81 f0 13 6d 61 2e 97 2e 5d ca 75 =.u..."Dj'.....:........ma...].u
0360 40 50 2d a0 c0 c8 d2 09 88 1d 70 f0 42 5c bd 67 66 81 ec e3 c7 8f b3 cd 5a 51 66 52 0a f0 72 e1 @P-.......p.B\.gf.......ZQfR..r.
0380 56 9d 67 a1 53 46 06 4e af 2e 76 40 5f 57 22 af 5c b9 d2 d5 4d 2c c0 8b 85 4d 02 10 f3 d2 20 52 V.g.SF.N..v@_W".\...M,...M.....R
03a0 22 ea f4 0d 01 b1 ba 76 89 69 45 24 d1 1e 28 cc 61 12 8c 2c 73 06 20 57 e6 80 3e 38 2a 84 b9 c5 "......v.iE$..(.a..,s..W..>8*...
03c0 ae 39 17 d9 0d 01 c1 fd c9 93 27 bb e8 65 e5 cb f1 bf 88 5f 2a 3f 4d c0 d6 99 00 32 4c 8a 69 30 .9........'..e....._*?M....2L.i0
03e0 23 99 58 f2 0a 9b 0f 41 72 00 7f 71 cf 2f 64 60 22 9c 3c 8d b5 38 92 9f 39 a3 5f 0f 16 ac 64 67 #.X....Ar..q./d`".<..8..9._...dg
0400 63 f3 fc 82 ad 3a d7 3b d7 38 d4 39 db 08 a7 fa e9 23 4b 3f 7a f4 a8 f3 8b d7 af 5f 77 7d 5d 99 c....:.;.8.9.....#K?z......_w}].
0420 19 93 23 de 71 9c 38 fd bc 68 d2 12 13 8c 0d 2b 48 54 7c 69 21 ad 1e 19 f6 cf 7c c2 e6 6f de bc ..#.q.8..h.....+HT|i!.....|..o..
0440 d9 85 53 57 fd ad 7a 7c 5b c4 f1 64 0c 0c 2d 79 32 db cf 54 6c 3f 30 15 26 13 b6 1c e1 d0 39 07 ..SW..z|[..d..-y2..Tl?0.&.....9.
0460 ac 22 a
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading;

using Tango.Scripting.Editors.Document;

namespace Tango.Scripting.Editors.Xml
{
	/// <summary>
	/// Creates object tree from XML document.
	/// </summary>
	/// <remarks>
	/// The created tree fully describes the document and thus the orginal XML file can be
	/// exactly reproduced.
	/// 
	/// Any further parses will reparse only the changed parts and the existing tree will
	/// be updated with the changes.  The user can add event handlers to be notified of
	/// the changes.  The parser tries to minimize the number of changes to the tree.
	/// (for example, it will add a single child at the start of collection rather than
	/// clearing the collection and adding new children)
	/// 
	/// The object tree consists of following types:
	///   RawObject - Abstact base class for all types
	///     RawContainer - Abstact base class for all types that can contain child nodes
	///       RawDocument - The root object of the XML document
	///       RawElement - Logical grouping of other nodes together.  The first child is always the start tag.
	///       RawTag - Represents any markup starting with "&lt;" and (hopefully) ending with ">"
	///     RawAttribute - Name-value pair in a tag
	///     RawText - Whitespace or character data
	/// 
	/// For example, see the following XML and the produced object tree:
	/// <![CDATA[
	///   <!-- My favourite quote -->
	///   <quote author="Albert Einstein">
	///     Make everything as simple as possible, but not simpler.
	///   </quote>
	/// 
	///   RawDocument
	///     RawTag "<!--" "-->"
	///       RawText " My favourite quote "
	///     RawElement
	///       RawTag "<" "quote" ">"
	///         RawText " "
	///         RawAttribute 'author="Albert Einstein"'
	///       RawText "\n  Make everything as simple as possible, but not simpler.\n"
	///       RawTag "</" "quote" ">"
	/// ]]>
	/// 
	/// The precise content of RawTag depends on what it represents:
	/// <![CDATA[
	///   Start tag:  "<"  Name?  (RawText+ RawAttribute)* RawText* (">" | "/>")
	///   End tag:    "</" Name?  (RawText+ RawAttribute)* RawText* ">"
	///   P.instr.:   "<?" Name?  (RawText)* "?>"
	///   Comment:    "<!--"      (RawText)* "-->"
	///   CData:      "<![CDATA[" (RawText)* "]]" ">"
	///   DTD:        "<!DOCTYPE" (RawText+ RawTag)* RawText* ">"    (DOCTYPE or other DTD names)
	///   UknownBang: "<!"        (RawText)* ">"
	/// ]]>
	/// 
	/// The type of tag can be identified by the opening backet.
	/// There are helpper properties in the RawTag class to identify the type, exactly
	/// one of the properties will be true.
	/// 
	/// The closing bracket may be missing or may be different for mallformed XML.
	/// 
	/// Note that there can always be multiple consequtive RawText nodes.
	/// This is to ensure that idividual texts are not too long.
	/// 
	/// XML Spec:  http://www.w3.org/TR/xml/
	/// XML EBNF:  http://www.jelks.nu/XML/xmlebnf.html
	/// 
	/// Internals:
	/// 
	/// "Try" methods can silently fail by returning false.
	/// MoveTo methods do not move if they are already at the given target
	/// If methods return some object, it must be no-empty.  It is up to the caller to ensure
	/// the context is appropriate for reading.
	/// 
	/// </remarks>
	public class AXmlParser
	{
		AXmlDocument userDocument;
		
		internal TrackedSegmentCollection TrackedSegments { get; private set; }
		
		/// <summary>
		/// Generate syntax error when seeing enity reference other then the build-in ones
		/// </summary>
		public bool UnknownEntityReferenceIsError { get; set; }
		
		/// <summary> Create new parser </summary>
		public AXmlParser()
		{
			this.Lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
			ClearInternal();
		}
		
		/// <summary> Throws exception if condition is false </summary>
		internal static void Assert(bool condition, string message)
		{
			if (!condition) {
				throw new InternalException("Assertion failed: " + message);
			}
		}

		/// <summary> Throws exception if condition is false </summary>
		[Conditional("DEBUG")]
		internal static void DebugAssert(bool condition, string message)
		{
			if (!condition) {
				throw new InternalException("Assertion failed: " + message);
			}
		}
		
		[Conditional("DEBUG")]
		internal static void Log(string text, params object[] pars)
		{
			//System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "XML: " + text, pars));
		}
		
		/// <summary>
		/// Incrementaly parse the given text.
		/// You have to hold the write lock.
		/// </summary>
		/// <param name="input">
		/// The full XML text of the new document.
		/// </param>
		/// <param name="changesSinceLastParse">
		/// Changes since last parse.  Null will cause full reparse.
		/// </param>
		public AXmlDocument Parse(string input, IEnumerable<DocumentChangeEventArgs> changesSinceLastParse)
		{
			if (!Lock.IsWriteLockHeld)
				throw new InvalidOperationException("Lock needed!");
			
			// Use changes to invalidate cache
			if (changesSinceLastParse != null) {
				this.TrackedSegments.UpdateOffsetsAndInvalidate(changesSinceLastParse);
			} else {
				this.TrackedSegments.InvalidateAll();
			}
			
			TagReader tagReader = new TagReader(this, input);
			List<AXmlObject> tags = tagReader.ReadAllTags();
			AXmlDocument parsedDocument = new TagMatchingHeuristics(this, input, tags).ReadDocument();
			tagReader.PrintStringCacheStats();
			AXmlParser.Log("Updating main DOM tree...");
			userDocument.UpdateTreeFrom(parsedDocument);
			userDocument.DebugCheckConsistency(true);
			Assert(userDocument.GetSelfAndAllChildren().Count() == parsedDocument.GetSelfAndAllChildren().Count(), "Parsed document and updated document have different number of children");
			return userDocument;
		}
		
		/// <summary>
		/// Makes calls to Parse() thread-safe. Use Lock everywhere Parse() is called.
		/// </summary>
		public ReaderWriterLockSlim Lock { get; private set; }
		
		/// <summary>
		/// Returns the last cached version of the document.
		/// </summary>
		/// <exception cref="InvalidOperationException">No read lock is held by the current thread.</exception>
		public AXmlDocument LastDocument {
			get {
				if (!Lock.IsReadLockHeld)
					throw new InvalidOperationException("Read lock needed!");
				
				return userDocument;
			}
		}
		
		/// <summary>
		/// Clears the parser data.
		/// </summary>
		/// <exception cref="InvalidOperationException">No write lock is held by the current thread.</exception>
		public void Clear()
		{
			if (!Lock.IsWriteLockHeld)
				throw new InvalidOperationException("Write lock needed!");
			
			ClearInternal();
		}
		
		void ClearInternal()
		{
			this.UnknownEntityReferenceIsError = true;
			this.TrackedSegments = new TrackedSegmentCollection();
			this.userDocument = new AXmlDocument() { Parser = this };
			this.userDocument.Document = this.userDocument;
			// Track the document
			this.TrackedSegments.AddParsedObject(this.userDocument, null);
			this.userDocument.IsCached = false;
		}
	}
}