diff 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
line wrap: on
line diff
--- a/src/luan/parser/ParseException.java	Fri May 30 08:57:24 2014 +0000
+++ b/src/luan/parser/ParseException.java	Sun Jun 01 07:07:31 2014 +0000
@@ -1,14 +1,16 @@
 package luan.parser;
 
+import luan.LuanSource;
+
 
 public class ParseException extends Exception {
-	public final String text;
+	public final LuanSource src;
 	public final int iCurrent;
 	public final int iHigh;
 
-	ParseException(String msg,String text,int iCurrent,int iHigh) {
+	ParseException(String msg,LuanSource src,int iCurrent,int iHigh) {
 		super(msg);
-		this.text = text;
+		this.src = src;
 		this.iCurrent = iCurrent;
 		this.iHigh = iHigh;
 //System.out.println("iCurrent = "+iCurrent);
@@ -23,8 +25,8 @@
 			int line = 0;
 			int i = -1;
 			while(true) {
-				int j = text.indexOf('\n',i+1);
-				if( j == -1 || j > index )
+				int j = src.text.indexOf('\n',i+1);
+				if( j == -1 || j >= index )
 					break;
 				i = j;
 				line++;
@@ -35,13 +37,13 @@
 	}
 
 	private String[] lines() {
-		return text.split("\n",-1);
+		return src.text.split("\n",-1);
 	}
 
 	public String getFancyMessage() {
 		Location loc = new Location(iCurrent);
 		String line = lines()[loc.line];
-		String msg = getMessage() +  " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ")\n";
+		String msg = getMessage() +  " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ") in " + src.name + "\n";
 		StringBuilder sb = new StringBuilder(msg);
 		sb.append( line + "\n" );
 		for( int i=0; i<loc.pos; i++ ) {