| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 Returns: A tuple that looks like: | 50 Returns: A tuple that looks like: |
| 51 ( | 51 ( |
| 52 "The processed comment, minus all |parameter| mentions.", | 52 "The processed comment, minus all |parameter| mentions.", |
| 53 { | 53 { |
| 54 'parameter_name_1': "The comment that followed |parameter_name_1|:", | 54 'parameter_name_1': "The comment that followed |parameter_name_1|:", |
| 55 ... | 55 ... |
| 56 } | 56 } |
| 57 ) | 57 ) |
| 58 ''' | 58 ''' |
| 59 # Find all the parameter comments of the form '|name|: comment'. | 59 # Find all the parameter comments of the form '|name|: comment'. |
| 60 parameter_starts = list(re.finditer(r'\n *\|([^|]*)\| *: *', comment)) | 60 parameter_starts = list(re.finditer(r' *\|([^|]*)\| *: *', comment)) |
| 61 | 61 |
| 62 # Get the parent comment (everything before the first parameter comment. | 62 # Get the parent comment (everything before the first parameter comment. |
| 63 first_parameter_location = (parameter_starts[0].start() | 63 first_parameter_location = (parameter_starts[0].start() |
| 64 if parameter_starts else len(comment)) | 64 if parameter_starts else len(comment)) |
| 65 parent_comment = comment[:first_parameter_location] | 65 parent_comment = comment[:first_parameter_location] |
| 66 | 66 |
| 67 # We replace \n\n with <br/><br/> here and below, because the documentation | 67 # We replace \n\n with <br/><br/> here and below, because the documentation |
| 68 # needs to know where the newlines should be, and this is easier than | 68 # needs to know where the newlines should be, and this is easier than |
| 69 # escaping \n. | 69 # escaping \n. |
| 70 parent_comment = (parent_comment.strip().replace('\n\n', '<br/><br/>') | 70 parent_comment = (parent_comment.strip().replace('\n\n', '<br/><br/>') |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 instance_of = self.parent.GetProperty('instanceOf') | 222 instance_of = self.parent.GetProperty('instanceOf') |
| 223 if instance_of: | 223 if instance_of: |
| 224 properties['isInstanceOf'] = instance_of | 224 properties['isInstanceOf'] = instance_of |
| 225 elif self.typeref == 'ArrayBuffer': | 225 elif self.typeref == 'ArrayBuffer': |
| 226 properties['type'] = 'binary' | 226 properties['type'] = 'binary' |
| 227 properties['isInstanceOf'] = 'ArrayBuffer' | 227 properties['isInstanceOf'] = 'ArrayBuffer' |
| 228 elif self.typeref is None: | 228 elif self.typeref is None: |
| 229 properties['type'] = 'function' | 229 properties['type'] = 'function' |
| 230 else: | 230 else: |
| 231 if self.typeref in callbacks: | 231 if self.typeref in callbacks: |
| 232 # Do not override name and description if they are already specified. |
| 233 name = properties.get('name', None) |
| 234 description = properties.get('description', None) |
| 232 properties.update(callbacks[self.typeref]) | 235 properties.update(callbacks[self.typeref]) |
| 236 if description is not None: |
| 237 properties['description'] = description |
| 238 if name is not None: |
| 239 properties['name'] = name |
| 233 else: | 240 else: |
| 234 properties['$ref'] = self.typeref | 241 properties['$ref'] = self.typeref |
| 235 | |
| 236 return result | 242 return result |
| 237 | 243 |
| 238 | 244 |
| 239 class Enum(object): | 245 class Enum(object): |
| 240 ''' | 246 ''' |
| 241 Given an IDL Enum node, converts into a Python dictionary that the JSON | 247 Given an IDL Enum node, converts into a Python dictionary that the JSON |
| 242 schema compiler expects to see. | 248 schema compiler expects to see. |
| 243 ''' | 249 ''' |
| 244 def __init__(self, enum_node): | 250 def __init__(self, enum_node): |
| 245 self.node = enum_node | 251 self.node = enum_node |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 ''' | 373 ''' |
| 368 Dump a json serialization of parse result for the IDL files whose names | 374 Dump a json serialization of parse result for the IDL files whose names |
| 369 were passed in on the command line. | 375 were passed in on the command line. |
| 370 ''' | 376 ''' |
| 371 for filename in sys.argv[1:]: | 377 for filename in sys.argv[1:]: |
| 372 schema = Load(filename) | 378 schema = Load(filename) |
| 373 print json.dumps(schema, indent=2) | 379 print json.dumps(schema, indent=2) |
| 374 | 380 |
| 375 if __name__ == '__main__': | 381 if __name__ == '__main__': |
| 376 Main() | 382 Main() |
| OLD | NEW |