Mercurial Hosting > luan
comparison src/luan/parser/ParseException.java @ 118:735708619119
add Debug.debug()
git-svn-id: https://luan-java.googlecode.com/svn/trunk@119 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 01 Jun 2014 07:07:31 +0000 |
parents | 754e6030c029 |
children |
comparison
equal
deleted
inserted
replaced
117:e935581cf9fb | 118:735708619119 |
---|---|
1 package luan.parser; | 1 package luan.parser; |
2 | |
3 import luan.LuanSource; | |
2 | 4 |
3 | 5 |
4 public class ParseException extends Exception { | 6 public class ParseException extends Exception { |
5 public final String text; | 7 public final LuanSource src; |
6 public final int iCurrent; | 8 public final int iCurrent; |
7 public final int iHigh; | 9 public final int iHigh; |
8 | 10 |
9 ParseException(String msg,String text,int iCurrent,int iHigh) { | 11 ParseException(String msg,LuanSource src,int iCurrent,int iHigh) { |
10 super(msg); | 12 super(msg); |
11 this.text = text; | 13 this.src = src; |
12 this.iCurrent = iCurrent; | 14 this.iCurrent = iCurrent; |
13 this.iHigh = iHigh; | 15 this.iHigh = iHigh; |
14 //System.out.println("iCurrent = "+iCurrent); | 16 //System.out.println("iCurrent = "+iCurrent); |
15 //System.out.println("iHigh = "+iHigh); | 17 //System.out.println("iHigh = "+iHigh); |
16 } | 18 } |
21 | 23 |
22 Location(int index) { | 24 Location(int index) { |
23 int line = 0; | 25 int line = 0; |
24 int i = -1; | 26 int i = -1; |
25 while(true) { | 27 while(true) { |
26 int j = text.indexOf('\n',i+1); | 28 int j = src.text.indexOf('\n',i+1); |
27 if( j == -1 || j > index ) | 29 if( j == -1 || j >= index ) |
28 break; | 30 break; |
29 i = j; | 31 i = j; |
30 line++; | 32 line++; |
31 } | 33 } |
32 this.line = line; | 34 this.line = line; |
33 this.pos = index - i - 1; | 35 this.pos = index - i - 1; |
34 } | 36 } |
35 } | 37 } |
36 | 38 |
37 private String[] lines() { | 39 private String[] lines() { |
38 return text.split("\n",-1); | 40 return src.text.split("\n",-1); |
39 } | 41 } |
40 | 42 |
41 public String getFancyMessage() { | 43 public String getFancyMessage() { |
42 Location loc = new Location(iCurrent); | 44 Location loc = new Location(iCurrent); |
43 String line = lines()[loc.line]; | 45 String line = lines()[loc.line]; |
44 String msg = getMessage() + " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ")\n"; | 46 String msg = getMessage() + " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ") in " + src.name + "\n"; |
45 StringBuilder sb = new StringBuilder(msg); | 47 StringBuilder sb = new StringBuilder(msg); |
46 sb.append( line + "\n" ); | 48 sb.append( line + "\n" ); |
47 for( int i=0; i<loc.pos; i++ ) { | 49 for( int i=0; i<loc.pos; i++ ) { |
48 sb.append( line.charAt(i)=='\t' ? '\t' : ' ' ); | 50 sb.append( line.charAt(i)=='\t' ? '\t' : ' ' ); |
49 } | 51 } |