/
ParseError.java
63 lines (54 loc) · 1.58 KB
/
ParseError.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.jsoup.parser;
/**
* A Parse Error records an error in the input HTML that occurs in either the tokenisation or the tree building phase.
*/
public class ParseError {
private final int pos;
private final String cursorPos;
private final String errorMsg;
ParseError(CharacterReader reader, String errorMsg) {
pos = reader.pos();
cursorPos = reader.posLineCol();
this.errorMsg = errorMsg;
}
ParseError(CharacterReader reader, String errorFormat, Object... args) {
pos = reader.pos();
cursorPos = reader.posLineCol();
this.errorMsg = String.format(errorFormat, args);
}
ParseError(int pos, String errorMsg) {
this.pos = pos;
cursorPos = String.valueOf(pos);
this.errorMsg = errorMsg;
}
ParseError(int pos, String errorFormat, Object... args) {
this.pos = pos;
cursorPos = String.valueOf(pos);
this.errorMsg = String.format(errorFormat, args);
}
/**
* Retrieve the error message.
* @return the error message.
*/
public String getErrorMessage() {
return errorMsg;
}
/**
* Retrieves the offset of the error.
* @return error offset within input
*/
public int getPosition() {
return pos;
}
/**
Get the formatted line:column cursor position where the error occurred.
@return line:number cursor position
*/
public String getCursorPos() {
return cursorPos;
}
@Override
public String toString() {
return "<" + cursorPos + ">: " + errorMsg;
}
}