From d38e08f102465ea39588747f0d5aca3fe2270f2a Mon Sep 17 00:00:00 2001 From: gamax92 Date: Mon, 7 Jul 2014 21:42:53 -0600 Subject: [PATCH] fix txtToken, lexerror --- src/main/java/org/luaj/vm3/compiler/LexState.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/luaj/vm3/compiler/LexState.java b/src/main/java/org/luaj/vm3/compiler/LexState.java index 9d680cd4a..0f404f087 100644 --- a/src/main/java/org/luaj/vm3/compiler/LexState.java +++ b/src/main/java/org/luaj/vm3/compiler/LexState.java @@ -252,7 +252,7 @@ public class LexState { case TK_NAME: case TK_STRING: case TK_NUMBER: - return new String( buff, 0, nbuff ); + return new String( buff, 0, nbuff ).replace("\0", ""); default: return token2str( token ); } @@ -260,10 +260,14 @@ public class LexState { void lexerror( String msg, int token ) { String cid = Lua.chunkid( source.tojstring() ); + // Is the string pushing needed? L.pushfstring( cid+":"+linenumber+": "+msg ); if ( token != 0 ) L.pushfstring( "syntax error: "+msg+" near "+txtToken(token) ); - throw new LuaError(cid+":"+linenumber+": "+msg); + if ( token != 0 ) + throw new LuaError(cid+":"+linenumber+": "+msg+" near "+LUA_QS(txtToken(token))); + else + throw new LuaError(cid+":"+linenumber+": "+msg); } void syntaxerror( String msg ) { @@ -553,7 +557,7 @@ public class LexState { continue; default: if (!isdigit(current)) - syntaxerror("invalid escape sequence near '\\" + ((char) current) + "'"); + lexerror("invalid escape sequence near '\\" + ((char) current) + "'", 0); else { /* \xxx */ int i = 0; c = 0; @@ -562,7 +566,7 @@ public class LexState { nextChar(); } while (++i < 3 && isdigit(current)); if (c > UCHAR_MAX) - syntaxerror("decimal escape too large near '\\" + c + "'"); + lexerror("decimal escape too large near '\\" + c + "'", 0); save(c); } continue; @@ -1390,7 +1394,7 @@ public class LexState { return; } default: { - this.syntaxerror("unexpected symbol near '" + txtToken(t.token) + "'"); + this.syntaxerror("unexpected symbol"); return; } }