add comment support to more stuff
This commit is contained in:
parent
b5e1131729
commit
cb20dd6e9b
28
index.js
28
index.js
|
@ -177,7 +177,19 @@ function parse(code, originalCode) {
|
||||||
while ((match = enums.exec(code)) !== null) {
|
while ((match = enums.exec(code)) !== null) {
|
||||||
parsedElements++;
|
parsedElements++;
|
||||||
enumFreeCode = enumFreeCode.replace(match[0], '');
|
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;
|
code = enumFreeCode;
|
||||||
|
|
||||||
|
@ -187,7 +199,19 @@ function parse(code, originalCode) {
|
||||||
while ((match = consts.exec(code)) !== null) {
|
while ((match = consts.exec(code)) !== null) {
|
||||||
parsedElements++;
|
parsedElements++;
|
||||||
constFreeCode = constFreeCode.replace(match[0], '');
|
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;
|
code = constFreeCode;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue