in src/parser/WDL/entities/Context.js [57:110]
static preprocessTheTaskOntoCommandMap(src) {
const genericTaskCommandMap = new Map();
const taskRegex = /\s*^task\s*.+\s*\{/gm;
const tasks = [];
let task = taskRegex.exec(src);
while (task) {
const message = task[0].replace(/task\s+/, '').trim();
tasks.push({
message: message.slice(0, message.length - 1).trim(),
lastIndex: taskRegex.lastIndex,
});
task = taskRegex.exec(src);
}
const commandRegex = /\s*command\s*({|<<<)/gm;// [\s\S]*?\s*\n\s*(}|>>>)
const commands = [];
let command = commandRegex.exec(src);
while (command) {
commands.push({
lastIndex: commandRegex.lastIndex,
type: command[1],
});
command = commandRegex.exec(src);
}
const taskLength = tasks.length;
const cmdLength = commands.length;
let cmdIdx = 0;
_.forEach(tasks, (val, idx, arr) => {
const nextTask = idx < taskLength - 1 ? arr[idx + 1] : undefined;
const currCmd = cmdIdx < cmdLength ? commands[cmdIdx] : undefined;
if (currCmd &&
(!nextTask || (val.lastIndex < currCmd.lastIndex && currCmd.lastIndex < nextTask.lastIndex))) {
genericTaskCommandMap.set(val.message, currCmd);
cmdIdx += 1;
}
});
genericTaskCommandMap.forEach((val, key) => {
const lastIndex = val.lastIndex;
const closer = val.type === '{' ? '}' : '>>>';
genericTaskCommandMap.set(key, {
command: Context.traceTheCommand(src, lastIndex, closer),
type: val.type,
});
});
return genericTaskCommandMap;
}