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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 dictionary that the JSON schema compiler expects to see. | 336 dictionary that the JSON schema compiler expects to see. |
337 ''' | 337 ''' |
338 | 338 |
339 def __init__(self, | 339 def __init__(self, |
340 namespace_node, | 340 namespace_node, |
341 description, | 341 description, |
342 nodoc=False, | 342 nodoc=False, |
343 internal=False, | 343 internal=False, |
344 platforms=None, | 344 platforms=None, |
345 compiler_options=None, | 345 compiler_options=None, |
346 deprecated=None): | 346 deprecated=None, |
| 347 documentation_options=None): |
347 self.namespace = namespace_node | 348 self.namespace = namespace_node |
348 self.nodoc = nodoc | 349 self.nodoc = nodoc |
349 self.internal = internal | 350 self.internal = internal |
350 self.platforms = platforms | 351 self.platforms = platforms |
351 self.compiler_options = compiler_options | 352 self.compiler_options = compiler_options |
352 self.events = [] | 353 self.events = [] |
353 self.functions = [] | 354 self.functions = [] |
354 self.types = [] | 355 self.types = [] |
355 self.callbacks = OrderedDict() | 356 self.callbacks = OrderedDict() |
356 self.description = description | 357 self.description = description |
357 self.deprecated = deprecated | 358 self.deprecated = deprecated |
| 359 self.documentation_options = documentation_options |
358 | 360 |
359 def process(self): | 361 def process(self): |
360 for node in self.namespace.GetChildren(): | 362 for node in self.namespace.GetChildren(): |
361 if node.cls == 'Dictionary': | 363 if node.cls == 'Dictionary': |
362 self.types.append(Dictionary(node).process(self.callbacks)) | 364 self.types.append(Dictionary(node).process(self.callbacks)) |
363 elif node.cls == 'Callback': | 365 elif node.cls == 'Callback': |
364 k, v = Member(node).process(self.callbacks) | 366 k, v = Member(node).process(self.callbacks) |
365 self.callbacks[k] = v | 367 self.callbacks[k] = v |
366 elif node.cls == 'Interface' and node.GetName() == 'Functions': | 368 elif node.cls == 'Interface' and node.GetName() == 'Functions': |
367 self.functions = self.process_interface(node) | 369 self.functions = self.process_interface(node) |
368 elif node.cls == 'Interface' and node.GetName() == 'Events': | 370 elif node.cls == 'Interface' and node.GetName() == 'Events': |
369 self.events = self.process_interface(node) | 371 self.events = self.process_interface(node) |
370 elif node.cls == 'Enum': | 372 elif node.cls == 'Enum': |
371 self.types.append(Enum(node).process()) | 373 self.types.append(Enum(node).process()) |
372 else: | 374 else: |
373 sys.exit('Did not process %s %s' % (node.cls, node)) | 375 sys.exit('Did not process %s %s' % (node.cls, node)) |
374 if self.compiler_options is not None: | 376 compiler_options = self.compiler_options or {} |
375 compiler_options = self.compiler_options | 377 documentation_options = self.documentation_options or {} |
376 else: | |
377 compiler_options = {} | |
378 return {'namespace': self.namespace.GetName(), | 378 return {'namespace': self.namespace.GetName(), |
379 'description': self.description, | 379 'description': self.description, |
380 'nodoc': self.nodoc, | 380 'nodoc': self.nodoc, |
381 'types': self.types, | 381 'types': self.types, |
382 'functions': self.functions, | 382 'functions': self.functions, |
383 'internal': self.internal, | 383 'internal': self.internal, |
384 'events': self.events, | 384 'events': self.events, |
385 'platforms': self.platforms, | 385 'platforms': self.platforms, |
386 'compiler_options': compiler_options, | 386 'compiler_options': compiler_options, |
387 'deprecated': self.deprecated} | 387 'deprecated': self.deprecated, |
| 388 'documentation_options': documentation_options} |
388 | 389 |
389 def process_interface(self, node): | 390 def process_interface(self, node): |
390 members = [] | 391 members = [] |
391 for member in node.GetChildren(): | 392 for member in node.GetChildren(): |
392 if member.cls == 'Member': | 393 if member.cls == 'Member': |
393 _, properties = Member(member).process(self.callbacks) | 394 _, properties = Member(member).process(self.callbacks) |
394 members.append(properties) | 395 members.append(properties) |
395 return members | 396 return members |
396 | 397 |
397 | 398 |
398 class IDLSchema(object): | 399 class IDLSchema(object): |
399 ''' | 400 ''' |
400 Given a list of IDLNodes and IDLAttributes, converts into a Python list | 401 Given a list of IDLNodes and IDLAttributes, converts into a Python list |
401 of api_defs that the JSON schema compiler expects to see. | 402 of api_defs that the JSON schema compiler expects to see. |
402 ''' | 403 ''' |
403 | 404 |
404 def __init__(self, idl): | 405 def __init__(self, idl): |
405 self.idl = idl | 406 self.idl = idl |
406 | 407 |
407 def process(self): | 408 def process(self): |
408 namespaces = [] | 409 namespaces = [] |
409 nodoc = False | 410 nodoc = False |
410 internal = False | 411 internal = False |
411 description = None | 412 description = None |
412 platforms = None | 413 platforms = None |
413 compiler_options = {} | 414 compiler_options = {} |
414 deprecated = None | 415 deprecated = None |
| 416 documentation_options = {} |
415 for node in self.idl: | 417 for node in self.idl: |
416 if node.cls == 'Namespace': | 418 if node.cls == 'Namespace': |
417 if not description: | 419 if not description: |
418 # TODO(kalman): Go back to throwing an error here. | 420 # TODO(kalman): Go back to throwing an error here. |
419 print('%s must have a namespace-level comment. This will ' | 421 print('%s must have a namespace-level comment. This will ' |
420 'appear on the API summary page.' % node.GetName()) | 422 'appear on the API summary page.' % node.GetName()) |
421 description = '' | 423 description = '' |
422 namespace = Namespace(node, description, nodoc, internal, | 424 namespace = Namespace(node, description, nodoc, internal, |
423 platforms=platforms, | 425 platforms=platforms, |
424 compiler_options=compiler_options or None, | 426 compiler_options=compiler_options or None, |
425 deprecated=deprecated) | 427 deprecated=deprecated, |
| 428 documentation_options=documentation_options) |
426 namespaces.append(namespace.process()) | 429 namespaces.append(namespace.process()) |
427 nodoc = False | 430 nodoc = False |
428 internal = False | 431 internal = False |
429 platforms = None | 432 platforms = None |
430 compiler_options = None | 433 compiler_options = None |
431 elif node.cls == 'Copyright': | 434 elif node.cls == 'Copyright': |
432 continue | 435 continue |
433 elif node.cls == 'Comment': | 436 elif node.cls == 'Comment': |
434 description = node.GetName() | 437 description = node.GetName() |
435 elif node.cls == 'ExtAttribute': | 438 elif node.cls == 'ExtAttribute': |
436 if node.name == 'nodoc': | 439 if node.name == 'nodoc': |
437 nodoc = bool(node.value) | 440 nodoc = bool(node.value) |
438 elif node.name == 'internal': | 441 elif node.name == 'internal': |
439 internal = bool(node.value) | 442 internal = bool(node.value) |
440 elif node.name == 'platforms': | 443 elif node.name == 'platforms': |
441 platforms = list(node.value) | 444 platforms = list(node.value) |
442 elif node.name == 'implemented_in': | 445 elif node.name == 'implemented_in': |
443 compiler_options['implemented_in'] = node.value | 446 compiler_options['implemented_in'] = node.value |
444 elif node.name == 'camel_case_enum_to_string': | 447 elif node.name == 'camel_case_enum_to_string': |
445 compiler_options['camel_case_enum_to_string'] = node.value | 448 compiler_options['camel_case_enum_to_string'] = node.value |
446 elif node.name == 'deprecated': | 449 elif node.name == 'deprecated': |
447 deprecated = str(node.value) | 450 deprecated = str(node.value) |
| 451 elif node.name == 'documentation_title': |
| 452 documentation_options['title'] = node.value |
| 453 elif node.name == 'documentation_namespace': |
| 454 documentation_options['namespace'] = node.value |
| 455 elif node.name == 'documented_in': |
| 456 documentation_options['documented_in'] = node.value |
448 else: | 457 else: |
449 continue | 458 continue |
450 else: | 459 else: |
451 sys.exit('Did not process %s %s' % (node.cls, node)) | 460 sys.exit('Did not process %s %s' % (node.cls, node)) |
452 return namespaces | 461 return namespaces |
453 | 462 |
454 | 463 |
455 def Load(filename): | 464 def Load(filename): |
456 ''' | 465 ''' |
457 Given the filename of an IDL file, parses it and returns an equivalent | 466 Given the filename of an IDL file, parses it and returns an equivalent |
(...skipping 20 matching lines...) Expand all Loading... |
478 print json.dumps(schema, indent=2) | 487 print json.dumps(schema, indent=2) |
479 else: | 488 else: |
480 contents = sys.stdin.read() | 489 contents = sys.stdin.read() |
481 idl = idl_parser.IDLParser().ParseData(contents, '<stdin>') | 490 idl = idl_parser.IDLParser().ParseData(contents, '<stdin>') |
482 schema = IDLSchema(idl).process() | 491 schema = IDLSchema(idl).process() |
483 print json.dumps(schema, indent=2) | 492 print json.dumps(schema, indent=2) |
484 | 493 |
485 | 494 |
486 if __name__ == '__main__': | 495 if __name__ == '__main__': |
487 Main() | 496 Main() |
OLD | NEW |