eof helpers

This commit is contained in:
Yura Dupyn 2026-04-06 18:06:45 +02:00
parent 8f1c35b982
commit 7757394fab

View file

@ -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);
}