| 194 | let mapped = new Map<number, number>() |
| 195 | // whether the map has a token it wrote where it read another |
| 196 | const isMapped = (b: number, o: number): boolean => { |
| 197 | const { start } = base.tokens[b] |
| 198 | let at = Math.max(line, 0) |
| 199 | while (at + 1 < starts.length && starts[at + 1] <= start) at++ |
| 200 | if (at !== line) { |
| 201 | line = at |
| 202 | mapped = new Map( |
| 203 | (lines[line] ?? []).flatMap((segment): [number, number][] => |
| 204 | segment.length === 1 || segment[2] >= readStarts.length ? |
| 205 | [] |
| 206 | : [[segment[0], readStarts[segment[2]] + segment[3]]] |
| 207 | ) |
| 208 | ) |
| 209 | } |
| 210 | // its own segment, as the map has one where each token it kept starts |
| 211 | const from = mapped.get(start - starts[line]) |
| 212 | return from !== undefined && byStart.get(from) === o |
| 213 | } |
| 214 | let [b, o] = [0, 0] |
| 215 | const keep = () => { |
| 216 | if (isMapped(b, o)) readAt[b] = o |