xchess
Version:
Chess Engine
52 lines (43 loc) • 866 B
JavaScript
export {PGNSyntaxError}
function FindLineAndColumn(source, offset){
let line = 1;
let column = 1;
for(let pos = 0; pos < offset; pos ++){
const char = source[pos];
if(char === '\n'){
line ++;
column = 1;
} else if(char === '\r'){
if(source[pos + 1] == '\n')
pos ++;
line ++;
column = 1;
} else column ++;
} return {line, column};
}
class PGNSyntaxError extends Error {
constructor(message, {source, offset}){
const {line, column} = FindLineAndColumn(source, offset);
super(`${message} (line: ${line}, column: ${column})`);
this.
this.
this.
this.
}
get source(){
return this.
}
get offset(){
return this.
}
get line(){
return this.
}
get column(){
return this.
}
}