'use strict';

function getMainLine(src) {
  var lines = src.split('\n');
  for (var i = 0; i < lines.length; i++) {
    console.log('line', lines[i]);
    if (lines[i].indexOf('main()') != -1) return i;
  }
  return -1;
}

module.exports = function mapGLErrorToISFLine(error, glsl, isf) {
  var glslMainLine = getMainLine(glsl);
  var isfMainLine = getMainLine(isf);
  var regex = /ERROR: (\d+):(\d+): (.*)/g;
  var matches = regex.exec(error.message);
  var glslErrorLine = matches[2];
  var isfErrorLine = parseInt(glslErrorLine, 10) + isfMainLine - glslMainLine;
  return isfErrorLine;
};