| 7401 | } |
| 7402 | |
| 7403 | static public class CompilerException extends RuntimeException implements IExceptionInfo{ |
| 7404 | final public String source; |
| 7405 | |
| 7406 | final public int line; |
| 7407 | |
| 7408 | final public Object data; |
| 7409 | |
| 7410 | // Error keys |
| 7411 | final static public String ERR_NS = "clojure.error"; |
| 7412 | final static public Keyword ERR_SOURCE = Keyword.intern(ERR_NS, "source"); |
| 7413 | final static public Keyword ERR_LINE = Keyword.intern(ERR_NS, "line"); |
| 7414 | final static public Keyword ERR_COLUMN = Keyword.intern(ERR_NS, "column"); |
| 7415 | final static public Keyword ERR_PHASE = Keyword.intern(ERR_NS, "phase"); |
| 7416 | final static public Keyword ERR_SYMBOL = Keyword.intern(ERR_NS, "symbol"); |
| 7417 | |
| 7418 | // Compile error phases |
| 7419 | final static public Keyword PHASE_READ = Keyword.intern(null, "read-source"); |
| 7420 | final static public Keyword PHASE_MACRO_SYNTAX_CHECK = Keyword.intern(null, "macro-syntax-check"); |
| 7421 | final static public Keyword PHASE_MACROEXPANSION = Keyword.intern(null, "macroexpansion"); |
| 7422 | final static public Keyword PHASE_COMPILE_SYNTAX_CHECK = Keyword.intern(null, "compile-syntax-check"); |
| 7423 | final static public Keyword PHASE_COMPILATION = Keyword.intern(null, "compilation"); |
| 7424 | final static public Keyword PHASE_EXECUTION = Keyword.intern(null, "execution"); |
| 7425 | |
| 7426 | final static public Keyword SPEC_PROBLEMS = Keyword.intern("clojure.spec.alpha", "problems"); |
| 7427 | |
| 7428 | // Class compile exception |
| 7429 | public CompilerException(String source, int line, int column, Throwable cause){ |
| 7430 | this(source, line, column, null, cause); |
| 7431 | } |
| 7432 | |
| 7433 | public CompilerException(String source, int line, int column, Symbol sym, Throwable cause){ |
| 7434 | this(source, line, column, sym, PHASE_COMPILE_SYNTAX_CHECK, cause); |
| 7435 | } |
| 7436 | |
| 7437 | public CompilerException(String source, int line, int column, Symbol sym, Keyword phase, Throwable cause){ |
| 7438 | super(makeMsg(source, line, column, sym, phase, cause), cause); |
| 7439 | this.source = source; |
| 7440 | this.line = line; |
| 7441 | Associative m = RT.map(ERR_PHASE, phase, ERR_LINE, line, ERR_COLUMN, column); |
| 7442 | if(source != null) m = RT.assoc(m, ERR_SOURCE, source); |
| 7443 | if(sym != null) m = RT.assoc(m, ERR_SYMBOL, sym); |
| 7444 | this.data = m; |
| 7445 | } |
| 7446 | |
| 7447 | public IPersistentMap getData(){ |
| 7448 | return (IPersistentMap)data; |
| 7449 | } |
| 7450 | |
| 7451 | private static String verb(Keyword phase) { |
| 7452 | if(PHASE_READ.equals(phase)){ |
| 7453 | return "reading source"; |
| 7454 | } else if(PHASE_COMPILE_SYNTAX_CHECK.equals(phase) || PHASE_COMPILATION.equals(phase)){ |
| 7455 | return "compiling"; |
| 7456 | } else { |
| 7457 | return "macroexpanding"; |
| 7458 | } |
| 7459 | } |
| 7460 | |