|
@@ -22,13 +22,13 @@ Allows for using regular expressions as a mask
|
|
|
definitions: {
|
|
definitions: {
|
|
|
'r': {
|
|
'r': {
|
|
|
validator: function (chrs, buffer, pos, strict, opts) {
|
|
validator: function (chrs, buffer, pos, strict, opts) {
|
|
|
-
|
|
|
|
|
|
|
+ function regexToken() {
|
|
|
|
|
+ this.matches = [];
|
|
|
|
|
+ this.isGroup = false;
|
|
|
|
|
+ this.isQuantifier = false;
|
|
|
|
|
+ }
|
|
|
function analyseRegex() {
|
|
function analyseRegex() {
|
|
|
- var currentToken = {
|
|
|
|
|
- "isQuantifier": false,
|
|
|
|
|
- "matches": [],
|
|
|
|
|
- "isGroup": false
|
|
|
|
|
- }, match, m, opengroups = [];
|
|
|
|
|
|
|
+ var currentToken = new regexToken(), match, m, opengroups = [];
|
|
|
|
|
|
|
|
opts.regexTokens = [];
|
|
opts.regexTokens = [];
|
|
|
|
|
|
|
@@ -39,25 +39,18 @@ Allows for using regular expressions as a mask
|
|
|
case "[": // Character class
|
|
case "[": // Character class
|
|
|
case "\\": // Escape or backreference
|
|
case "\\": // Escape or backreference
|
|
|
if (currentToken["isGroup"] !== true) {
|
|
if (currentToken["isGroup"] !== true) {
|
|
|
- currentToken = {
|
|
|
|
|
- "isQuantifier": false,
|
|
|
|
|
- "matches": [],
|
|
|
|
|
- "isGroup": false
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ currentToken = new regexToken();
|
|
|
opts.regexTokens.push(currentToken);
|
|
opts.regexTokens.push(currentToken);
|
|
|
}
|
|
}
|
|
|
if (opengroups.length > 0) {
|
|
if (opengroups.length > 0) {
|
|
|
opengroups[opengroups.length - 1]["matches"].push(m);
|
|
opengroups[opengroups.length - 1]["matches"].push(m);
|
|
|
} else {
|
|
} else {
|
|
|
- currentToken["matches"].push(m);
|
|
|
|
|
|
|
+ currentToken.matches.push(m);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case "(": // Group opening
|
|
case "(": // Group opening
|
|
|
- currentToken = {
|
|
|
|
|
- "isQuantifier": false,
|
|
|
|
|
- "matches": [],
|
|
|
|
|
- "isGroup": true
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ currentToken = new regexToken();
|
|
|
|
|
+ currentToken.isGroup = true;
|
|
|
opengroups.push(currentToken);
|
|
opengroups.push(currentToken);
|
|
|
break;
|
|
break;
|
|
|
case ")": // Group closing
|
|
case ")": // Group closing
|
|
@@ -70,15 +63,13 @@ Allows for using regular expressions as a mask
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case "{": //Quantifier
|
|
case "{": //Quantifier
|
|
|
- var quantifier = {
|
|
|
|
|
- "isQuantifier": true,
|
|
|
|
|
- "matches": [m],
|
|
|
|
|
- "isGroup": false
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ var quantifier = new regexToken();
|
|
|
|
|
+ quantifier.isQuantifier = true;
|
|
|
|
|
+ quantifier.matches.push(m);
|
|
|
if (opengroups.length > 0) {
|
|
if (opengroups.length > 0) {
|
|
|
opengroups[opengroups.length - 1]["matches"].push(quantifier);
|
|
opengroups[opengroups.length - 1]["matches"].push(quantifier);
|
|
|
} else {
|
|
} else {
|
|
|
- currentToken["matches"].push(quantifier);
|
|
|
|
|
|
|
+ currentToken.matches.push(quantifier);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
@@ -89,7 +80,7 @@ Allows for using regular expressions as a mask
|
|
|
if (opengroups.length > 0) {
|
|
if (opengroups.length > 0) {
|
|
|
opengroups[opengroups.length - 1]["matches"].push(m);
|
|
opengroups[opengroups.length - 1]["matches"].push(m);
|
|
|
} else {
|
|
} else {
|
|
|
- currentToken["matches"].push(m);
|
|
|
|
|
|
|
+ currentToken.matches.push(m);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|