Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LuaJIT syntax extensions #92

Closed
sapphyrus opened this issue Dec 30, 2020 · 1 comment · Fixed by #97
Closed

Support LuaJIT syntax extensions #92

sapphyrus opened this issue Dec 30, 2020 · 1 comment · Fixed by #97
Labels
enhancement Request for functionality covering an entirely new use case

Comments

@sapphyrus
Copy link

LuaJIT extends the Lua syntax with some extra stuff:

Extensions to the Lua Parser
The parser for Lua source code treats numeric literals with the suffixes LL or ULL as signed or unsigned 64 bit integers. Case doesn't matter, but uppercase is recommended for readability. It handles both decimal (42LL) and hexadecimal (0x2aLL) literals.
The imaginary part of complex numbers can be specified by suffixing number literals with i or I, e.g. 12.5i. Caveat: you'll need to use 1i to get an imaginary part with the value one, since i itself still refers to a variable named i.

See https://luajit.org/ext_ffi_api.html#literals:~:text=Extensions%20to%20the%20Lua%20Parser

These don't get parsed correctly by luaparse, even with luaVersion set to 'LuaJIT':

var parser = require('luaparse');
var ast = parser.parse('local x = 1234ULL', {luaVersion: 'LuaJIT'});
console.log(JSON.stringify(ast));
D:\dev\node_modules\luaparse\luaparse.js:614
    throw error;
    ^
SyntaxError: [1:17] '=' expected near '<eof>'
    at raise (D:\dev\node_modules\luaparse\luaparse.js:609:26)
    at expect (D:\dev\node_modules\luaparse\luaparse.js:1298:10)
    at parseAssignmentOrCallStatement (D:\dev\node_modules\luaparse\luaparse.js:2119:5)
    at parseStatement (D:\dev\node_modules\luaparse\luaparse.js:1763:12)
    at parseBlock (D:\dev\node_modules\luaparse\luaparse.js:1700:19)
    at parseChunk (D:\dev\node_modules\luaparse\luaparse.js:1675:16)
    at end (D:\dev\node_modules\luaparse\luaparse.js:2658:17)
    at Object.parse (D:\dev\node_modules\luaparse\luaparse.js:2629:31)
    at Object.<anonymous> (D:\dev\test.js:2:18)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
@fstirlitz fstirlitz added the enhancement Request for functionality covering an entirely new use case label Jan 4, 2021
@fstirlitz
Copy link
Owner

Previously suggested in #57. I was privately working on a patch adapting that PR. Might merge it when I have the time.

@fstirlitz fstirlitz added duplicate An issue already exists covering the same or substantially overlapping problem and removed duplicate An issue already exists covering the same or substantially overlapping problem labels Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for functionality covering an entirely new use case
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants