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

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: (kalman) rebase 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 result[property_name] = True 302 result[property_name] = True
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, internal=False): 312 def __init__(self, namespace_node, description, nodoc=False, internal=False):
313 self.namespace = namespace_node 313 self.namespace = namespace_node
314 self.nodoc = nodoc 314 self.nodoc = nodoc
315 self.internal = internal 315 self.internal = internal
316 self.events = [] 316 self.events = []
317 self.functions = [] 317 self.functions = []
318 self.types = [] 318 self.types = []
319 self.callbacks = OrderedDict() 319 self.callbacks = OrderedDict()
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 'types': self.types, 340 'types': self.types,
339 'functions': self.functions, 341 'functions': self.functions,
340 'internal': self.internal, 342 'internal': self.internal,
341 'events': self.events} 343 'events': self.events}
342 344
343 def process_interface(self, node): 345 def process_interface(self, node):
344 members = [] 346 members = []
345 for member in node.children: 347 for member in node.children:
346 if member.cls == 'Member': 348 if member.cls == 'Member':
347 name, properties = Member(member).process(self.callbacks) 349 name, properties = Member(member).process(self.callbacks)
348 members.append(properties) 350 members.append(properties)
349 return members 351 return members
350 352
351 class IDLSchema(object): 353 class IDLSchema(object):
352 ''' 354 '''
353 Given a list of IDLNodes and IDLAttributes, converts into a Python list 355 Given a list of IDLNodes and IDLAttributes, converts into a Python list
354 of api_defs that the JSON schema compiler expects to see. 356 of api_defs that the JSON schema compiler expects to see.
355 ''' 357 '''
356 358
357 def __init__(self, idl): 359 def __init__(self, idl):
358 self.idl = idl 360 self.idl = idl
359 361
360 def process(self): 362 def process(self):
361 namespaces = [] 363 namespaces = []
362 nodoc = False 364 nodoc = False
363 internal = False 365 internal = False
366 description = None
364 for node in self.idl: 367 for node in self.idl:
365 if node.cls == 'Namespace': 368 if node.cls == 'Namespace':
366 namespace = Namespace(node, nodoc, internal) 369 if not description:
370 raise ValueError('%s must have a namespace-level comment. This will '
371 'appear on the API summary page.' % node.GetName())
372 namespace = Namespace(node, description, nodoc, internal)
367 namespaces.append(namespace.process()) 373 namespaces.append(namespace.process())
368 nodoc = False 374 nodoc = False
369 internal = False 375 internal = False
370 elif node.cls == 'Copyright': 376 elif node.cls == 'Copyright':
371 continue 377 continue
372 elif node.cls == 'Comment': 378 elif node.cls == 'Comment':
373 continue 379 description = node.GetName()
374 elif node.cls == 'ExtAttribute': 380 elif node.cls == 'ExtAttribute':
375 if node.name == 'nodoc': 381 if node.name == 'nodoc':
376 nodoc = bool(node.value) 382 nodoc = bool(node.value)
377 elif node.name == 'internal': 383 elif node.name == 'internal':
378 internal = bool(node.value) 384 internal = bool(node.value)
379 else: 385 else:
380 continue 386 continue
381 else: 387 else:
382 sys.exit('Did not process %s %s' % (node.cls, node)) 388 sys.exit('Did not process %s %s' % (node.cls, node))
383 return namespaces 389 return namespaces
(...skipping 16 matching lines...) Expand all
400 ''' 406 '''
401 Dump a json serialization of parse result for the IDL files whose names 407 Dump a json serialization of parse result for the IDL files whose names
402 were passed in on the command line. 408 were passed in on the command line.
403 ''' 409 '''
404 for filename in sys.argv[1:]: 410 for filename in sys.argv[1:]:
405 schema = Load(filename) 411 schema = Load(filename)
406 print json.dumps(schema, indent=2) 412 print json.dumps(schema, indent=2)
407 413
408 if __name__ == '__main__': 414 if __name__ == '__main__':
409 Main() 415 Main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/dart_test/tags.idl ('k') | tools/json_schema_compiler/json_schema_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698