Mercurial Hosting > luan
changeset 1114:540e1940170f
improve ParseException
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Aug 2017 16:21:45 -0600 |
parents | 22652f4020fb |
children | 809d74db1415 |
files | src/luan/lib/parser/ParseException.java |
diffstat | 1 files changed, 14 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/lib/parser/ParseException.java Wed Aug 02 19:00:24 2017 -0600 +++ b/src/luan/lib/parser/ParseException.java Thu Aug 03 16:21:45 2017 -0600 @@ -48,12 +48,21 @@ } @Override public String getMessage() { - Location loc = new Location(errorIndex); - String line = lines()[loc.line]; - String msg = super.getMessage() + " (line " + (loc.line+1) + ", pos " + (loc.pos+1) + ")\n"; - StringBuilder sb = new StringBuilder(msg); + String line; + int pos; + StringBuilder sb = new StringBuilder(super.getMessage()); + if( text.indexOf('\n') == -1 ) { + line = text; + pos = errorIndex; + sb.append( " (position " + (pos+1) + ")\n" ); + } else { + Location loc = new Location(errorIndex); + line = lines()[loc.line]; + pos = loc.pos; + sb.append( " (line " + (loc.line+1) + ", pos " + (pos+1) + ")\n" ); + } sb.append( line + "\n" ); - for( int i=0; i<loc.pos; i++ ) { + for( int i=0; i<pos; i++ ) { sb.append( line.charAt(i)=='\t' ? '\t' : ' ' ); } sb.append("^\n");