diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-02 11:56:54 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-02 12:52:57 +0100 |
commit | 8785e3801b3bd4b3add20f004c9492565fb77fbd (patch) | |
tree | 303c831d4c22e138a4e2ce2cbf61921e35dfc4f4 /src | |
parent | 57de149902761c4ed5d9c199fd0818aad781bde3 (diff) | |
download | fengari-8785e3801b3bd4b3add20f004c9492565fb77fbd.tar.gz fengari-8785e3801b3bd4b3add20f004c9492565fb77fbd.tar.bz2 fengari-8785e3801b3bd4b3add20f004c9492565fb77fbd.zip |
[Parsing tests] SETLIST
Diffstat (limited to 'src')
-rw-r--r-- | src/llex.js | 14 | ||||
-rw-r--r-- | src/lobject.js | 2 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/llex.js b/src/llex.js index f90dc47..dab384d 100644 --- a/src/llex.js +++ b/src/llex.js @@ -132,8 +132,8 @@ const save = function(ls, c) { }; const luaX_token2str = function(ls, token) { - if (token < FIRST_RESERVED) { /* single-byte symbols? */ - return `'${String.fromCharCode(token)}'`; + if (typeof token === "string" || token < FIRST_RESERVED) { /* single-byte symbols? */ + return `'${typeof token === "string" ? token : String.fromCharCode(token)}'`; } else { let s = luaX_tokens[token - FIRST_RESERVED]; if (token < R.TK_EOS) /* fixed format (symbols and reserved words)? */ @@ -266,11 +266,12 @@ const txtToken = function(ls, token) { const lexerror = function(ls, msg, token) { msg = ldebug.luaG_addinfo(ls.L, msg, ls.source, ls.linenumber); if (token) - lapi.lua_pushstring(ls.L, `${msg} near ${txtToken(ls, token)}`); + lapi.lua_pushstring(ls.L, `${msg instanceof TValue ? msg.value : msg} near ${txtToken(ls, token)}`); ldo.luaD_throw(ls.L, TS.LUA_ERRSYNTAX); }; const luaX_syntaxerror = function(ls, msg) { + msg = msg instanceof TValue ? msg.value : msg; lexerror(ls, msg, ls.t.token); }; @@ -584,7 +585,10 @@ const llex = function(ls, seminfo) { const luaX_next = function(ls) { ls.lastline = ls.linenumber; if (ls.lookahead.token !== R.TK_EOS) { /* is there a look-ahead token? */ - ls.t = ls.lookahead; /* use this one */ + ls.t.token = ls.lookahead.token; /* use this one */ + ls.t.seminfo.i = ls.lookahead.seminfo.i; + ls.t.seminfo.r = ls.lookahead.seminfo.r; + ls.t.seminfo.ts = ls.lookahead.seminfo.ts; // TODO ? ls.lookahead.token = R.TK_EOS; /* and discharge it */ } else ls.t.token = llex(ls, ls.t.seminfo); /* read next token */ @@ -592,7 +596,7 @@ const luaX_next = function(ls) { const luaX_lookahead = function(ls) { assert(ls.lookahead.token === R.TK_EOS); - ls.lookahead.token = llex(ls. ls.lookahead.seminfo); + ls.lookahead.token = llex(ls, ls.lookahead.seminfo); return ls.lookahead.token; }; diff --git a/src/lobject.js b/src/lobject.js index 0ef6e9a..3d9edb0 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -221,6 +221,8 @@ const PRE = "[string \""; const POS = "\"]"; const luaO_chunkid = function(source, bufflen) { + source = source instanceof TValue ? source.value : source; + bufflen = bufflen instanceof TValue ? bufflen.value : bufflen; let l = source.length; let out = ""; if (source[0] === '=') { /* 'literal' source */ |