regex fixes & stuff

This commit is contained in:
Jill 2022-05-09 00:06:22 +03:00
parent cbcb649841
commit 472df2027d
3 changed files with 22 additions and 4 deletions

7
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"Lua.runtime.version": "Lua 5.3",
"Lua.runtime.special": {
"include": "require"
},
"Lua.workspace.useGitIgnore": false
}

View File

@ -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], '');

11
override/main.lua Normal file
View File

@ -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