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

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

Issue 273323002: Convert snakecase enum names to camelcase when stringified. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final changes Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « tools/json_schema_compiler/cpp_type_generator.py ('k') | tools/json_schema_compiler/model.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 enum.append(enum_value) 312 enum.append(enum_value)
313 elif node.cls == 'Comment': 313 elif node.cls == 'Comment':
314 self.description = ProcessComment(node.GetName())[0] 314 self.description = ProcessComment(node.GetName())[0]
315 else: 315 else:
316 sys.exit('Did not process %s %s' % (node.cls, node)) 316 sys.exit('Did not process %s %s' % (node.cls, node))
317 result = {'id' : self.node.GetName(), 317 result = {'id' : self.node.GetName(),
318 'description': self.description, 318 'description': self.description,
319 'type': 'string', 319 'type': 'string',
320 'enum': enum} 320 'enum': enum}
321 for property_name in ( 321 for property_name in (
322 'inline_doc', 'noinline_doc', 'nodoc', 'cpp_omit_enum_type',): 322 'inline_doc', 'noinline_doc', 'nodoc', 'cpp_enum_prefix_override',):
323 if self.node.GetProperty(property_name): 323 if self.node.GetProperty(property_name):
324 result[property_name] = True 324 result[property_name] = self.node.GetProperty(property_name)
325 if self.node.GetProperty('deprecated'): 325 if self.node.GetProperty('deprecated'):
326 result[deprecated] = self.node.GetProperty('deprecated') 326 result[deprecated] = self.node.GetProperty('deprecated')
327 return result 327 return result
328 328
329 329
330 class Namespace(object): 330 class Namespace(object):
331 ''' 331 '''
332 Given an IDLNode representing an IDL namespace, converts into a Python 332 Given an IDLNode representing an IDL namespace, converts into a Python
333 dictionary that the JSON schema compiler expects to see. 333 dictionary that the JSON schema compiler expects to see.
334 ''' 334 '''
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 def __init__(self, idl): 401 def __init__(self, idl):
402 self.idl = idl 402 self.idl = idl
403 403
404 def process(self): 404 def process(self):
405 namespaces = [] 405 namespaces = []
406 nodoc = False 406 nodoc = False
407 internal = False 407 internal = False
408 description = None 408 description = None
409 platforms = None 409 platforms = None
410 compiler_options = None 410 compiler_options = {}
411 deprecated = None 411 deprecated = None
412 for node in self.idl: 412 for node in self.idl:
413 if node.cls == 'Namespace': 413 if node.cls == 'Namespace':
414 if not description: 414 if not description:
415 # TODO(kalman): Go back to throwing an error here. 415 # TODO(kalman): Go back to throwing an error here.
416 print('%s must have a namespace-level comment. This will ' 416 print('%s must have a namespace-level comment. This will '
417 'appear on the API summary page.' % node.GetName()) 417 'appear on the API summary page.' % node.GetName())
418 description = '' 418 description = ''
419 namespace = Namespace(node, description, nodoc, internal, 419 namespace = Namespace(node, description, nodoc, internal,
420 platforms=platforms, 420 platforms=platforms,
421 compiler_options=compiler_options, 421 compiler_options=compiler_options or None,
422 deprecated=deprecated) 422 deprecated=deprecated)
423 namespaces.append(namespace.process()) 423 namespaces.append(namespace.process())
424 nodoc = False 424 nodoc = False
425 internal = False 425 internal = False
426 platforms = None 426 platforms = None
427 compiler_options = None 427 compiler_options = None
428 elif node.cls == 'Copyright': 428 elif node.cls == 'Copyright':
429 continue 429 continue
430 elif node.cls == 'Comment': 430 elif node.cls == 'Comment':
431 description = node.GetName() 431 description = node.GetName()
432 elif node.cls == 'ExtAttribute': 432 elif node.cls == 'ExtAttribute':
433 if node.name == 'nodoc': 433 if node.name == 'nodoc':
434 nodoc = bool(node.value) 434 nodoc = bool(node.value)
435 elif node.name == 'internal': 435 elif node.name == 'internal':
436 internal = bool(node.value) 436 internal = bool(node.value)
437 elif node.name == 'platforms': 437 elif node.name == 'platforms':
438 platforms = list(node.value) 438 platforms = list(node.value)
439 elif node.name == 'implemented_in': 439 elif node.name == 'implemented_in':
440 compiler_options = {'implemented_in': node.value} 440 compiler_options['implemented_in'] = node.value
441 elif node.name == 'camel_case_enum_to_string':
442 compiler_options['camel_case_enum_to_string'] = node.value
441 elif node.name == 'deprecated': 443 elif node.name == 'deprecated':
442 deprecated = str(node.value) 444 deprecated = str(node.value)
443 else: 445 else:
444 continue 446 continue
445 else: 447 else:
446 sys.exit('Did not process %s %s' % (node.cls, node)) 448 sys.exit('Did not process %s %s' % (node.cls, node))
447 return namespaces 449 return namespaces
448 450
449 451
450 def Load(filename): 452 def Load(filename):
(...skipping 16 matching lines...) Expand all
467 Dump a json serialization of parse result for the IDL files whose names 469 Dump a json serialization of parse result for the IDL files whose names
468 were passed in on the command line. 470 were passed in on the command line.
469 ''' 471 '''
470 for filename in sys.argv[1:]: 472 for filename in sys.argv[1:]:
471 schema = Load(filename) 473 schema = Load(filename)
472 print json.dumps(schema, indent=2) 474 print json.dumps(schema, indent=2)
473 475
474 476
475 if __name__ == '__main__': 477 if __name__ == '__main__':
476 Main() 478 Main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cpp_type_generator.py ('k') | tools/json_schema_compiler/model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698