add comment support to more stuff

This commit is contained in:
Jill 2021-11-10 11:10:14 +00:00
parent b5e1131729
commit cb20dd6e9b
1 changed files with 26 additions and 2 deletions

View File

@ -177,7 +177,19 @@ function parse(code, originalCode) {
while ((match = enums.exec(code)) !== null) {
parsedElements++;
enumFreeCode = enumFreeCode.replace(match[0], '');
elements.push(['enum', {name: match[1], contents: match[2].split(',').filter(c => c.split('=').length === 2).map(c => {return {name: c.split('=')[0].trim(), value: c.split('=')[1].trim()}})}]);
const origIndex = originalCode.indexOf(match[0]);
const comment = /\/\*(.*?)\*\//gs;
let comments = [];
let comm;
while ((comm = comment.exec(originalCode.slice(0, origIndex))) !== null) {
comments.push([comm[1], comm.index + comm[0].length]);
}
comments = comments.filter(c => Math.abs(origIndex - c[1]) < 10);
const c = comments.pop();
//if (c) c[0] += 'isaac-lua-definitions debug: comment distance = ' + (origIndex - c[1]).toString();
elements.push(['enum', {name: match[1], contents: match[2].split(',').filter(c => c.split('=').length === 2).map(c => {return {name: c.split('=')[0].trim(), value: c.split('=')[1].trim()}}), comment: (c || [null])[0]}]);
}
code = enumFreeCode;
@ -187,7 +199,19 @@ function parse(code, originalCode) {
while ((match = consts.exec(code)) !== null) {
parsedElements++;
constFreeCode = constFreeCode.replace(match[0], '');
elements.push(['const', {name: match[1], type: match[2]}]);
const origIndex = originalCode.indexOf(match[0]);
const comment = /\/\*(.*?)\*\//gs;
let comments = [];
let comm;
while ((comm = comment.exec(originalCode.slice(0, origIndex))) !== null) {
comments.push([comm[1], comm.index + comm[0].length]);
}
comments = comments.filter(c => Math.abs(origIndex - c[1]) < 10);
const c = comments.pop();
//if (c) c[0] += 'isaac-lua-definitions debug: comment distance = ' + (origIndex - c[1]).toString();
elements.push(['const', {name: match[1], type: match[2], comment: (c || [null])[0]}]);
}
code = constFreeCode;