Update qkf/stepRegistry.js
This commit is contained in:
@@ -9,12 +9,32 @@ function normalizeText(t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function patternToRegex(pattern) {
|
function patternToRegex(pattern) {
|
||||||
const parts = String(pattern).split("{string}");
|
// Supports:
|
||||||
const escaped = parts.map((p) => escapeRegex(normalizeText(p)));
|
// - {string} -> "value" OR 'value' OR bareWord(s)
|
||||||
const joined = escaped.join("\\s+(.+?)\\s+");
|
// Also normalizes whitespace
|
||||||
const final = "^" + joined.replace(/\s+/g, "\\s+") + "$";
|
const norm = normalizeText(pattern);
|
||||||
return new RegExp(final, "i");
|
|
||||||
|
// Split around {string}
|
||||||
|
const parts = norm.split("{string}").map((p) => escapeRegex(p));
|
||||||
|
|
||||||
|
// Capture:
|
||||||
|
// - "..." or '...' or unquoted token(s) (until end)
|
||||||
|
// We make it non-greedy and allow extra spaces.
|
||||||
|
const CAPTURE = `(?:"([^"]+)"|'([^']+)'|([^]+?))`;
|
||||||
|
|
||||||
|
let regexStr = "^";
|
||||||
|
for (let i = 0; i < parts.length; i++) {
|
||||||
|
regexStr += parts[i];
|
||||||
|
if (i < parts.length - 1) {
|
||||||
|
// allow flexible whitespace around the capture
|
||||||
|
regexStr += "\\s+" + CAPTURE + "\\s+";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
regexStr += "$";
|
||||||
|
|
||||||
|
return new RegExp(regexStr.replace(/\s+/g, "\\s+"), "i");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function createStepRegistry(initialCtx = {}) {
|
function createStepRegistry(initialCtx = {}) {
|
||||||
const defs = [];
|
const defs = [];
|
||||||
@@ -41,7 +61,11 @@ function createStepRegistry(initialCtx = {}) {
|
|||||||
const m = d.regex.exec(text);
|
const m = d.regex.exec(text);
|
||||||
if (!m) continue;
|
if (!m) continue;
|
||||||
|
|
||||||
const captures = m.slice(1).map((x) => normalizeText(x));
|
const captures = [];
|
||||||
|
for (let i = 1; i < m.length; i += 3) {
|
||||||
|
const v = m[i] || m[i + 1] || m[i + 2] || "";
|
||||||
|
captures.push(normalizeText(v));
|
||||||
|
}
|
||||||
const ctx = { ...initialCtx, ...extraCtx };
|
const ctx = { ...initialCtx, ...extraCtx };
|
||||||
|
|
||||||
// ✅ Begin step tracking so QKF calls are awaited even if step defs don't `await`
|
// ✅ Begin step tracking so QKF calls are awaited even if step defs don't `await`
|
||||||
|
|||||||
Reference in New Issue
Block a user