| 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 = '<link rel="import" href="/%s.html" as="%s" />' | 10 IMPORT_TEMPLATE = '<link rel="import" href="/%s.html" as="%s" />' |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if state == "imports": | 63 if state == "imports": |
| 64 m = import_regex.search(line) | 64 m = import_regex.search(line) |
| 65 if m: | 65 if m: |
| 66 module.imports.append(Import(RewritePathNames(m.group(1)), None)) | 66 module.imports.append(Import(RewritePathNames(m.group(1)), None)) |
| 67 continue | 67 continue |
| 68 m = begin_body_regexp.search(line) | 68 m = begin_body_regexp.search(line) |
| 69 if m: | 69 if m: |
| 70 AddImportNames(module, m.group(1)) | 70 AddImportNames(module, m.group(1)) |
| 71 state = "body" | 71 state = "body" |
| 72 continue | 72 continue |
| 73 raise Exception, "Unknown import declaration" | 73 raise Exception, "Unknown import declaration:" + line |
| 74 if state == "body": | 74 if state == "body": |
| 75 if end_body_regexp.search(line): | 75 if end_body_regexp.search(line): |
| 76 module.body = "\n".join(body_lines) | 76 module.body = "\n".join(body_lines) |
| 77 return module | 77 return module |
| 78 body_lines.append(line) | 78 body_lines.append(line) |
| 79 continue | 79 continue |
| 80 raise Exception, "Unknown parser state" | 80 raise Exception, "Unknown parser state" |
| 81 raise Exception, "End of file reached with finding a module" | 81 raise Exception, "End of file reached with finding a module" |
| 82 | 82 |
| 83 def main(): | 83 def main(): |
| 84 parser = argparse.ArgumentParser() | 84 parser = argparse.ArgumentParser() |
| 85 parser.add_argument("--input") | 85 parser.add_argument("--input") |
| 86 parser.add_argument("--output") | 86 parser.add_argument("--output") |
| 87 args = parser.parse_args() | 87 args = parser.parse_args() |
| 88 | 88 |
| 89 module = None | 89 module = None |
| 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 |