summaryrefslogtreecommitdiff
path: root/src/llex.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-02 11:56:54 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-02 12:52:57 +0100
commit8785e3801b3bd4b3add20f004c9492565fb77fbd (patch)
tree303c831d4c22e138a4e2ce2cbf61921e35dfc4f4 /src/llex.js
parent57de149902761c4ed5d9c199fd0818aad781bde3 (diff)
downloadfengari-8785e3801b3bd4b3add20f004c9492565fb77fbd.tar.gz
fengari-8785e3801b3bd4b3add20f004c9492565fb77fbd.tar.bz2
fengari-8785e3801b3bd4b3add20f004c9492565fb77fbd.zip
[Parsing tests] SETLIST
Diffstat (limited to 'src/llex.js')
-rw-r--r--src/llex.js14
1 files changed, 9 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;
};