From a2788f8864b9a7453be80bac49e550e7be6914d0 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 16 Jan 2013 17:38:56 +0100 Subject: [PATCH] [loose parser] Make expect check two tokens ahead if it fails to find its target --- acorn_loose.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/acorn_loose.js b/acorn_loose.js index a95efae515..81f5f2fa48 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -97,7 +97,7 @@ var tok = readToken(); ahead.push({start: tok.from, end: tok.end, type: tok.type, value: tok.value}); } - return ahead[n]; + return ahead[n-1]; } var newline = /[\n\r\u2028\u2029]/; @@ -125,7 +125,6 @@ } return count; } - // FIXME maybe use smarter heuristics (look at next lines, etc) function closesBlock(closeTok, indent) { return token.type === closeTok || token.type === tt.eof || indent > indentationAt(token.start); } @@ -172,9 +171,14 @@ function expect(type) { if (eat(type)) return true; - // FIXME - // - it might just be missing, in which case ignoring is good - // + custom strategies for re-syncing in other cases + if (lookAhead(1).type == type) { + next(); next(); + return true; + } + if (lookAhead(2).type == type) { + next(); next(); next(); + return true; + } } function checkLVal(expr) {