| 155 | } |
| 156 | |
| 157 | read(): string | null { |
| 158 | const budget = 4 * this.n + 65536; |
| 159 | let steps = 0; |
| 160 | for (;;) { |
| 161 | while (this.i < this.n) { |
| 162 | if (++steps > budget) return null; |
| 163 | const top = this.stack[this.stack.length - 1]!; |
| 164 | const c = this.src.charCodeAt(this.i); |
| 165 | const ok = |
| 166 | top.mode === 'code' ? this.code(top, c) |
| 167 | : top.mode === 'template' ? this.template(c) |
| 168 | : top.mode === 'tag' ? this.tag(top, c) |
| 169 | : this.children(top, c); |
| 170 | if (!ok) return null; |
| 171 | } |
| 172 | if (this.stack.length === 1 && this.stack[0]!.braces === 0) break; |
| 173 | if (!this.reread()) return null; |
| 174 | } |
| 175 | return blankRanges(this.src, this.blanks); |
| 176 | } |
| 177 | |
| 178 | private blank(from: number, to: number): void { |
| 179 | if (to > from) this.blanks.push(from, Math.min(to, this.n)); |