* Return the next substring matching regEx and advance.
(regEx: RegExp)
| 166 | /** |
| 167 | * Return the next char and advance |
| 168 | */ |
| 169 | get(): string { |
| 170 | return this.pos < this.s.length ? this.s[this.pos++] : ''; |
| 171 | } |
| 172 | /** |
| 173 | * Return the next char, but do not advance |
| 174 | */ |
| 175 | peek(): string { |
| 176 | return this.s[this.pos]; |
| 177 | } |
| 178 | /** |
| 179 | * Return the next substring matching regEx and advance. |
| 180 | */ |
| 181 | match(regEx: RegExp): string | null { |
| 182 | // this.s can either be a string, if it's made up only of ASCII chars |
| 183 | // or an array of graphemes, if it's more complicated. |
| 184 | // |
| 185 | // Use a sticky variant of the regex positioned at the current offset, |
| 186 | // rather than slicing the remaining input (O(n) per token, O(n²) total). |
| 187 | const re = stickyRegex(regEx); |
| 188 | if (typeof this.s === 'string') { |
| 189 | re.lastIndex = this.pos; |
| 190 | } else { |