|
1 # |
|
2 # Jasy - Web Tooling Framework |
|
3 # Copyright 2010-2012 Zynga Inc. |
|
4 # Copyright 2013-2014 Sebastian Werner |
|
5 # |
|
6 |
|
7 from __future__ import unicode_literals |
|
8 |
|
9 futureReserved = set([ |
|
10 "abstract", |
|
11 "boolean", |
|
12 "byte", |
|
13 "char", |
|
14 "class", |
|
15 "const", |
|
16 "debugger", |
|
17 "double", |
|
18 "enum", |
|
19 "export", |
|
20 "extends", |
|
21 "final", |
|
22 "float", |
|
23 "goto", |
|
24 "implements", |
|
25 "import", |
|
26 "int", |
|
27 "interface", |
|
28 "long", |
|
29 "native", |
|
30 "package", |
|
31 "private", |
|
32 "protected", |
|
33 "public", |
|
34 "short", |
|
35 "static", |
|
36 "super", |
|
37 "synchronized", |
|
38 "throws", |
|
39 "transient", |
|
40 "volatile" |
|
41 ]) |
|
42 |
|
43 |
|
44 statements = [ |
|
45 # With semicolon at end |
|
46 "semicolon", |
|
47 "return", |
|
48 "throw", |
|
49 "label", |
|
50 "break", |
|
51 "continue", |
|
52 "var", |
|
53 "const", |
|
54 "debugger", |
|
55 |
|
56 # Only semicolon when no-block braces are created |
|
57 "block", |
|
58 "let_block", |
|
59 "while", |
|
60 "do", |
|
61 "for", |
|
62 "for_in", |
|
63 "if", |
|
64 "switch", |
|
65 "hook", |
|
66 "with", |
|
67 |
|
68 # no semicolons |
|
69 # function, setter and getter as statement_form or declared_form |
|
70 "function", |
|
71 "setter", |
|
72 "getter", |
|
73 "try", |
|
74 "label" |
|
75 ] |
|
76 |
|
77 |
|
78 # All allowed expression types of JavaScript 1.7 |
|
79 # They may be separated by "comma" which is quite of special |
|
80 # and not allowed everywhere e.g. in conditional statements |
|
81 expressions = [ |
|
82 # Primary Expression - Part 1 (expressed form) |
|
83 "function", |
|
84 |
|
85 # Primary Expression - Part 2 |
|
86 "object_init", |
|
87 "array_init", |
|
88 "array_comp", |
|
89 |
|
90 # Primary Expression - Part 3 |
|
91 "let", |
|
92 |
|
93 # Primary Expression - Part 4 |
|
94 "null", |
|
95 "this", |
|
96 "true", |
|
97 "false", |
|
98 "identifier", |
|
99 "number", |
|
100 "string", |
|
101 "regexp", |
|
102 |
|
103 # Member Expression - Part 1 |
|
104 "new_with_args", |
|
105 "new", |
|
106 |
|
107 # Member Expression - Part 2 |
|
108 "dot", |
|
109 "call", |
|
110 "index", |
|
111 |
|
112 # Unary Expression |
|
113 "unary_plus", |
|
114 "unary_minus", |
|
115 "delete", |
|
116 "void", |
|
117 "typeof", |
|
118 "not", |
|
119 "bitwise_not", |
|
120 "increment", |
|
121 "decrement", |
|
122 |
|
123 # Multiply Expression |
|
124 "mul", |
|
125 "div", |
|
126 "mod", |
|
127 |
|
128 # Add Expression |
|
129 "plus", |
|
130 "minus", |
|
131 |
|
132 # Shift Expression |
|
133 "lsh", |
|
134 "rsh", |
|
135 "ursh", |
|
136 |
|
137 # Relational Expression |
|
138 "lt", |
|
139 "le", |
|
140 "ge", |
|
141 "gt", |
|
142 "in", |
|
143 "instanceof", |
|
144 |
|
145 # Equality Expression |
|
146 "eq", |
|
147 "ne", |
|
148 "strict_eq", |
|
149 "strict_ne", |
|
150 |
|
151 # BitwiseAnd Expression |
|
152 "bitwise_and", |
|
153 |
|
154 # BitwiseXor Expression |
|
155 "bitwise_xor", |
|
156 |
|
157 # BitwiseOr Expression |
|
158 "bitwise_or", |
|
159 |
|
160 # And Expression |
|
161 "and", |
|
162 |
|
163 # Or Expression |
|
164 "or", |
|
165 |
|
166 # Conditional Expression |
|
167 "hook", |
|
168 |
|
169 # Assign Expression |
|
170 "assign", |
|
171 |
|
172 # Expression |
|
173 "comma" |
|
174 ] |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 def __createOrder(): |
|
180 expressions = [ |
|
181 ["comma"], |
|
182 ["assign"], |
|
183 ["hook"], |
|
184 ["or"], |
|
185 ["and"], |
|
186 ["bitwise_or"], |
|
187 ["bitwise_xor",], |
|
188 ["bitwise_and"], |
|
189 ["eq","ne","strict_eq","strict_ne"], |
|
190 ["lt","le","ge","gt","in","instanceof"], |
|
191 ["lsh","rsh","ursh"], |
|
192 ["plus","minus"], |
|
193 ["mul","div","mod"], |
|
194 ["unary_plus","unary_minus","delete","void","typeof","not","bitwise_not","increment","decrement"], |
|
195 ["dot","call","index"], |
|
196 ["new_with_args","new"], |
|
197 ["null","this","true","false","identifier","number","string","regexp"], |
|
198 ["let"], |
|
199 ["object_init","array_init","array_comp"], |
|
200 ["function"] |
|
201 ] |
|
202 |
|
203 result = {} |
|
204 for priority, itemList in enumerate(expressions): |
|
205 for item in itemList: |
|
206 result[item] = priority |
|
207 |
|
208 return result |
|
209 |
|
210 expressionOrder = __createOrder() |
|
211 |