Skip to content

Commit

Permalink
Fix the reported line/column for syntax errors.
Browse files Browse the repository at this point in the history
As reported at decaffeinate/decaffeinate#54, CoffeeScriptRedux syntax
errors always point to line 1 column 1. This is very annoying when
trying to figure out what part of the file it actually can’t parse.
This updates the peg override to match the new signature for
`peg$computePosDetails` which now takes a `pos` argument.
  • Loading branch information
eventualbuddha committed Sep 23, 2015
1 parent e1368e9 commit 81afe1c
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
Original file line number Diff line number Diff line change
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 81afe1c

Please sign in to comment.