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