(text)
| 141 | // Parse `key=value, key=value, ...` (Python kwargs). Returns plain object, |
| 142 | // or null on parse failure. |
| 143 | function _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. |
no test coverage detected