Brackets still open after `text`, outside strings.
(text: string)
| 34 | |
| 35 | /** Brackets still open after `text`, outside strings. */ |
| 36 | function openBrackets(text: string): number { |
| 37 | let depth = 0, quote: string | undefined; |
| 38 | for (let index = 0; index < text.length; index++) { |
| 39 | const character = text[index]; |
| 40 | if (quote) { if (character === '\\') index++; else if (character === quote) quote = undefined; continue; } |
| 41 | if (character === '#') break; |
| 42 | if (character === '"' || character === "'") quote = character; |
| 43 | else if ('([{'.includes(character)) depth++; |
| 44 | else if (')]}'.includes(character)) depth--; |
| 45 | } |
| 46 | return depth; |
| 47 | } |
| 48 | |
| 49 | /** The statement starting at `start`, joined over the lines its brackets keep open. */ |
| 50 | function statement(lines: readonly string[], start: number): { text: string; end: number } { |