MCPcopy Index your code
hub / github.com/Doorman11991/smallcode / _parseDict

Function _parseDict

src/tools/liquid_tool_parser.js:277–312  ·  view source on GitHub ↗
(text, pos)

Source from the content-addressed store, hash-verified

275}
276
277function _parseDict(text, pos) {
278 // Find matching }
279 let depth = 1;
280 let i = pos + 1;
281 while (i < text.length && depth > 0) {
282 const c = text[i];
283 if (c === "'" || c === '"') { i = _skipString(text, i); if (i === -1) return null; continue; }
284 if (c === '[' || c === '(' || c === '{') depth++;
285 else if (c === ']' || c === ')' || c === '}') {
286 depth--;
287 if (depth === 0 && c === '}') break;
288 }
289 i++;
290 }
291 if (depth !== 0) return null;
292 const inner = text.slice(pos + 1, i);
293 const obj = {};
294 let p = 0;
295 while (p < inner.length) {
296 while (p < inner.length && /\s/.test(inner[p])) p++;
297 if (p >= inner.length) break;
298 const k = _parseValue(inner, p);
299 if (!k || (typeof k.value !== 'string' && typeof k.value !== 'number')) return null;
300 p = k.next;
301 while (p < inner.length && /\s/.test(inner[p])) p++;
302 if (inner[p] !== ':') return null;
303 p++;
304 const v = _parseValue(inner, p);
305 if (!v) return null;
306 obj[String(k.value)] = v.value;
307 p = v.next;
308 while (p < inner.length && /\s/.test(inner[p])) p++;
309 if (p < inner.length && inner[p] === ',') p++;
310 }
311 return { value: obj, next: i + 1 };
312}
313
314module.exports = { parseLiquidToolCalls };

Callers 1

_parseValueFunction · 0.85

Calls 2

_skipStringFunction · 0.85
_parseValueFunction · 0.85

Tested by

no test coverage detected