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 |
8 import sys | 9 import sys |
9 import re | 10 |
| 11 import schema_util |
10 | 12 |
11 # This file is a peer to json_schema.py. Each of these files understands a | 13 # 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 | 14 # 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 | 15 # 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 | 16 # 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 | 17 # the JSON schema compiler understands. compiler.py drives both idl_schema.py |
16 # and json_schema.py. | 18 # and json_schema.py. |
17 | 19 |
18 # idl_parser expects to be able to import certain files in its directory, | 20 # idl_parser expects to be able to import certain files in its directory, |
19 # so let's set things up the way it wants. | 21 # so let's set things up the way it wants. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 continue | 251 continue |
250 elif cls == 'Comment': | 252 elif cls == 'Comment': |
251 continue | 253 continue |
252 elif cls == 'ExtAttribute': | 254 elif cls == 'ExtAttribute': |
253 if node.name == 'nodoc': | 255 if node.name == 'nodoc': |
254 nodoc = bool(node.value) | 256 nodoc = bool(node.value) |
255 else: | 257 else: |
256 continue | 258 continue |
257 else: | 259 else: |
258 sys.exit("Did not process %s %s" % (node.cls, node)) | 260 sys.exit("Did not process %s %s" % (node.cls, node)) |
| 261 schema_util.PrefixSchemasWithNamespace(namespaces) |
259 return namespaces | 262 return namespaces |
260 | 263 |
261 def Load(filename): | 264 def Load(filename): |
262 ''' | 265 ''' |
263 Given the filename of an IDL file, parses it and returns an equivalent | 266 Given the filename of an IDL file, parses it and returns an equivalent |
264 Python dictionary in a format that the JSON schema compiler expects to see. | 267 Python dictionary in a format that the JSON schema compiler expects to see. |
265 ''' | 268 ''' |
266 | 269 |
267 f = open(filename, 'r') | 270 f = open(filename, 'r') |
268 contents = f.read() | 271 contents = f.read() |
269 f.close() | 272 f.close() |
270 | 273 |
271 idl = idl_parser.IDLParser().ParseData(contents, filename) | 274 idl = idl_parser.IDLParser().ParseData(contents, filename) |
272 idl_schema = IDLSchema(idl) | 275 idl_schema = IDLSchema(idl) |
273 return idl_schema.process() | 276 return idl_schema.process() |
274 | 277 |
275 def Main(): | 278 def Main(): |
276 ''' | 279 ''' |
277 Dump a json serialization of parse result for the IDL files whose names | 280 Dump a json serialization of parse result for the IDL files whose names |
278 were passed in on the command line. | 281 were passed in on the command line. |
279 ''' | 282 ''' |
280 for filename in sys.argv[1:]: | 283 for filename in sys.argv[1:]: |
281 schema = Load(filename) | 284 schema = Load(filename) |
282 print json.dumps(schema, indent=2) | 285 print json.dumps(schema, indent=2) |
283 | 286 |
284 if __name__ == '__main__': | 287 if __name__ == '__main__': |
285 Main() | 288 Main() |
OLD | NEW |