(text, pos)
| 166 | // Parse a single Python literal starting at `text[pos]`. Returns |
| 167 | // `{ value, next }` or null on failure. |
| 168 | function _parseValue(text, pos) { |
| 169 | while (pos < text.length && /\s/.test(text[pos])) pos++; |
| 170 | if (pos >= text.length) return null; |
| 171 | const c = text[pos]; |
| 172 | |
| 173 | if (c === "'" || c === '"') return _parseString(text, pos); |
| 174 | if (c === '[') return _parseList(text, pos); |
| 175 | if (c === '{') return _parseDict(text, pos); |
| 176 | |
| 177 | // Identifier-like: True/False/None or a bare keyword we don't accept. |
| 178 | const idMatch = text.slice(pos).match(/^(True|False|None)\b/); |
| 179 | if (idMatch) { |
| 180 | const map = { True: true, False: false, None: null }; |
| 181 | return { value: map[idMatch[1]], next: pos + idMatch[0].length }; |
| 182 | } |
| 183 | |
| 184 | // Number — including scientific notation and signs. |
| 185 | const numMatch = text.slice(pos).match(/^[+-]?(\d+\.\d*|\.\d+|\d+)([eE][+-]?\d+)?/); |
| 186 | if (numMatch) { |
| 187 | return { value: parseFloat(numMatch[0]), next: pos + numMatch[0].length }; |
| 188 | } |
| 189 | |
| 190 | return null; |
| 191 | } |
| 192 | |
| 193 | function _parseString(text, pos) { |
| 194 | const quote = text[pos]; |
no test coverage detected