Mercurial Hosting > luan
comparison core/src/luan/impl/ParseException.java @ 645:859c0dedc8b6
remove LuanSource
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Mar 2016 18:09:51 -0600 |
parents | 3dcb0f9bee82 |
children | b620b8e1010f |
comparison
equal
deleted
inserted
replaced
644:ba1e318377c5 | 645:859c0dedc8b6 |
---|---|
1 package luan.impl; | 1 package luan.impl; |
2 | |
3 import luan.LuanSource; | |
4 | 2 |
5 | 3 |
6 public final class ParseException extends Exception { | 4 public final class ParseException extends Exception { |
7 public final LuanSource src; | 5 // public final LuanSource src; |
6 public final String sourceName; | |
7 public final String text; | |
8 public final int iCurrent; | 8 public final int iCurrent; |
9 public final int iHigh; | 9 public final int iHigh; |
10 | 10 |
11 ParseException(String msg,LuanSource src,int iCurrent,int iHigh) { | 11 ParseException(String msg,String sourceName,String text,int iCurrent,int iHigh) { |
12 super(msg); | 12 super(msg); |
13 this.src = src; | 13 // this.src = src; |
14 this.sourceName = sourceName; | |
15 this.text = text; | |
14 this.iCurrent = iCurrent; | 16 this.iCurrent = iCurrent; |
15 this.iHigh = iHigh; | 17 this.iHigh = iHigh; |
16 //System.out.println("iCurrent = "+iCurrent); | 18 //System.out.println("iCurrent = "+iCurrent); |
17 //System.out.println("iHigh = "+iHigh); | 19 //System.out.println("iHigh = "+iHigh); |
18 } | 20 } |
23 | 25 |
24 Location(int index) { | 26 Location(int index) { |
25 int line = 0; | 27 int line = 0; |
26 int i = -1; | 28 int i = -1; |
27 while(true) { | 29 while(true) { |
28 int j = src.text.indexOf('\n',i+1); | 30 int j = text.indexOf('\n',i+1); |
29 if( j == -1 || j >= index ) | 31 if( j == -1 || j >= index ) |
30 break; | 32 break; |
31 i = j; | 33 i = j; |
32 line++; | 34 line++; |
33 } | 35 } |
35 this.pos = index - i - 1; | 37 this.pos = index - i - 1; |
36 } | 38 } |
37 } | 39 } |
38 | 40 |
39 private String[] lines() { | 41 private String[] lines() { |
40 return src.text.split("\n",-1); | 42 return text.split("\n",-1); |
41 } | 43 } |
42 | 44 |
43 public String getFancyMessage() { | 45 public String getFancyMessage() { |
44 Location loc = new Location(iCurrent); | 46 Location loc = new Location(iCurrent); |
45 String line = lines()[loc.line]; | 47 String line = lines()[loc.line]; |
46 String msg = getMessage() + " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ") in " + src.name + "\n"; | 48 String msg = getMessage() + " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ") in " + sourceName + "\n"; |
47 StringBuilder sb = new StringBuilder(msg); | 49 StringBuilder sb = new StringBuilder(msg); |
48 sb.append( line + "\n" ); | 50 sb.append( line + "\n" ); |
49 for( int i=0; i<loc.pos; i++ ) { | 51 for( int i=0; i<loc.pos; i++ ) { |
50 sb.append( line.charAt(i)=='\t' ? '\t' : ' ' ); | 52 sb.append( line.charAt(i)=='\t' ? '\t' : ' ' ); |
51 } | 53 } |