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

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

Issue 16876004: Updating JSON Schema Compiler to add description field to schemas. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 return result 303 return result
304 304
305 305
306 class Namespace(object): 306 class Namespace(object):
307 ''' 307 '''
308 Given an IDLNode representing an IDL namespace, converts into a Python 308 Given an IDLNode representing an IDL namespace, converts into a Python
309 dictionary that the JSON schema compiler expects to see. 309 dictionary that the JSON schema compiler expects to see.
310 ''' 310 '''
311 311
312 def __init__(self, namespace_node, nodoc=False, permissions=None, 312 def __init__(self, namespace_node, nodoc=False, permissions=None,
313 internal=False): 313 internal=False, description=None):
314 self.namespace = namespace_node 314 self.namespace = namespace_node
315 self.nodoc = nodoc 315 self.nodoc = nodoc
316 self.internal = internal 316 self.internal = internal
317 self.events = [] 317 self.events = []
318 self.functions = [] 318 self.functions = []
319 self.types = [] 319 self.types = []
320 self.callbacks = OrderedDict() 320 self.callbacks = OrderedDict()
321 self.permissions = permissions or [] 321 self.permissions = permissions or []
322 self.description = description
322 323
323 def process(self): 324 def process(self):
324 for node in self.namespace.children: 325 for node in self.namespace.children:
325 if node.cls == 'Dictionary': 326 if node.cls == 'Dictionary':
326 self.types.append(Dictionary(node).process(self.callbacks)) 327 self.types.append(Dictionary(node).process(self.callbacks))
327 elif node.cls == 'Callback': 328 elif node.cls == 'Callback':
328 k, v = Member(node).process(self.callbacks) 329 k, v = Member(node).process(self.callbacks)
329 self.callbacks[k] = v 330 self.callbacks[k] = v
330 elif node.cls == 'Interface' and node.GetName() == 'Functions': 331 elif node.cls == 'Interface' and node.GetName() == 'Functions':
331 self.functions = self.process_interface(node) 332 self.functions = self.process_interface(node)
332 elif node.cls == 'Interface' and node.GetName() == 'Events': 333 elif node.cls == 'Interface' and node.GetName() == 'Events':
333 self.events = self.process_interface(node) 334 self.events = self.process_interface(node)
334 elif node.cls == 'Enum': 335 elif node.cls == 'Enum':
335 self.types.append(Enum(node).process(self.callbacks)) 336 self.types.append(Enum(node).process(self.callbacks))
336 else: 337 else:
337 sys.exit('Did not process %s %s' % (node.cls, node)) 338 sys.exit('Did not process %s %s' % (node.cls, node))
338 return {'namespace': self.namespace.GetName(), 339 return {'namespace': self.namespace.GetName(),
340 'description': self.description,
339 'nodoc': self.nodoc, 341 'nodoc': self.nodoc,
340 'documentation_permissions_required': self.permissions, 342 'documentation_permissions_required': self.permissions,
341 'types': self.types, 343 'types': self.types,
342 'functions': self.functions, 344 'functions': self.functions,
343 'internal': self.internal, 345 'internal': self.internal,
344 'events': self.events} 346 'events': self.events}
345 347
346 def process_interface(self, node): 348 def process_interface(self, node):
347 members = [] 349 members = []
348 for member in node.children: 350 for member in node.children:
349 if member.cls == 'Member': 351 if member.cls == 'Member':
350 name, properties = Member(member).process(self.callbacks) 352 name, properties = Member(member).process(self.callbacks)
351 members.append(properties) 353 members.append(properties)
352 return members 354 return members
353 355
354 class IDLSchema(object): 356 class IDLSchema(object):
355 ''' 357 '''
356 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
357 of api_defs that the JSON schema compiler expects to see. 359 of api_defs that the JSON schema compiler expects to see.
358 ''' 360 '''
359 361
360 def __init__(self, idl): 362 def __init__(self, idl):
361 self.idl = idl 363 self.idl = idl
362 364
363 def process(self): 365 def process(self):
364 namespaces = [] 366 namespaces = []
365 nodoc = False 367 nodoc = False
366 internal = False 368 internal = False
367 permissions = None 369 permissions = None
370 description = None
368 for node in self.idl: 371 for node in self.idl:
369 if node.cls == 'Namespace': 372 if node.cls == 'Namespace':
370 namespace = Namespace(node, nodoc, permissions, internal) 373 namespace = Namespace(node, nodoc, permissions, internal, description)
371 namespaces.append(namespace.process()) 374 namespaces.append(namespace.process())
372 nodoc = False 375 nodoc = False
373 internal = False 376 internal = False
374 elif node.cls == 'Copyright': 377 elif node.cls == 'Copyright':
375 continue 378 continue
376 elif node.cls == 'Comment': 379 elif node.cls == 'Comment':
377 continue 380 description = node.GetName()
381 if description == '':
382 description = None
378 elif node.cls == 'ExtAttribute': 383 elif node.cls == 'ExtAttribute':
379 if node.name == 'nodoc': 384 if node.name == 'nodoc':
380 nodoc = bool(node.value) 385 nodoc = bool(node.value)
381 elif node.name == 'permissions': 386 elif node.name == 'permissions':
382 permission = node.value.split(',') 387 permission = node.value.split(',')
383 elif node.name == 'internal': 388 elif node.name == 'internal':
384 internal = bool(node.value) 389 internal = bool(node.value)
385 else: 390 else:
386 continue 391 continue
387 else: 392 else:
(...skipping 18 matching lines...) Expand all
406 ''' 411 '''
407 Dump a json serialization of parse result for the IDL files whose names 412 Dump a json serialization of parse result for the IDL files whose names
408 were passed in on the command line. 413 were passed in on the command line.
409 ''' 414 '''
410 for filename in sys.argv[1:]: 415 for filename in sys.argv[1:]:
411 schema = Load(filename) 416 schema = Load(filename)
412 print json.dumps(schema, indent=2) 417 print json.dumps(schema, indent=2)
413 418
414 if __name__ == '__main__': 419 if __name__ == '__main__':
415 Main() 420 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698