28 lines
452 B
JavaScript
28 lines
452 B
JavaScript
export default class Position {
|
|
constructor() {
|
|
this.line = 1;
|
|
this.column = 0;
|
|
}
|
|
|
|
push(str) {
|
|
for (var i = 0; i < str.length; i++) {
|
|
if (str[i] === "\n") {
|
|
this.line++;
|
|
this.column = 0;
|
|
} else {
|
|
this.column++;
|
|
}
|
|
}
|
|
}
|
|
|
|
unshift(str) {
|
|
for (var i = 0; i < str.length; i++) {
|
|
if (str[i] === "\n") {
|
|
this.line--;
|
|
} else {
|
|
this.column--;
|
|
}
|
|
}
|
|
}
|
|
}
|