@@ -1,10 +1,8 @@
|
||||
import {Math} from 'angular2/src/facade/math';
|
||||
|
||||
export class ParseLocation {
|
||||
constructor(public file: ParseSourceFile, public offset: number, public line: number,
|
||||
public col: number) {}
|
||||
|
||||
toString() { return `${this.file.url}@${this.line}:${this.col}`; }
|
||||
toString(): string { return `${this.file.url}@${this.line}:${this.col}`; }
|
||||
}
|
||||
|
||||
export class ParseSourceFile {
|
||||
@@ -16,9 +14,33 @@ export abstract class ParseError {
|
||||
|
||||
toString(): string {
|
||||
var source = this.location.file.content;
|
||||
var ctxStart = Math.max(this.location.offset - 10, 0);
|
||||
var ctxEnd = Math.min(this.location.offset + 10, source.length);
|
||||
return `${this.msg} (${source.substring(ctxStart, ctxEnd)}): ${this.location}`;
|
||||
var ctxStart = this.location.offset;
|
||||
var ctxEnd = this.location.offset;
|
||||
var ctxLen = 0;
|
||||
var ctxLines = 0;
|
||||
|
||||
while (ctxLen < 100 && ctxStart > 0) {
|
||||
ctxStart--;
|
||||
ctxLen++;
|
||||
if (source[ctxStart] == "\n") {
|
||||
if (++ctxLines == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctxLen = 0;
|
||||
ctxLines = 0;
|
||||
while (ctxLen < 100 && ctxEnd < source.length - 1) {
|
||||
ctxEnd++;
|
||||
ctxLen++;
|
||||
if (source[ctxEnd] == "\n") {
|
||||
if (++ctxLines == 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return `${this.msg} ("${source.substring(ctxStart, ctxEnd + 1)}"): ${this.location}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user