OLD | NEW |
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 Loading... |
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/bindings", "mojo/public/sky") | 45 return path.replace("mojo/public/js", "mojo/public/sky") |
46 | 46 |
47 def Parse(amd_module): | 47 def Parse(amd_module): |
48 module = Module() | 48 module = Module() |
49 body_lines = [] | 49 body_lines = [] |
50 state = "name" | 50 state = "name" |
51 for line in amd_module.splitlines(): | 51 for line in amd_module.splitlines(): |
52 if state == "name": | 52 if state == "name": |
53 m = name_regex.search(line) | 53 m = name_regex.search(line) |
54 if m: | 54 if m: |
55 module.name = m.group(1) | 55 module.name = m.group(1) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 with open(args.input, "r") as input_file: | 90 with open(args.input, "r") as input_file: |
91 module = Parse(input_file.read()) | 91 module = Parse(input_file.read()) |
92 | 92 |
93 with open(args.output, "w+") as output_file: | 93 with open(args.output, "w+") as output_file: |
94 output_file.write(Serialize(module)) | 94 output_file.write(Serialize(module)) |
95 | 95 |
96 return 0 | 96 return 0 |
97 | 97 |
98 if __name__ == "__main__": | 98 if __name__ == "__main__": |
99 sys.exit(main()) | 99 sys.exit(main()) |
OLD | NEW |