From 472df2027dba4e00634e1568fe02d256bd03e879 Mon Sep 17 00:00:00 2001 From: Jill Monoids Date: Mon, 9 May 2022 00:06:22 +0300 Subject: [PATCH] regex fixes & stuff --- .vscode/settings.json | 7 +++++++ index.js | 8 ++++---- override/main.lua | 11 +++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 override/main.lua diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ce17ba2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "Lua.runtime.version": "Lua 5.3", + "Lua.runtime.special": { + "include": "require" + }, + "Lua.workspace.useGitIgnore": false +} \ No newline at end of file diff --git a/index.js b/index.js index d62023d..288c0dc 100644 --- a/index.js +++ b/index.js @@ -101,7 +101,7 @@ function transpile(parsed, indent, prefix, gl) { } classes[d.name] = contents; - return `${comments}---@class ${d.name}${d.extends ? ' : ' + d.extends : ''}${n}${contents.filter(e => e[0] === 'const').map(c => `---@field public ${c[1].name} ${transpileType(c[1].type)}${n}`).join('')}${global ? '' : '__class_'}${d.name} = {}${n}${contents.filter(e => e[0] !== 'const').map(c => transpile(c, indent, `${global ? '' : '__class_'}${d.name}`, global)).join(n)}\n`; + return `${comments}---@class ${d.name}${d.extends ? ' : ' + d.extends : ''}${n}${contents.filter(e => e[0] === 'const').map(c => `---@field ${c[1].type.startsWith('Readonly<') ? 'protected' : 'public'} ${c[1].name} ${transpileType(c[1].type)}${n}`).join('')}${global ? '' : '__class_'}${d.name} = {}${n}${contents.filter(e => e[0] !== 'const').map(c => transpile(c, indent, `${global ? '' : '__class_'}${d.name}`, global)).join(n)}\n`; case 'function': if (d.arguments[0] && d.arguments[0].type === 'void') d.arguments = d.arguments.slice(1); return `${comments}${d.arguments.map(p => `---@param ${p.name.replace('?', '')} ${transpileType(p.type)}${p.comment ? ' @' + p.comment : ''}${n}`).join('')}---@return ${transpileType(d.returns)}${d.returnsComment ? ' @' + d.returnsComment : ''}${n}function ${prefix ? prefix + (gl ? '.' : ':') : ''}${d.name}(${d.arguments.map(a => a.name.replace('?', '')).join(', ')}) end`; @@ -164,7 +164,7 @@ function parse(code, originalCode) { // look for functions let functionFreeCode = code; - const functions = /(function)?\s(\w+)\s*\(([^;]*)\)(\s*:\s*([\w\[\]\s|<>,:]+))?/g; // wow this sucks + const functions = /(function)?\s([\w_]+)\s*\(([^;]*)\)(\s*:\s*([\w\[\]\s|<>,:]+))?/g; // wow this sucks while ((match = functions.exec(code)) !== null) { parsedElements++; functionFreeCode = functionFreeCode.replace(match[0], ''); @@ -210,7 +210,7 @@ function parse(code, originalCode) { // looks for enums let enumFreeCode = code; - const enums = /enum (\w+) ?{([^}]*)}/g; + const enums = /enum ([_\w]+) ?{([^}]*)}/g; while ((match = enums.exec(code)) !== null) { parsedElements++; enumFreeCode = enumFreeCode.replace(match[0], ''); @@ -233,7 +233,7 @@ function parse(code, originalCode) { // looks for constants / properties let constFreeCode = code; - const consts = /(\w+)\s*:\s*(\w+)/g; + const consts = /([\w_]+)\s*:\s*([\w<>\s,]+)/g; while ((match = consts.exec(code)) !== null) { parsedElements++; constFreeCode = constFreeCode.replace(match[0], ''); diff --git a/override/main.lua b/override/main.lua new file mode 100644 index 0000000..42892c7 --- /dev/null +++ b/override/main.lua @@ -0,0 +1,11 @@ +---@alias void nil +---@alias float number +---@alias int number +---@type boolean +REPENTANCE = nil +---@return void +function StartDebug() end +---@param modName string +---@param apiVersion APIVersion +---@return Mod +function RegisterMod(modName, apiVersion) end \ No newline at end of file