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

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

Issue 1015033003: [Extension API Extern Generation] Auto-generate enums (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_externs_generator.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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 def Load(filename): 464 def Load(filename):
465 ''' 465 '''
466 Given the filename of an IDL file, parses it and returns an equivalent 466 Given the filename of an IDL file, parses it and returns an equivalent
467 Python dictionary in a format that the JSON schema compiler expects to see. 467 Python dictionary in a format that the JSON schema compiler expects to see.
468 ''' 468 '''
469 469
470 f = open(filename, 'r') 470 f = open(filename, 'r')
471 contents = f.read() 471 contents = f.read()
472 f.close() 472 f.close()
473 473
474 return Process(contents, filename)
475
476
477 def Process(contents, filename):
478 '''
479 Processes the contents of a file and returns an equivalent Python dictionary
480 in a format that the JSON schema compiler expects to see. (Separate from
481 Load primarily for testing purposes.)
482 '''
483
474 idl = idl_parser.IDLParser().ParseData(contents, filename) 484 idl = idl_parser.IDLParser().ParseData(contents, filename)
475 idl_schema = IDLSchema(idl) 485 idl_schema = IDLSchema(idl)
476 return idl_schema.process() 486 return idl_schema.process()
477 487
478 488
479 def Main(): 489 def Main():
480 ''' 490 '''
481 Dump a json serialization of parse result for the IDL files whose names 491 Dump a json serialization of parse result for the IDL files whose names
482 were passed in on the command line. 492 were passed in on the command line.
483 ''' 493 '''
484 if len(sys.argv) > 1: 494 if len(sys.argv) > 1:
485 for filename in sys.argv[1:]: 495 for filename in sys.argv[1:]:
486 schema = Load(filename) 496 schema = Load(filename)
487 print json.dumps(schema, indent=2) 497 print json.dumps(schema, indent=2)
488 else: 498 else:
489 contents = sys.stdin.read() 499 contents = sys.stdin.read()
490 idl = idl_parser.IDLParser().ParseData(contents, '<stdin>') 500 idl = idl_parser.IDLParser().ParseData(contents, '<stdin>')
491 schema = IDLSchema(idl).process() 501 schema = IDLSchema(idl).process()
492 print json.dumps(schema, indent=2) 502 print json.dumps(schema, indent=2)
493 503
494 504
495 if __name__ == '__main__': 505 if __name__ == '__main__':
496 Main() 506 Main()
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_externs_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698