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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 result['inline_doc'] = True | 255 result['inline_doc'] = True |
256 return result | 256 return result |
257 | 257 |
258 | 258 |
259 class Namespace(object): | 259 class Namespace(object): |
260 ''' | 260 ''' |
261 Given an IDLNode representing an IDL namespace, converts into a Python | 261 Given an IDLNode representing an IDL namespace, converts into a Python |
262 dictionary that the JSON schema compiler expects to see. | 262 dictionary that the JSON schema compiler expects to see. |
263 ''' | 263 ''' |
264 | 264 |
265 def __init__(self, namespace_node, nodoc=False, permissions=None): | 265 def __init__(self, namespace_node, nodoc=False, permissions=None, |
| 266 internal=False): |
266 self.namespace = namespace_node | 267 self.namespace = namespace_node |
267 self.nodoc = nodoc | 268 self.nodoc = nodoc |
| 269 self.internal = internal |
268 self.events = [] | 270 self.events = [] |
269 self.functions = [] | 271 self.functions = [] |
270 self.types = [] | 272 self.types = [] |
271 self.callbacks = {} | 273 self.callbacks = {} |
272 self.permissions = permissions or [] | 274 self.permissions = permissions or [] |
273 | 275 |
274 def process(self): | 276 def process(self): |
275 for node in self.namespace.children: | 277 for node in self.namespace.children: |
276 if node.cls == 'Dictionary': | 278 if node.cls == 'Dictionary': |
277 self.types.append(Dictionary(node).process(self.callbacks)) | 279 self.types.append(Dictionary(node).process(self.callbacks)) |
278 elif node.cls == 'Callback': | 280 elif node.cls == 'Callback': |
279 k, v = Member(node).process(self.callbacks) | 281 k, v = Member(node).process(self.callbacks) |
280 self.callbacks[k] = v | 282 self.callbacks[k] = v |
281 elif node.cls == 'Interface' and node.GetName() == 'Functions': | 283 elif node.cls == 'Interface' and node.GetName() == 'Functions': |
282 self.functions = self.process_interface(node) | 284 self.functions = self.process_interface(node) |
283 elif node.cls == 'Interface' and node.GetName() == 'Events': | 285 elif node.cls == 'Interface' and node.GetName() == 'Events': |
284 self.events = self.process_interface(node) | 286 self.events = self.process_interface(node) |
285 elif node.cls == 'Enum': | 287 elif node.cls == 'Enum': |
286 self.types.append(Enum(node).process(self.callbacks)) | 288 self.types.append(Enum(node).process(self.callbacks)) |
287 else: | 289 else: |
288 sys.exit('Did not process %s %s' % (node.cls, node)) | 290 sys.exit('Did not process %s %s' % (node.cls, node)) |
289 return {'namespace': self.namespace.GetName(), | 291 return {'namespace': self.namespace.GetName(), |
290 'nodoc': self.nodoc, | 292 'nodoc': self.nodoc, |
291 'documentation_permissions_required': self.permissions, | 293 'documentation_permissions_required': self.permissions, |
292 'types': self.types, | 294 'types': self.types, |
293 'functions': self.functions, | 295 'functions': self.functions, |
| 296 'internal': self.internal, |
294 'events': self.events} | 297 'events': self.events} |
295 | 298 |
296 def process_interface(self, node): | 299 def process_interface(self, node): |
297 members = [] | 300 members = [] |
298 for member in node.children: | 301 for member in node.children: |
299 if member.cls == 'Member': | 302 if member.cls == 'Member': |
300 name, properties = Member(member).process(self.callbacks) | 303 name, properties = Member(member).process(self.callbacks) |
301 members.append(properties) | 304 members.append(properties) |
302 return members | 305 return members |
303 | 306 |
304 class IDLSchema(object): | 307 class IDLSchema(object): |
305 ''' | 308 ''' |
306 Given a list of IDLNodes and IDLAttributes, converts into a Python list | 309 Given a list of IDLNodes and IDLAttributes, converts into a Python list |
307 of api_defs that the JSON schema compiler expects to see. | 310 of api_defs that the JSON schema compiler expects to see. |
308 ''' | 311 ''' |
309 | 312 |
310 def __init__(self, idl): | 313 def __init__(self, idl): |
311 self.idl = idl | 314 self.idl = idl |
312 | 315 |
313 def process(self): | 316 def process(self): |
314 namespaces = [] | 317 namespaces = [] |
315 nodoc = False | 318 nodoc = False |
| 319 internal = False |
316 permissions = None | 320 permissions = None |
317 for node in self.idl: | 321 for node in self.idl: |
318 if node.cls == 'Namespace': | 322 if node.cls == 'Namespace': |
319 namespace = Namespace(node, nodoc, permissions) | 323 namespace = Namespace(node, nodoc, permissions, internal) |
320 namespaces.append(namespace.process()) | 324 namespaces.append(namespace.process()) |
| 325 nodoc = False |
| 326 internal = False |
321 elif node.cls == 'Copyright': | 327 elif node.cls == 'Copyright': |
322 continue | 328 continue |
323 elif node.cls == 'Comment': | 329 elif node.cls == 'Comment': |
324 continue | 330 continue |
325 elif node.cls == 'ExtAttribute': | 331 elif node.cls == 'ExtAttribute': |
326 if node.name == 'nodoc': | 332 if node.name == 'nodoc': |
327 nodoc = bool(node.value) | 333 nodoc = bool(node.value) |
328 elif node.name == 'permissions': | 334 elif node.name == 'permissions': |
329 permission = node.value.split(',') | 335 permission = node.value.split(',') |
| 336 elif node.name == 'internal': |
| 337 internal = bool(node.value) |
330 else: | 338 else: |
331 continue | 339 continue |
332 else: | 340 else: |
333 sys.exit('Did not process %s %s' % (node.cls, node)) | 341 sys.exit('Did not process %s %s' % (node.cls, node)) |
334 schema_util.PrefixSchemasWithNamespace(namespaces) | 342 schema_util.PrefixSchemasWithNamespace(namespaces) |
335 return namespaces | 343 return namespaces |
336 | 344 |
337 def Load(filename): | 345 def Load(filename): |
338 ''' | 346 ''' |
339 Given the filename of an IDL file, parses it and returns an equivalent | 347 Given the filename of an IDL file, parses it and returns an equivalent |
(...skipping 12 matching lines...) Expand all Loading... |
352 ''' | 360 ''' |
353 Dump a json serialization of parse result for the IDL files whose names | 361 Dump a json serialization of parse result for the IDL files whose names |
354 were passed in on the command line. | 362 were passed in on the command line. |
355 ''' | 363 ''' |
356 for filename in sys.argv[1:]: | 364 for filename in sys.argv[1:]: |
357 schema = Load(filename) | 365 schema = Load(filename) |
358 print json.dumps(schema, indent=2) | 366 print json.dumps(schema, indent=2) |
359 | 367 |
360 if __name__ == '__main__': | 368 if __name__ == '__main__': |
361 Main() | 369 Main() |
OLD | NEW |