1 module deepmagic.dom.xml.exception;
2 
3 import deepmagic.dom;
4 
5 /** The base class for exceptions thrown by this module */
6 class XMLException : Exception { this(string msg) { super(msg); } }
7 
8 // Other exceptions
9 
10 /// Thrown during Comment constructor
11 class CommentException : XMLException
12 { this(string msg) { super(msg); } }
13 
14 /// Thrown during CData constructor
15 //class CDataException : XMLException
16 //{ private this(string msg) { super(msg); } }
17 
18 /// Thrown during XMLInstruction constructor
19 class XIException : XMLException
20 { this(string msg) { super(msg); } }
21 
22 /// Thrown during ProcessingInstruction constructor
23 class PIException : XMLException
24 { this(string msg) { super(msg); } }
25 
26 /// Thrown during Text constructor
27 class TextException : XMLException
28 { this(string msg) { super(msg); } }
29 
30 /// Thrown during decode()
31 class DecodeException : XMLException
32 { this(string msg) { super(msg); } }
33 
34 /// Thrown if comparing with wrong type
35 class InvalidTypeException : XMLException
36 { this(string msg) { super(msg); } }
37 
38 /// Thrown when parsing for Tags
39 class TagException : XMLException
40 { this(string msg) { super(msg); } }
41 
42 /+
43 /**
44  * Thrown during check()
45  */
46 class CheckException : XMLException
47 {
48 	CheckException err; /// Parent in hierarchy
49 	private string tail;
50 	/**
51 	 * Name of production rule which failed to parse,
52 	 * or specific error message
53 	 */
54 	string msg;
55 	size_t line = 0; /// Line number at which parse failure occurred
56 	size_t column = 0; /// Column number at which parse failure occurred
57 
58 	public this(string tail,string msg,Err err=null)
59 	{
60 		super(null);
61 		this.tail = tail;
62 		this.msg = msg;
63 		this.err = err;
64 	}
65 
66 	private void complete(string entire)
67 	{
68 		string head = entire[0..$-tail.length];
69 		ptrdiff_t n = head.lastIndexOf('\n') + 1;
70 		line = head.count("\n") + 1;
71 		dstring t;
72 		transcode(head[n..$],t);
73 		column = t.length + 1;
74 		if (err !is null) err.complete(entire);
75 	}
76 
77 	override string toString() const
78 	{
79 		string s;
80 		if (line != 0) s = format("Line %d, column %d: ",line,column);
81 		s ~= msg;
82 		s ~= '\n';
83 		if (err !is null) s = err.toString() ~ s;
84 		return s;
85 	}
86 }
87 
88 public alias Err = CheckException;
89 +/