| 2 | import { LocationI } from '@cashscript/utils'; |
| 3 | |
| 4 | export class Location implements LocationI { |
| 5 | constructor(public start: Point, public end: Point) {} |
| 6 | |
| 7 | static fromCtx(ctx: ParserRuleContext): Location { |
| 8 | const stop = ctx.stop?.text ? ctx.stop : ctx.start; |
| 9 | const textLength = (stop.text ?? '').length; |
| 10 | |
| 11 | const start = new Point(ctx.start.line, ctx.start.column); |
| 12 | const end = new Point(stop.line, stop.column + textLength); |
| 13 | |
| 14 | return new Location(start, end); |
| 15 | } |
| 16 | |
| 17 | static fromToken(token: Token): Location { |
| 18 | const textLength = (token.text ?? '').length; |
| 19 | |
| 20 | const start = new Point(token.line, token.column); |
| 21 | const end = new Point(token.line, token.column + textLength); |
| 22 | |
| 23 | return new Location(start, end); |
| 24 | } |
| 25 | |
| 26 | static fromObject(object: LocationI): Location { |
| 27 | const start = new Point(object.start.line, object.start.column); |
| 28 | const end = new Point(object.end.line, object.end.column); |
| 29 | |
| 30 | return new Location(start, end); |
| 31 | } |
| 32 | |
| 33 | text(code: string): string { |
| 34 | return code.slice(this.start.offset(code), this.end.offset(code)); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export class Point { |
| 39 | constructor(public line: number, public column: number) {} |
nothing calls this directly
no outgoing calls
no test coverage detected