OLD | NEW |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import json | 6 import json |
7 import os.path | 7 import os.path |
8 import re | |
9 import schema_util | |
asargent_no_longer_on_chrome
2012/05/09 18:37:23
nit: I've been trying to move all the code in this
bryeung
2012/05/09 19:12:00
Done.
| |
8 import sys | 10 import sys |
9 import re | |
10 | 11 |
11 # This file is a peer to json_schema.py. Each of these files understands a | 12 # This file is a peer to json_schema.py. Each of these files understands a |
12 # certain format describing APIs (either JSON or IDL), reads files written | 13 # certain format describing APIs (either JSON or IDL), reads files written |
13 # in that format into memory, and emits them as a Python array of objects | 14 # in that format into memory, and emits them as a Python array of objects |
14 # corresponding to those APIs, where the objects are formatted in a way that | 15 # corresponding to those APIs, where the objects are formatted in a way that |
15 # the JSON schema compiler understands. compiler.py drives both idl_schema.py | 16 # the JSON schema compiler understands. compiler.py drives both idl_schema.py |
16 # and json_schema.py. | 17 # and json_schema.py. |
17 | 18 |
18 # idl_parser expects to be able to import certain files in its directory, | 19 # idl_parser expects to be able to import certain files in its directory, |
19 # so let's set things up the way it wants. | 20 # so let's set things up the way it wants. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 continue | 248 continue |
248 elif cls == 'Comment': | 249 elif cls == 'Comment': |
249 continue | 250 continue |
250 elif cls == 'ExtAttribute': | 251 elif cls == 'ExtAttribute': |
251 if node.name == 'nodoc': | 252 if node.name == 'nodoc': |
252 nodoc = bool(node.value) | 253 nodoc = bool(node.value) |
253 else: | 254 else: |
254 continue | 255 continue |
255 else: | 256 else: |
256 sys.exit("Did not process %s %s" % (node.cls, node)) | 257 sys.exit("Did not process %s %s" % (node.cls, node)) |
258 schema_util.PrefixSchemasWithNamespace(namespaces) | |
257 return namespaces | 259 return namespaces |
258 | 260 |
259 def Load(filename): | 261 def Load(filename): |
260 ''' | 262 ''' |
261 Given the filename of an IDL file, parses it and returns an equivalent | 263 Given the filename of an IDL file, parses it and returns an equivalent |
262 Python dictionary in a format that the JSON schema compiler expects to see. | 264 Python dictionary in a format that the JSON schema compiler expects to see. |
263 ''' | 265 ''' |
264 | 266 |
265 f = open(filename, 'r') | 267 f = open(filename, 'r') |
266 contents = f.read() | 268 contents = f.read() |
267 f.close() | 269 f.close() |
268 | 270 |
269 idl = idl_parser.IDLParser().ParseData(contents, filename) | 271 idl = idl_parser.IDLParser().ParseData(contents, filename) |
270 idl_schema = IDLSchema(idl) | 272 idl_schema = IDLSchema(idl) |
271 return idl_schema.process() | 273 return idl_schema.process() |
272 | 274 |
273 def Main(): | 275 def Main(): |
274 ''' | 276 ''' |
275 Dump a json serialization of parse result for the IDL files whose names | 277 Dump a json serialization of parse result for the IDL files whose names |
276 were passed in on the command line. | 278 were passed in on the command line. |
277 ''' | 279 ''' |
278 for filename in sys.argv[1:]: | 280 for filename in sys.argv[1:]: |
279 schema = Load(filename) | 281 schema = Load(filename) |
280 print json.dumps(schema, indent=2) | 282 print json.dumps(schema, indent=2) |
281 | 283 |
282 if __name__ == '__main__': | 284 if __name__ == '__main__': |
283 Main() | 285 Main() |
OLD | NEW |