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

Side by Side Diff: mojo/public/sky/convert_amd_modules_to_sky.py

Issue 837283002: Mojo JS Bindings: merge Application, Shell, ServiceProvider with Sky (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Commit missing file Created 5 years, 11 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 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 argparse 6 import argparse
7 import sys 7 import sys
8 import re 8 import re
9 9
10 IMPORT_TEMPLATE = '<import src="/%s.sky" as="%s" />' 10 IMPORT_TEMPLATE = '<import src="/%s.sky" as="%s" />'
(...skipping 24 matching lines...) Expand all
35 import_regex = re.compile(r' +"([^"]+)",') 35 import_regex = re.compile(r' +"([^"]+)",')
36 begin_body_regexp = re.compile(r', function\(([^)]*)\)') 36 begin_body_regexp = re.compile(r', function\(([^)]*)\)')
37 end_body_regexp = re.compile(r'return exports') 37 end_body_regexp = re.compile(r'return exports')
38 38
39 def AddImportNames(module, unparsed_names): 39 def AddImportNames(module, unparsed_names):
40 names = [n.strip() for n in unparsed_names.split(',')] 40 names = [n.strip() for n in unparsed_names.split(',')]
41 for i in range(len(module.imports)): 41 for i in range(len(module.imports)):
42 module.imports[i].name = names[i] 42 module.imports[i].name = names[i]
43 43
44 def RewritePathNames(path): 44 def RewritePathNames(path):
45 return path.replace("mojo/public/js", "mojo/public/sky") 45 return path.replace("mojo/public/js", "mojo/public/sky") \
46 .replace("mojo/services/public/js", "mojo/services/public/sky")
46 47
47 def Parse(amd_module): 48 def Parse(amd_module):
48 module = Module() 49 module = Module()
49 body_lines = [] 50 body_lines = []
50 state = "name" 51 state = "name"
51 for line in amd_module.splitlines(): 52 for line in amd_module.splitlines():
52 if state == "name": 53 if state == "name":
53 m = name_regex.search(line) 54 m = name_regex.search(line)
54 if m: 55 if m:
55 module.name = m.group(1) 56 module.name = m.group(1)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 with open(args.input, "r") as input_file: 91 with open(args.input, "r") as input_file:
91 module = Parse(input_file.read()) 92 module = Parse(input_file.read())
92 93
93 with open(args.output, "w+") as output_file: 94 with open(args.output, "w+") as output_file:
94 output_file.write(Serialize(module)) 95 output_file.write(Serialize(module))
95 96
96 return 0 97 return 0
97 98
98 if __name__ == "__main__": 99 if __name__ == "__main__":
99 sys.exit(main()) 100 sys.exit(main())
OLDNEW
« no previous file with comments | « examples/js/wget.js ('k') | mojo/services/BUILD.gn » ('j') | sky/tools/skydb » ('J')

Powered by Google App Engine
This is Rietveld 408576698