2015-08-11 17:40:59 +01:00

40 lines
706 B
JavaScript

/**
* Track current position in code generation.
*/
export default class Position {
constructor() {
this.line = 1;
this.column = 0;
}
/**
* Push a string to the current position, mantaining the current line and column.
*/
push(str) {
for (var i = 0; i < str.length; i++) {
if (str[i] === "\n") {
this.line++;
this.column = 0;
} else {
this.column++;
}
}
}
/**
* Unshift a string from the current position, mantaining the current line and column.
*/
unshift(str) {
for (var i = 0; i < str.length; i++) {
if (str[i] === "\n") {
this.line--;
} else {
this.column--;
}
}
}
}