| 2260 | return { type: text, value: text }; |
| 2261 | } |
| 2262 | _string() { |
| 2263 | let i = this._position; |
| 2264 | let prefix = -1; |
| 2265 | if (this._get(i) === "'" || this._get(i) === '"') { |
| 2266 | prefix = ''; |
| 2267 | } else if (this._get(i + 1) === "'" || this._get(i + 1) === '"') { |
| 2268 | const c = this._get(i); |
| 2269 | const cc = c.toLowerCase(); |
| 2270 | if (cc === 'b' || cc === 'f' || cc === 'r' || cc === 'u') { |
| 2271 | prefix = c; |
| 2272 | } |
| 2273 | } else if (this._get(i + 2) === "'" || this._get(i + 2) === '"') { |
| 2274 | const c = this._text.substring(this._position, this._position + 2); |
| 2275 | const cc = c.toLowerCase(); |
| 2276 | if (cc === 'br' || cc === 'fr' || cc === 'rb' || cc === 'rf' || cc === 'ur') { |
| 2277 | prefix = c; |
| 2278 | } |
| 2279 | } |
| 2280 | if (prefix.length >= 0) { |
| 2281 | i += prefix.length; |
| 2282 | let quote = ''; |
| 2283 | let count = 0; |
| 2284 | const q0 = this._get(i); |
| 2285 | const q1 = this._get(i + 1); |
| 2286 | const q2 = this._get(i + 2); |
| 2287 | switch (q0) { |
| 2288 | case "'": |
| 2289 | quote = q0; |
| 2290 | count = (q1 === "'" && q2 === "'") ? 3 : 1; |
| 2291 | break; |
| 2292 | case '"': |
| 2293 | quote = q0; |
| 2294 | count = (q1 === '"' && q2 === '"') ? 3 : 1; |
| 2295 | break; |
| 2296 | default: |
| 2297 | throw new python.Error(`Unsupported string quote '${q0}'.`); |
| 2298 | } |
| 2299 | i += count; |
| 2300 | if (count === 1) { |
| 2301 | while (i < this._text.length) { |
| 2302 | if (this._text[i] === quote) { |
| 2303 | return { type: 'str', value: this._text.substring(this._position, i + 1) }; |
| 2304 | } else if (this._text[i] === '\\' && |
| 2305 | (this._get(i + 1) === quote || this._get(i + 1) === '\n' || this._get(i + 1) === '\\')) { |
| 2306 | i += 2; |
| 2307 | } else if (this._text[i] === '\r' || this._text[i] === '\n') { |
| 2308 | break; |
| 2309 | } else { |
| 2310 | i++; |
| 2311 | } |
| 2312 | } |
| 2313 | } else if (count === 3) { |
| 2314 | while (i < this._text.length) { |
| 2315 | if (this._get(i) === quote && this._get(i + 1) === quote && this._get(i + 2) === quote) { |
| 2316 | return { type: 'str', value: this._text.substring(this._position, i + 3) }; |
| 2317 | } else if (this._get(i) === '\\' && this._get(i + 1) === quote) { |
| 2318 | i += 2; |
| 2319 | continue; |