01 /*
02 * ParsingProblem.java
03 * Copyright (c) 1998-2008, The University of Sheffield.
04 *
05 * This code is from the GATE project (http://gate.ac.uk/) and is free
06 * software licenced under the GNU General Public License version 3. It is
07 * distributed without any warranty. For more details see COPYING.txt in the
08 * top level directory (or at http://gatewiki.sf.net/COPYING.txt).
09 *
10 * Hamish Cunningham, 2nd September 2006
11 */
12
13 package gate.yam.parse;
14 import java.util.*;
15 import gate.util.*;
16
17 /**
18 * Class storing data about errors and warnings during parsing.
19 * @author Hamish Cunningham
20 */
21 public class ParsingProblem {
22 /** Construction. */
23 public ParsingProblem(
24 int beginLine, int beginColumn, int endLine, int endColumn,
25 Exception e, String error, boolean included
26 ) {
27 this.beginLine = beginLine;
28 this.beginColumn = beginColumn;
29 this.endLine = endLine;
30 this.endColumn = endColumn;
31 this.e = e;
32 this.error = error;
33 this.included = included;
34 }
35
36 /** Where the error starts and ends. */
37 public int beginLine, beginColumn, endLine, endColumn;
38
39 /** Exception thrown by the parser (may be null). */
40 public Exception e;
41
42 /** The text of the error. */
43 public String error;
44
45 /** Was this in an included file? */
46 public boolean included = false;
47
48 /** A message for printing. */
49 public String getMessage() {
50 String incMess = (included) ? "(In included file.) " : "";
51 StringBuffer message = new StringBuffer(
52 incMess + "Problem translating from line " + beginLine + " column " +
53 beginColumn + " to line " + endLine + " column " + endColumn +
54 ". The text was: >>>" + error + "<<<."
55 );
56 if(e != null) {
57 String eMess = e.getMessage().replaceAll("\n", "");
58 int len = eMess.length();
59 len = (len < 300) ? len : 300;
60 message.append(
61 "\nThe exception was: " + eMess.substring(0, len) + "..."
62 );
63 }
64 return message.toString();
65 } // getMessage()
66
67 } // ParsingProblem
|