Skip to content

Commit

Permalink
Merge pull request #353 from eventualbuddha/fix-error-position-reporting
Browse files Browse the repository at this point in the history
Fix the reported line/column for syntax errors.
  • Loading branch information
michaelficarra committed Sep 23, 2015
2 parents a180874 + 81afe1c commit 4f71af2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions src/grammar.pegcoffee
Expand Up @@ -272,36 +272,37 @@
return peg$reportedPos - csr$controlCharacterCount;
}

function peg$computePosDetails() {
function advanceCachedReportedPos() {
var ch;
function peg$computePosDetails(pos) {
function advance(details, startPos, endPos) {
var p, ch;

for (; peg$cachedPos < peg$reportedPos; peg$cachedPos++) {
ch = input.charAt(peg$cachedPos);
for (p = startPos; p < endPos; p++) {
ch = input.charAt(p);
if (ch === "\n") {
if (!peg$cachedPosDetails.seenCR) { peg$cachedPosDetails.line++; }
peg$cachedPosDetails.column = 1;
peg$cachedPosDetails.seenCR = false;
if (!details.seenCR) { details.line++; }
details.column = 1;
details.seenCR = false;
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
peg$cachedPosDetails.line++;
peg$cachedPosDetails.column = 1;
peg$cachedPosDetails.seenCR = true;
details.line++;
details.column = 1;
details.seenCR = true;
} else if(!/[\uEFEF\uEFFE\uEFFF]/.test(ch)) {
peg$cachedPosDetails.column++;
peg$cachedPosDetails.seenCR = false;
details.column++;
details.seenCR = false;
} else {
csr$controlCharacterCount++;
}
}
}

if (peg$cachedPos !== peg$reportedPos) {
if (peg$cachedPos > peg$reportedPos) {
if (peg$cachedPos !== pos) {
if (peg$cachedPos > pos) {
csr$controlCharacterCount = 0;
peg$cachedPos = 0;
peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
}
advanceCachedReportedPos();
advance(peg$cachedPosDetails, peg$cachedPos, pos);
peg$cachedPos = pos;
}

return peg$cachedPosDetails;
Expand Down

0 comments on commit 4f71af2

Please sign in to comment.