diff --git a/src/index.ts b/src/index.ts index 25dc4a9..620c4c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -65,6 +65,15 @@ export class SourceText { return this.lineStarts.length; } + get eofLocation(): SourceLocation { + return this.getLocation(this.length); + } + + get eofSpan(): Span { + const loc = this.eofLocation; + return span(loc, loc); + } + sliceByCp(start: number, end: number): string { const startRef = this.chars[start]; // Handle out of bounds gracefully @@ -195,6 +204,15 @@ export class SourceRegion { return this.span.end.line - this.span.start.line + 1; } + get eofLocation(): SourceLocation { + return this.span.end; + } + + get eofSpan(): Span { + const loc = this.eofLocation; + return span(loc, loc); + } + toString(): string { return this.source.sliceByCp(this.span.start.index, this.span.end.index); }