* Retrieve a `ParseSpan` from `start` to the current position (or to `artificialEndIndex` if * provided). * * @param start Position from which the `ParseSpan` will start. * @param artificialEndIndex Optional ending index to be used if provided (and if greater than the * natural en
(start: number, artificialEndIndex?: number)
| 652 | * natural ending index) |
| 653 | */ |
| 654 | private span(start: number, artificialEndIndex?: number): ParseSpan { |
| 655 | let endIndex = this.currentEndIndex; |
| 656 | if (artificialEndIndex !== undefined && artificialEndIndex > this.currentEndIndex) { |
| 657 | endIndex = artificialEndIndex; |
| 658 | } |
| 659 | |
| 660 | // In some unusual parsing scenarios (like when certain tokens are missing and an `EmptyExpr` is |
| 661 | // being created), the current token may already be advanced beyond the `currentEndIndex`. This |
| 662 | // appears to be a deep-seated parser bug. |
| 663 | // |
| 664 | // As a workaround for now, swap the start and end indices to ensure a valid `ParseSpan`. |
| 665 | // TODO(alxhub): fix the bug upstream in the parser state, and remove this workaround. |
| 666 | if (start > endIndex) { |
| 667 | const tmp = endIndex; |
| 668 | endIndex = start; |
| 669 | start = tmp; |
| 670 | } |
| 671 | |
| 672 | return new ParseSpan(start, endIndex); |
| 673 | } |
| 674 | |
| 675 | private sourceSpan(start: number, artificialEndIndex?: number): AbsoluteSourceSpan { |
| 676 | const serial = `${start}@${this.inputIndex}:${artificialEndIndex}`; |
no outgoing calls
no test coverage detected