MCPcopy Index your code
hub / github.com/CashScript/cashscript / Location

Class Location

packages/cashc/src/ast/Location.ts:4–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import { LocationI } from '@cashscript/utils';
3
4export 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
38export class Point {
39 constructor(public line: number, public column: number) {}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected