|
2 | 2 | # Use of this source code is governed by a BSD-style license that can be |
3 | 3 | # found in the LICENSE file. |
4 | 4 |
|
5 | | -from compiler.ast import Const |
6 | | -from compiler.ast import Dict |
7 | | -from compiler.ast import Discard |
8 | | -from compiler.ast import List |
9 | | -from compiler.ast import Module |
10 | | -from compiler.ast import Node |
11 | | -from compiler.ast import Stmt |
12 | | -import compiler |
| 5 | +import ast |
| 6 | + |
13 | 7 | import gyp.common |
14 | 8 | import gyp.simple_copy |
15 | 9 | import multiprocessing |
@@ -183,43 +177,38 @@ def CheckedEval(file_contents): |
183 | 177 | Note that this is slower than eval() is. |
184 | 178 | """ |
185 | 179 |
|
186 | | - ast = compiler.parse(file_contents) |
187 | | - assert isinstance(ast, Module) |
188 | | - c1 = ast.getChildren() |
189 | | - assert c1[0] is None |
190 | | - assert isinstance(c1[1], Stmt) |
191 | | - c2 = c1[1].getChildren() |
192 | | - assert isinstance(c2[0], Discard) |
193 | | - c3 = c2[0].getChildren() |
194 | | - assert len(c3) == 1 |
195 | | - return CheckNode(c3[0], []) |
| 180 | + syntax_tree = ast.parse(file_contents) |
| 181 | + assert isinstance(syntax_tree, ast.Module) |
| 182 | + c1 = syntax_tree.body |
| 183 | + assert len(c1) == 1 |
| 184 | + c2 = c1[0] |
| 185 | + assert isinstance(c2, ast.Expr) |
| 186 | + return CheckNode(c2.value, []) |
196 | 187 |
|
197 | 188 |
|
198 | 189 | def CheckNode(node, keypath): |
199 | | - if isinstance(node, Dict): |
200 | | - c = node.getChildren() |
| 190 | + if isinstance(node, ast.Dict): |
201 | 191 | dict = {} |
202 | | - for n in range(0, len(c), 2): |
203 | | - assert isinstance(c[n], Const) |
204 | | - key = c[n].getChildren()[0] |
| 192 | + for key, value in zip(node.keys, node.values): |
| 193 | + assert isinstance(key, ast.Str) |
| 194 | + key = key.s |
205 | 195 | if key in dict: |
206 | 196 | raise GypError("Key '" + key + "' repeated at level " + |
207 | 197 | repr(len(keypath) + 1) + " with key path '" + |
208 | 198 | '.'.join(keypath) + "'") |
209 | 199 | kp = list(keypath) # Make a copy of the list for descending this node. |
210 | 200 | kp.append(key) |
211 | | - dict[key] = CheckNode(c[n + 1], kp) |
| 201 | + dict[key] = CheckNode(value, kp) |
212 | 202 | return dict |
213 | | - elif isinstance(node, List): |
214 | | - c = node.getChildren() |
| 203 | + elif isinstance(node, ast.List): |
215 | 204 | children = [] |
216 | | - for index, child in enumerate(c): |
| 205 | + for index, child in enumerate(node.elts): |
217 | 206 | kp = list(keypath) # Copy list. |
218 | 207 | kp.append(repr(index)) |
219 | 208 | children.append(CheckNode(child, kp)) |
220 | 209 | return children |
221 | | - elif isinstance(node, Const): |
222 | | - return node.getChildren()[0] |
| 210 | + elif isinstance(node, ast.Str): |
| 211 | + return node.s |
223 | 212 | else: |
224 | 213 | raise TypeError("Unknown AST node at key path '" + '.'.join(keypath) + |
225 | 214 | "': " + repr(node)) |
|