66import * as lodash from "lodash"
77import { HasLocation , Location , ParseError } from "../ast"
88
9- const LOC_PATTERN = / \( ( \d + ) : ( \d + ) \) / g
10-
119/**
1210 * Location calculators.
1311 *
@@ -41,13 +39,6 @@ export class LocationCalculator {
4139 : lodash . sortedLastIndex ( gapOffsets , this . baseOffset )
4240 }
4341
44- /**
45- * Get the calculator which does not have base offset.
46- */
47- get raw ( ) : LocationCalculator {
48- return new LocationCalculator ( this . gapOffsets , this . ltOffsets )
49- }
50-
5142 /**
5243 * Get sub calculator which have the given base offset.
5344 * @param offset The base offset of new sub calculator.
@@ -72,19 +63,6 @@ export class LocationCalculator {
7263 return { line, column}
7364 }
7465
75- /**
76- * Calculate the offset of the given location.
77- * @param line The line number (1-based) to get offset.
78- * @param column The column number (0-based) to get offset.
79- * @returns The offset of the location, or `-1`.
80- */
81- private _getOffset ( line : number , column : number ) : number {
82- if ( line < 0 || line >= this . ltOffsets . length ) {
83- return - 1
84- }
85- return this . ltOffsets [ line ] + column
86- }
87-
8866 /**
8967 * Calculate gap at the given index.
9068 * @param index The index to calculate gap.
@@ -112,15 +90,6 @@ export class LocationCalculator {
11290 return this . _getLocation ( this . baseOffset + offset )
11391 }
11492
115- /**
116- * Get the offset of the given index.
117- * @param index The index number from `this.baseOffset`.
118- * @returns The offset of the index
119- */
120- getOffsetWithGap ( index : number ) : number {
121- return this . baseOffset + index + this . _getGap ( index )
122- }
123-
12493 /**
12594 * Modify the location information of the given node with using the base offset and gaps of this calculator.
12695 * @param node The node to modify their location.
@@ -154,17 +123,6 @@ export class LocationCalculator {
154123 * @param error The error to modify their location.
155124 */
156125 fixErrorLocation ( error : ParseError ) {
157- error . message = error . message . replace ( LOC_PATTERN , ( whole , lineText , columnText ) => {
158- const offset = this . _getOffset (
159- parseInt ( lineText , 10 ) ,
160- parseInt ( columnText , 10 )
161- )
162- if ( offset !== - 1 ) {
163- const loc = this . getLocation ( offset )
164- return `(${ loc . line } :${ loc . column } )`
165- }
166- return whole
167- } )
168126 error . index = error . index + this . baseOffset
169127
170128 const loc = this . _getLocation ( error . index )
0 commit comments