1 8 13 package jfun.parsec; 14 15 import java.io.PrintStream ; 16 import java.io.PrintWriter ; 17 import java.util.Stack ; 18 19 26 public class ParserException extends RuntimeException { 27 private final ParseError err; 28 private final Pos pos; 29 private final String module; 30 private final Stack frames = new Stack (); 31 void pushFrame(ParsingFrame frame){ 32 frames.push(frame); 33 } 34 39 public Stack getParsingTrace(){ 40 return frames; 41 } 42 43 47 public void printParsingTrace(PrintStream out){ 48 printParsingTrace(new java.io.PrintWriter (out, true)); 49 } 50 54 public void printParsingTrace(java.io.PrintWriter out){ 55 final int size = frames.size(); 56 for(int i=0; i<size; i++){ 57 out.println(frames.get(i)); 58 } 59 } 60 63 public void printParsingTrace(){ 64 printParsingTrace(System.err); 65 } 66 public void printStackTrace(PrintStream s) { 67 printParsingTrace(s); 68 super.printStackTrace(s); 69 } 70 public void printStackTrace(PrintWriter s) { 71 printParsingTrace(s); 72 super.printStackTrace(s); 73 } 74 75 81 public ParserException(final ParseError err, 82 final String mname, final Pos pos) { 83 this.err = err; 84 this.pos = pos; 85 this.module = mname; 86 } 87 88 95 public ParserException(String message, final ParseError err, 96 final String mname, final Pos pos) { 97 super(message); 98 this.err = err; 99 this.pos = pos; 100 this.module = mname; 101 } 102 103 104 110 public ParserException(Throwable cause, final ParseError err, 111 final String mname, final Pos pos) { 112 super(cause); 113 this.err = err; 114 this.pos = pos; 115 this.module = mname; 116 } 117 118 125 public ParserException(String message, Throwable cause, final ParseError err, 126 final String mname, final Pos pos) { 127 super(message, cause); 128 this.err = err; 129 this.pos = pos; 130 this.module = mname; 131 } 132 133 137 public final ParseError getError() { 138 return err; 139 } 140 144 public String getMessage(){ 145 return getErrorMessage(); 146 } 147 private String getErrorMessage(){ 148 final String msg = super.getMessage(); 149 final StringBuffer buf = new StringBuffer (); 150 if(msg != null) buf.append(msg).append("\n"); 151 if(module != null) 152 buf.append(module).append(" - "); 153 buf.append(DefaultShowError.show(err, pos)); 154 return buf.toString(); 155 } 156 157 161 public String getModuleName() { 162 return module; 163 } 164 168 public int getLineNo() { 169 return pos.getLineNo(); 170 } 171 175 public int getColumnNo(){ 176 return pos.getColumnNo(); 177 } 178 } 179 | Popular Tags |