1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | module.exports = /((['"])(?:(?!\2)[^\\\r\n\u2028\u2029]|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:[^\]\\\r\n\u2028\u2029]|\\.)*\]|[^\/\]\\\r\n\u2028\u2029]|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiy]{1,4}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(-?(?:0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?))|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]{1,6}\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-*\/%&|^]|<{1,2}|>{1,3}|!=?|={1,2})=?|[?:~])|([;,.[\](){}])|(\s+)|(^$|[\s\S])/g
|
7 |
|
8 | module.exports.matchToToken = function(match) {
|
9 | token = {type: "invalid", value: match[0]}
|
10 | if (match[ 1]) token.type = "string" , token.closed = !!(match[3] || match[4])
|
11 | else if (match[ 5]) token.type = "comment"
|
12 | else if (match[ 6]) token.type = "comment", token.closed = !!match[7]
|
13 | else if (match[ 8]) token.type = "regex"
|
14 | else if (match[ 9]) token.type = "number"
|
15 | else if (match[10]) token.type = "name"
|
16 | else if (match[11]) token.type = "operator"
|
17 | else if (match[12]) token.type = "punctuation"
|
18 | else if (match[13]) token.type = "whitespace"
|
19 | return token
|
20 | }
|