eof helpers
This commit is contained in:
parent
8f1c35b982
commit
7757394fab
1 changed files with 18 additions and 0 deletions
18
src/index.ts
18
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue