| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 #!/usr/bin/env python |
| 3 |
| 4 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 6 # found in the LICENSE file. |
| 5 | 7 |
| 6 """Pretty-prints the contents of a GYP file.""" | 8 """Pretty-prints the contents of a GYP file.""" |
| 7 | 9 |
| 8 import sys | 10 import sys |
| 9 import re | 11 import re |
| 10 | 12 |
| 11 | 13 |
| 12 # Regex to remove comments when we're counting braces. | 14 # Regex to remove comments when we're counting braces. |
| 13 COMMENT_RE = re.compile(r'\s*#.*') | 15 COMMENT_RE = re.compile(r'\s*#.*') |
| 14 | 16 |
| 15 # Regex to remove quoted strings when we're counting braces. | 17 # Regex to remove quoted strings when we're counting braces. |
| 16 # It takes into account quoted quotes, and makes sure that the quotes match. | 18 # It takes into account quoted quotes, and makes sure that the quotes match. |
| 17 # NOTE: It does not handle quotes that span more than one line, or | 19 # NOTE: It does not handle quotes that span more than one line, or |
| 18 # cases where an escaped quote is preceeded by an escaped backslash. | 20 # cases where an escaped quote is preceeded by an escaped backslash. |
| 19 quote_re_str = r'(?P<q>[\'"])(.*?)(?<![^\\][\\])(?P=q)' | 21 QUOTE_RE_STR = r'(?P<q>[\'"])(.*?)(?<![^\\][\\])(?P=q)' |
| 20 QUOTE_RE = re.compile(QUOTE_RE_STR) | 22 QUOTE_RE = re.compile(QUOTE_RE_STR) |
| 21 | 23 |
| 22 | 24 |
| 23 def comment_replace(matchobj): | 25 def comment_replace(matchobj): |
| 24 return matchobj.group(1) + matchobj.group(2) + '#' * len(matchobj.group(3)) | 26 return matchobj.group(1) + matchobj.group(2) + '#' * len(matchobj.group(3)) |
| 25 | 27 |
| 26 | 28 |
| 27 def mask_comments(input): | 29 def mask_comments(input): |
| 28 """Mask the quoted strings so we skip braces inside quoted strings.""" | 30 """Mask the quoted strings so we skip braces inside quoted strings.""" |
| 29 search_re = re.compile(r'(.*?)(#)(.*)') | 31 search_re = re.compile(r'(.*?)(#)(.*)') |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 # Split up the double braces. | 147 # Split up the double braces. |
| 146 lines = split_double_braces(data) | 148 lines = split_double_braces(data) |
| 147 | 149 |
| 148 # Indent and print the output. | 150 # Indent and print the output. |
| 149 prettyprint_input(lines) | 151 prettyprint_input(lines) |
| 150 return 0 | 152 return 0 |
| 151 | 153 |
| 152 | 154 |
| 153 if __name__ == '__main__': | 155 if __name__ == '__main__': |
| 154 sys.exit(main()) | 156 sys.exit(main()) |
| OLD | NEW |