track index in getvar replacement

This commit is contained in:
LenAnderson 2024-06-20 15:52:08 -04:00
parent 538724739b
commit 9b3cd719d7
1 changed files with 11 additions and 5 deletions

View File

@ -514,11 +514,14 @@ export class SlashCommandParser {
} }
replaceGetvar(value) { replaceGetvar(value) {
return value.replace(/{{(get(?:global)?var)::([^}]+)}}/gi, (_, cmd, name) => { return value.replace(/{{(get(?:global)?var)::([^}]+)}}/gi, (match, cmd, name, idx) => {
name = name.trim(); name = name.trim();
const startIdx = this.index - value.length + idx;
const endIdx = this.index - value.length + idx + match.length;
// store pipe // store pipe
const pipeName = `_PARSER_${uuidv4()}`; const pipeName = `_PARSER_${uuidv4()}`;
const storePipe = new SlashCommandExecutor(null); { const storePipe = new SlashCommandExecutor(startIdx); {
storePipe.end = endIdx;
storePipe.command = this.commands['let']; storePipe.command = this.commands['let'];
storePipe.name = 'let'; storePipe.name = 'let';
const nameAss = new SlashCommandUnnamedArgumentAssignment(); const nameAss = new SlashCommandUnnamedArgumentAssignment();
@ -529,7 +532,8 @@ export class SlashCommandParser {
this.closure.executorList.push(storePipe); this.closure.executorList.push(storePipe);
} }
// getvar / getglobalvar // getvar / getglobalvar
const getvar = new SlashCommandExecutor(null); { const getvar = new SlashCommandExecutor(startIdx); {
getvar.end = endIdx;
getvar.command = this.commands[cmd]; getvar.command = this.commands[cmd];
getvar.name = 'cmd'; getvar.name = 'cmd';
const nameAss = new SlashCommandUnnamedArgumentAssignment(); const nameAss = new SlashCommandUnnamedArgumentAssignment();
@ -539,7 +543,8 @@ export class SlashCommandParser {
} }
// set to temp scoped var // set to temp scoped var
const varName = `_PARSER_${uuidv4()}`; const varName = `_PARSER_${uuidv4()}`;
const setvar = new SlashCommandExecutor(null); { const setvar = new SlashCommandExecutor(startIdx); {
setvar.end = endIdx;
setvar.command = this.commands['let']; setvar.command = this.commands['let'];
setvar.name = 'let'; setvar.name = 'let';
const nameAss = new SlashCommandUnnamedArgumentAssignment(); const nameAss = new SlashCommandUnnamedArgumentAssignment();
@ -550,7 +555,8 @@ export class SlashCommandParser {
this.closure.executorList.push(setvar); this.closure.executorList.push(setvar);
} }
// return pipe // return pipe
const returnPipe = new SlashCommandExecutor(null); { const returnPipe = new SlashCommandExecutor(startIdx); {
returnPipe.end = endIdx;
returnPipe.command = this.commands['return']; returnPipe.command = this.commands['return'];
returnPipe.name = 'return'; returnPipe.name = 'return';
const varAss = new SlashCommandUnnamedArgumentAssignment(); const varAss = new SlashCommandUnnamedArgumentAssignment();