Skip to content

Commit

Permalink
Improvements to regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Nov 20, 2015
1 parent 04cd184 commit a3d17d5
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/lib/annotations/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -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");
})(),
Expand Down

0 comments on commit a3d17d5

Please sign in to comment.