From 6b660009adc122a780550f933d8fa966c330bfaf Mon Sep 17 00:00:00 2001 From: c-spencer Date: Thu, 19 May 2011 13:07:42 +0100 Subject: [PATCH] Simplify backreference adjustment --- lib/ace/tokenizer.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/ace/tokenizer.js b/lib/ace/tokenizer.js index cfee8199..6d03388a 100644 --- a/lib/ace/tokenizer.js +++ b/lib/ace/tokenizer.js @@ -53,12 +53,9 @@ var Tokenizer = function(rules) { // Count number of matching groups. 2 extra groups from the full match // And the catch-all on the end (used to force a match); var matchcount = new RegExp("(?:(" + state[i].regex + ")|(.))").exec("a").length - 2; - - // Get how long references can be, depending on how many capturing groups have been found so far. - var reflength = ("" + (matchTotal + matchcount.length - 2)).length; - + // Replace any backreferences and offset appropriately. - var adjustedregex = state[i].regex.replace(new RegExp("\\\\([0-9]{1," + reflength + "})", "g"), function (match, digit) { + var adjustedregex = state[i].regex.replace(/\\([0-9]+)/g, function (match, digit) { return "\\" + (parseInt(digit, 10) + matchTotal + 1); });