Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: tools/json_schema_compiler/idl_schema.py

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving logic into availability_data_source Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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):
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
320 321
321 def process(self): 322 def process(self):
322 for node in self.namespace.children: 323 for node in self.namespace.children:
323 if node.cls == 'Dictionary': 324 if node.cls == 'Dictionary':
324 self.types.append(Dictionary(node).process(self.callbacks)) 325 self.types.append(Dictionary(node).process(self.callbacks))
325 elif node.cls == 'Callback': 326 elif node.cls == 'Callback':
326 k, v = Member(node).process(self.callbacks) 327 k, v = Member(node).process(self.callbacks)
327 self.callbacks[k] = v 328 self.callbacks[k] = v
328 elif node.cls == 'Interface' and node.GetName() == 'Functions': 329 elif node.cls == 'Interface' and node.GetName() == 'Functions':
329 self.functions = self.process_interface(node) 330 self.functions = self.process_interface(node)
330 elif node.cls == 'Interface' and node.GetName() == 'Events': 331 elif node.cls == 'Interface' and node.GetName() == 'Events':
331 self.events = self.process_interface(node) 332 self.events = self.process_interface(node)
332 elif node.cls == 'Enum': 333 elif node.cls == 'Enum':
333 self.types.append(Enum(node).process(self.callbacks)) 334 self.types.append(Enum(node).process(self.callbacks))
334 else: 335 else:
335 sys.exit('Did not process %s %s' % (node.cls, node)) 336 sys.exit('Did not process %s %s' % (node.cls, node))
336 return {'namespace': self.namespace.GetName(), 337 return {'namespace': self.namespace.GetName(),
338 'description': self.description,
337 'nodoc': self.nodoc, 339 'nodoc': self.nodoc,
338 'documentation_permissions_required': self.permissions, 340 'documentation_permissions_required': self.permissions,
339 'types': self.types, 341 'types': self.types,
340 'functions': self.functions, 342 'functions': self.functions,
341 'internal': self.internal, 343 'internal': self.internal,
342 'events': self.events} 344 'events': self.events}
343 345
344 def process_interface(self, node): 346 def process_interface(self, node):
345 members = [] 347 members = []
346 for member in node.children: 348 for member in node.children:
347 if member.cls == 'Member': 349 if member.cls == 'Member':
348 name, properties = Member(member).process(self.callbacks) 350 name, properties = Member(member).process(self.callbacks)
349 members.append(properties) 351 members.append(properties)
350 return members 352 return members
351 353
352 class IDLSchema(object): 354 class IDLSchema(object):
353 ''' 355 '''
354 Given a list of IDLNodes and IDLAttributes, converts into a Python list 356 Given a list of IDLNodes and IDLAttributes, converts into a Python list
355 of api_defs that the JSON schema compiler expects to see. 357 of api_defs that the JSON schema compiler expects to see.
356 ''' 358 '''
357 359
358 def __init__(self, idl): 360 def __init__(self, idl):
359 self.idl = idl 361 self.idl = idl
360 362
361 def process(self): 363 def process(self):
362 namespaces = [] 364 namespaces = []
363 nodoc = False 365 nodoc = False
364 internal = False 366 internal = False
365 permissions = None 367 permissions = None
368 description = None
366 for node in self.idl: 369 for node in self.idl:
367 if node.cls == 'Namespace': 370 if node.cls == 'Namespace':
368 namespace = Namespace(node, nodoc, permissions, internal) 371 namespace = Namespace(node, nodoc, permissions, internal, description)
369 namespaces.append(namespace.process()) 372 namespaces.append(namespace.process())
370 nodoc = False 373 nodoc = False
371 internal = False 374 internal = False
372 elif node.cls == 'Copyright': 375 elif node.cls == 'Copyright':
373 continue 376 continue
374 elif node.cls == 'Comment': 377 elif node.cls == 'Comment':
375 continue 378 description = node.GetName()
379 if description == '':
380 description = None
376 elif node.cls == 'ExtAttribute': 381 elif node.cls == 'ExtAttribute':
377 if node.name == 'nodoc': 382 if node.name == 'nodoc':
378 nodoc = bool(node.value) 383 nodoc = bool(node.value)
379 elif node.name == 'permissions': 384 elif node.name == 'permissions':
380 permission = node.value.split(',') 385 permission = node.value.split(',')
381 elif node.name == 'internal': 386 elif node.name == 'internal':
382 internal = bool(node.value) 387 internal = bool(node.value)
383 else: 388 else:
384 continue 389 continue
385 else: 390 else:
(...skipping 18 matching lines...) Expand all
404 ''' 409 '''
405 Dump a json serialization of parse result for the IDL files whose names 410 Dump a json serialization of parse result for the IDL files whose names
406 were passed in on the command line. 411 were passed in on the command line.
407 ''' 412 '''
408 for filename in sys.argv[1:]: 413 for filename in sys.argv[1:]:
409 schema = Load(filename) 414 schema = Load(filename)
410 print json.dumps(schema, indent=2) 415 print json.dumps(schema, indent=2)
411 416
412 if __name__ == '__main__': 417 if __name__ == '__main__':
413 Main() 418 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698