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 itertools | 6 import itertools |
7 import json | 7 import json |
8 import os.path | 8 import os.path |
9 import re | 9 import re |
10 import sys | 10 import sys |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 result[property_name] = True | 302 result[property_name] = True |
303 return result | 303 return result |
304 | 304 |
305 | 305 |
306 class Namespace(object): | 306 class Namespace(object): |
307 ''' | 307 ''' |
308 Given an IDLNode representing an IDL namespace, converts into a Python | 308 Given an IDLNode representing an IDL namespace, converts into a Python |
309 dictionary that the JSON schema compiler expects to see. | 309 dictionary that the JSON schema compiler expects to see. |
310 ''' | 310 ''' |
311 | 311 |
312 def __init__(self, namespace_node, nodoc=False, permissions=None, | 312 def __init__(self, namespace_node, nodoc=False, internal=False): |
313 internal=False): | |
314 self.namespace = namespace_node | 313 self.namespace = namespace_node |
315 self.nodoc = nodoc | 314 self.nodoc = nodoc |
316 self.internal = internal | 315 self.internal = internal |
317 self.events = [] | 316 self.events = [] |
318 self.functions = [] | 317 self.functions = [] |
319 self.types = [] | 318 self.types = [] |
320 self.callbacks = OrderedDict() | 319 self.callbacks = OrderedDict() |
321 self.permissions = permissions or [] | |
322 | 320 |
323 def process(self): | 321 def process(self): |
324 for node in self.namespace.children: | 322 for node in self.namespace.children: |
325 if node.cls == 'Dictionary': | 323 if node.cls == 'Dictionary': |
326 self.types.append(Dictionary(node).process(self.callbacks)) | 324 self.types.append(Dictionary(node).process(self.callbacks)) |
327 elif node.cls == 'Callback': | 325 elif node.cls == 'Callback': |
328 k, v = Member(node).process(self.callbacks) | 326 k, v = Member(node).process(self.callbacks) |
329 self.callbacks[k] = v | 327 self.callbacks[k] = v |
330 elif node.cls == 'Interface' and node.GetName() == 'Functions': | 328 elif node.cls == 'Interface' and node.GetName() == 'Functions': |
331 self.functions = self.process_interface(node) | 329 self.functions = self.process_interface(node) |
332 elif node.cls == 'Interface' and node.GetName() == 'Events': | 330 elif node.cls == 'Interface' and node.GetName() == 'Events': |
333 self.events = self.process_interface(node) | 331 self.events = self.process_interface(node) |
334 elif node.cls == 'Enum': | 332 elif node.cls == 'Enum': |
335 self.types.append(Enum(node).process(self.callbacks)) | 333 self.types.append(Enum(node).process(self.callbacks)) |
336 else: | 334 else: |
337 sys.exit('Did not process %s %s' % (node.cls, node)) | 335 sys.exit('Did not process %s %s' % (node.cls, node)) |
338 return {'namespace': self.namespace.GetName(), | 336 return {'namespace': self.namespace.GetName(), |
339 'nodoc': self.nodoc, | 337 'nodoc': self.nodoc, |
340 'documentation_permissions_required': self.permissions, | |
341 'types': self.types, | 338 'types': self.types, |
342 'functions': self.functions, | 339 'functions': self.functions, |
343 'internal': self.internal, | 340 'internal': self.internal, |
344 'events': self.events} | 341 'events': self.events} |
345 | 342 |
346 def process_interface(self, node): | 343 def process_interface(self, node): |
347 members = [] | 344 members = [] |
348 for member in node.children: | 345 for member in node.children: |
349 if member.cls == 'Member': | 346 if member.cls == 'Member': |
350 name, properties = Member(member).process(self.callbacks) | 347 name, properties = Member(member).process(self.callbacks) |
351 members.append(properties) | 348 members.append(properties) |
352 return members | 349 return members |
353 | 350 |
354 class IDLSchema(object): | 351 class IDLSchema(object): |
355 ''' | 352 ''' |
356 Given a list of IDLNodes and IDLAttributes, converts into a Python list | 353 Given a list of IDLNodes and IDLAttributes, converts into a Python list |
357 of api_defs that the JSON schema compiler expects to see. | 354 of api_defs that the JSON schema compiler expects to see. |
358 ''' | 355 ''' |
359 | 356 |
360 def __init__(self, idl): | 357 def __init__(self, idl): |
361 self.idl = idl | 358 self.idl = idl |
362 | 359 |
363 def process(self): | 360 def process(self): |
364 namespaces = [] | 361 namespaces = [] |
365 nodoc = False | 362 nodoc = False |
366 internal = False | 363 internal = False |
367 permissions = None | |
368 for node in self.idl: | 364 for node in self.idl: |
369 if node.cls == 'Namespace': | 365 if node.cls == 'Namespace': |
370 namespace = Namespace(node, nodoc, permissions, internal) | 366 namespace = Namespace(node, nodoc, internal) |
371 namespaces.append(namespace.process()) | 367 namespaces.append(namespace.process()) |
372 nodoc = False | 368 nodoc = False |
373 internal = False | 369 internal = False |
374 elif node.cls == 'Copyright': | 370 elif node.cls == 'Copyright': |
375 continue | 371 continue |
376 elif node.cls == 'Comment': | 372 elif node.cls == 'Comment': |
377 continue | 373 continue |
378 elif node.cls == 'ExtAttribute': | 374 elif node.cls == 'ExtAttribute': |
379 if node.name == 'nodoc': | 375 if node.name == 'nodoc': |
380 nodoc = bool(node.value) | 376 nodoc = bool(node.value) |
381 elif node.name == 'permissions': | |
382 permission = node.value.split(',') | |
383 elif node.name == 'internal': | 377 elif node.name == 'internal': |
384 internal = bool(node.value) | 378 internal = bool(node.value) |
385 else: | 379 else: |
386 continue | 380 continue |
387 else: | 381 else: |
388 sys.exit('Did not process %s %s' % (node.cls, node)) | 382 sys.exit('Did not process %s %s' % (node.cls, node)) |
389 return namespaces | 383 return namespaces |
390 | 384 |
391 def Load(filename): | 385 def Load(filename): |
392 ''' | 386 ''' |
(...skipping 13 matching lines...) Expand all Loading... |
406 ''' | 400 ''' |
407 Dump a json serialization of parse result for the IDL files whose names | 401 Dump a json serialization of parse result for the IDL files whose names |
408 were passed in on the command line. | 402 were passed in on the command line. |
409 ''' | 403 ''' |
410 for filename in sys.argv[1:]: | 404 for filename in sys.argv[1:]: |
411 schema = Load(filename) | 405 schema = Load(filename) |
412 print json.dumps(schema, indent=2) | 406 print json.dumps(schema, indent=2) |
413 | 407 |
414 if __name__ == '__main__': | 408 if __name__ == '__main__': |
415 Main() | 409 Main() |
OLD | NEW |