utils.js 455 B

1234567891011121314151617181920
  1. module.exports = {
  2. getLocation: function(index, inputStream) {
  3. var n = index + 1,
  4. line = null,
  5. column = -1;
  6. while (--n >= 0 && inputStream.charAt(n) !== '\n') {
  7. column++;
  8. }
  9. if (typeof index === 'number') {
  10. line = (inputStream.slice(0, index).match(/\n/g) || "").length;
  11. }
  12. return {
  13. line: line,
  14. column: column
  15. };
  16. }
  17. };