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