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