From a3d17d5e755b4993c342979b018bd93c5cf9d2bb Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Fri, 20 Nov 2015 10:58:37 -0800 Subject: [PATCH] Improvements to regex. --- src/lib/annotations/annotations.html | 33 ++++++++++------------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/lib/annotations/annotations.html b/src/lib/annotations/annotations.html index 0f2f678d65..f661e1cccb 100644 --- a/src/lib/annotations/annotations.html +++ b/src/lib/annotations/annotations.html @@ -90,29 +90,20 @@ }, _bindingRegex: (function() { - var IDENT = '([\\w\\s-_.:$]+)'; - // The following lookahead group (?= ... ) and backreference \\4, etc. - // for repeating identifier characters prevent catastrophic - // backtracking when the argument which contains the identifier itself - // is repeated. This approximates possessive/atomic groups which are - // otherwise unsupported in Javascript. Unfortunately this means each - // usage of identifier must be separated to index the backreference - // correctly. - // v..............v v - var PROPERTY = '(?:(?=' + IDENT + ')\\4)'; - var METHOD = '(?:(?=' + IDENT + ')\\5)'; - var ARG_IDENT = '(?:(?=' + IDENT + ')\\6)'; - var NUMBER = '(?:' + '[0-9]+' + ')'; - var SQUOTE_STRING = '(?:' + '\'(?:[^\'\\\\]|\\\\\'|\\\\,)*\'' + ')'; - var DQUOTE_STRING = '(?:' + '"(?:[^"\\\\]|\\\\"|\\\\,)*"' + ')'; + var IDENT = '(?:' + '[a-zA-Z_$][a-zA-Z0-9_.:$-]*' + '\\s*' + ')'; + var NUMBER = '(?:' + '[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?' + '\\s*' + ')'; + var SQUOTE_STRING = '(?:' + '\'(?:[^\'\\\\]|\\\\.)*\'' + '\\s*' + ')'; + var DQUOTE_STRING = '(?:' + '"(?:[^"\\\\]|\\\\.)*"' + '\\s*' + ')'; var STRING = '(?:' + SQUOTE_STRING + '|' + DQUOTE_STRING + ')'; - var ARGUMENT = '(?:' + ARG_IDENT + '|' + NUMBER + '|' + STRING + ')'; - var ARGUMENT_LIST = '(?:(?:' + ARGUMENT + ',?' + ')*)'; - var COMPUTED_FUNCTION = '(?:' + METHOD + '\\(' + ARGUMENT_LIST + '\\)' + ')'; - var BINDING = '(' + PROPERTY + '|' + COMPUTED_FUNCTION + ')'; // Group 3 - var OPEN_BRACKET = '(\\[\\[|{{)'; // Group 1 + var ARGUMENT = '(?:' + IDENT + '|' + NUMBER + '|' + STRING + ')'; + var ARGUMENTS = '(?:' + ARGUMENT + '(?:,\\s*' + ARGUMENT + ')*' + ')'; + var ARGUMENT_LIST = '(?:' + '\\(\\s*' + + '(?:' + ARGUMENTS + '?' + ')' + + '\\)\\s*' + ')'; + var BINDING = '(' + IDENT + ARGUMENT_LIST + '?' + ')'; // Group 3 + var OPEN_BRACKET = '(\\[\\[|{{)' + '\\s*'; var CLOSE_BRACKET = '(?:]]|}})'; - var NEGATE = '(!?)'; // Group 2 + var NEGATE = '(?:(!)\\s*)?'; // Group 2 var EXPRESSION = OPEN_BRACKET + NEGATE + BINDING + CLOSE_BRACKET; return new RegExp(EXPRESSION, "g"); })(),