UNPKG

2.52 kBtext/coffeescriptView Raw
1# Copyright 2014, 2015 Simon Lydell
2# X11 (“MIT”) Licensed. (See LICENSE.)
3
4# <http://es5.github.io/#A.1>
5
6# Don’t worry, you don’t need to know CoffeeScript. It is only used for its
7# readable regex syntax. Everything else is done in JavaScript in index.js.
8
9module.exports = ///
10 ( # <string>
11 ([ ' " ])
12 (?:
13 (?!\2)[^ \\ \r \n \u2028 \u2029 ]
14 |
15 \\(?: \r\n | [\s\S] )
16 )*
17 (\2)?
18 |
19 `
20 (?:
21 [^ ` \\ $ ]
22 |
23 \\[\s\S]
24 |
25 \$(?!\{)
26 |
27 \$\{
28 (?:
29 [^{}]
30 |
31 \{ [^}]* \}?
32 )*
33 \}?
34 )*
35 (`)?
36 )
37 |
38 ( # <comment>
39 //.*
40 )
41 |
42 ( # <comment>
43 /\*
44 (?:
45 [^*]
46 |
47 \*(?!/)
48 )*
49 ( \*/ )?
50 )
51 |
52 ( # <regex>
53 /(?!\*)
54 (?:
55 \[
56 (?:
57 [^ \] \\ \r \n \u2028 \u2029 ]
58 |
59 \\.
60 )*
61 \]
62 |
63 [^ / \] \\ \r \n \u2028 \u2029 ]
64 |
65 \\.
66 )+
67 /
68 (?:
69 (?!
70 \s*
71 (?:
72 \b
73 |
74 [ \u0080-\uFFFF $ \\ ' " ~ ( { ]
75 |
76 [ + \- ! ](?!=)
77 |
78 \.?\d
79 )
80 )
81 |
82 [ g m i y ]{1,4} \b
83 (?!
84 [ \u0080-\uFFFF $ \\ ]
85 |
86 \s*
87 (?:
88 [ + \- * % & | ^ < > ! = ? ( { ]
89 |
90 /(?! [ / * ] )
91 )
92 )
93 )
94 )
95 |
96 ( # <number>
97 -?
98 (?:
99 0[xX][ \d a-f A-F ]+
100 |
101 0[oO][0-7]+
102 |
103 0[bB][01]+
104 |
105 (?:
106 \d*\.\d+
107 |
108 \d+\.? # Support one trailing dot for integers only.
109 )
110 (?: [eE][+-]?\d+ )?
111 )
112 )
113 |
114 ( # <name>
115 # See <http://mathiasbynens.be/notes/javascript-identifiers>.
116 (?!\d)
117 (?:
118 (?!\s)[ $ \w \u0080-\uFFFF ]
119 |
120 # Unicode escape sequence.
121 \\u[ \d a-f A-F ]{4}
122 |
123 # ES6 unicode escape sequence.
124 \\u\{[ \d a-f A-F ]{1,6}\}
125 )+
126 )
127 |
128 ( # <operator>
129 # Word operators (such as `instanceof`) are matched as <name>s.
130 -- | \+\+
131 |
132 && | \|\|
133 |
134 => # ES6 function arrow.
135 |
136 \.{3} # ES6 splat.
137 |
138 (?:
139 [ + \- * / % & | ^ ]
140 |
141 <{1,2} | >{1,3}
142 |
143 !=? | ={1,2}
144 )=?
145 |
146 [ ? : ~ ]
147 )
148 |
149 ( # <punctuation>
150 # A comma can also be an operator, but is matched as <punctuation> only.
151 [ ; , . [ \] ( ) { } ]
152 )
153 |
154 ( # <whitespace>
155 \s+
156 )
157 |
158 ( # <invalid>
159 ^$ # Empty.
160 |
161 [\s\S] # Catch-all rule for anything not matched by the above.
162 )
163///g