MCPcopy
hub / github.com/Doorman11991/smallcode / _parseKwargs

Function _parseKwargs

src/tools/liquid_tool_parser.js:143–164  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

141// Parse `key=value, key=value, ...` (Python kwargs). Returns plain object,
142// or null on parse failure.
143function _parseKwargs(text) {
144 const out = {};
145 let pos = 0;
146 while (pos < text.length) {
147 while (pos < text.length && /\s/.test(text[pos])) pos++;
148 if (pos >= text.length) break;
149
150 const keyMatch = text.slice(pos).match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*/);
151 if (!keyMatch) return null;
152 const key = keyMatch[1];
153 pos += keyMatch[0].length;
154
155 const v = _parseValue(text, pos);
156 if (!v) return null;
157 out[key] = v.value;
158 pos = v.next;
159
160 while (pos < text.length && /\s/.test(text[pos])) pos++;
161 if (pos < text.length && text[pos] === ',') pos++;
162 }
163 return out;
164}
165
166// Parse a single Python literal starting at `text[pos]`. Returns
167// `{ value, next }` or null on failure.

Callers 1

_parseCallListFunction · 0.85

Calls 1

_parseValueFunction · 0.85

Tested by

no test coverage detected