UNPKG

2.3 kBtext/coffeescriptView Raw
1# Copyright 2014, 2015 Simon Lydell
2# X11 (“MIT”) Licensed. (See LICENSE.)
3
4# <http://es5.github.io/#A.1>
5# <http://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-language-lexical-grammar>
6
7# Don’t worry, you don’t need to know CoffeeScript. It is only used for its
8# readable regex syntax. Everything else is done in JavaScript in index.js.
9
10module.exports = ///
11 ( # <string>
12 ([ ' " ])
13 (?:
14 (?! \2 | \\ ).
15 |
16 \\(?: \r\n | [\s\S] )
17 )*
18 (\2)?
19 |
20 `
21 (?:
22 [^ ` \\ $ ]
23 |
24 \\[\s\S]
25 |
26 \$(?!\{)
27 |
28 \$\{
29 (?:
30 [^{}]
31 |
32 \{ [^}]* \}?
33 )*
34 \}?
35 )*
36 (`)?
37 )
38 |
39 ( # <comment>
40 //.*
41 )
42 |
43 ( # <comment>
44 /\*
45 (?:
46 [^*]
47 |
48 \*(?!/)
49 )*
50 ( \*/ )?
51 )
52 |
53 ( # <regex>
54 /(?!\*)
55 (?:
56 \[
57 (?:
58 (?![ \] \\ ]).
59 |
60 \\.
61 )*
62 \]
63 |
64 (?![ / \] \\ ]).
65 |
66 \\.
67 )+
68 /
69 (?:
70 (?!
71 \s*
72 (?:
73 \b
74 |
75 [ \u0080-\uFFFF $ \\ ' " ~ ( { ]
76 |
77 [ + \- ! ](?!=)
78 |
79 \.?\d
80 )
81 )
82 |
83 [ g m i y u ]{1,5} \b
84 (?!
85 [ \u0080-\uFFFF $ \\ ]
86 |
87 \s*
88 (?:
89 [ + \- * % & | ^ < > ! = ? ( { ]
90 |
91 /(?! [ / * ] )
92 )
93 )
94 )
95 )
96 |
97 ( # <number>
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 \\u[ \d a-f A-F ]{4}
121 |
122 \\u\{[ \d a-f A-F ]{1,6}\}
123 )+
124 )
125 |
126 ( # <punctuator>
127 -- | \+\+
128 |
129 && | \|\|
130 |
131 =>
132 |
133 \.{3}
134 |
135 (?:
136 [ + \- * / % & | ^ ]
137 |
138 <{1,2} | >{1,3}
139 |
140 !=? | ={1,2}
141 )=?
142 |
143 [ ? : ~ ]
144 |
145 [ ; , . [ \] ( ) { } ]
146 )
147 |
148 ( # <whitespace>
149 \s+
150 )
151 |
152 ( # <invalid>
153 ^$ # Empty.
154 |
155 [\s\S] # Catch-all rule for anything not matched by the above.
156 )
157///g