// match-failed handler written by Eric Kedji // The arrow pointing to the error position // in the error message works better when // using a fixed-width font, like in a shell. matchFailed = function (grammar, errorPos) { var lines = grammar.input.lst.split('\n'); var pos = 0, l = 0; var msg = ["Execution error: input matching failed at position: " + errorPos]; while (pos < errorPos) { var line = lines[l], length = line.length; if (pos + length >= errorPos) { var c = errorPos - pos; msg.push(" line:" + (l + 1) + ", column:" + c); msg.push(line) // replicate str n times function replicate(str, n) { if (n < 1) return ""; var t = []; for (var i=0; i