| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 # Template loader and preprocessor. | 6 # Template loader and preprocessor. |
| 7 # | 7 # |
| 8 # Preprocessor language: | 8 # Preprocessor language: |
| 9 # | 9 # |
| 10 # //$ Comment line removed by preprocessor | 10 # //$ Comment line removed by preprocessor |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if line.startswith('$'): | 75 if line.startswith('$'): |
| 76 words = line.split() | 76 words = line.split() |
| 77 directive = words[0] | 77 directive = words[0] |
| 78 | 78 |
| 79 if directive == '$if': | 79 if directive == '$if': |
| 80 if len(words) != 2: | 80 if len(words) != 2: |
| 81 error(lineno, '$if does not have single variable') | 81 error(lineno, '$if does not have single variable') |
| 82 variable = words[1] | 82 variable = words[1] |
| 83 if variable in conditions: | 83 if variable in conditions: |
| 84 condition_stack.append((active, seen_else)) | 84 condition_stack.append((active, seen_else)) |
| 85 active = conditions[variable] | 85 active = active and conditions[variable] |
| 86 seen_else = False | 86 seen_else = False |
| 87 else: | 87 else: |
| 88 error(lineno, "Unknown $if variable '%s'" % variable) | 88 error(lineno, "Unknown $if variable '%s'" % variable) |
| 89 | 89 |
| 90 elif directive == '$else': | 90 elif directive == '$else': |
| 91 if not condition_stack: | 91 if not condition_stack: |
| 92 error(lineno, '$else without $if') | 92 error(lineno, '$else without $if') |
| 93 if seen_else: | 93 if seen_else: |
| 94 raise error(lineno, 'Double $else') | 94 raise error(lineno, 'Double $else') |
| 95 seen_else = True | 95 seen_else = True |
| 96 active = not active | 96 (parentactive, _) = condition_stack[len(condition_stack) - 1] |
| 97 active = not active and parentactive |
| 97 | 98 |
| 98 elif directive == '$endif': | 99 elif directive == '$endif': |
| 99 if not condition_stack: | 100 if not condition_stack: |
| 100 error(lineno, '$endif without $if') | 101 error(lineno, '$endif without $if') |
| 101 (active, seen_else) = condition_stack.pop() | 102 (active, seen_else) = condition_stack.pop() |
| 102 | 103 |
| 103 else: | 104 else: |
| 104 # Something else, like '$!MEMBERS' | 105 # Something else, like '$!MEMBERS' |
| 105 if active: | 106 if active: |
| 106 out.append(full_line) | 107 out.append(full_line) |
| 107 elif line.startswith('//$'): | 108 elif line.startswith('//$'): |
| 108 pass # Ignore pre-processor comment. | 109 pass # Ignore pre-processor comment. |
| 109 | 110 |
| 110 else: | 111 else: |
| 111 if active: | 112 if active: |
| 112 out.append(full_line) | 113 out.append(full_line) |
| 113 continue | 114 continue |
| 114 | 115 |
| 115 if condition_stack: | 116 if condition_stack: |
| 116 error(len(lines), 'Unterminated $if') | 117 error(len(lines), 'Unterminated $if') |
| 117 | 118 |
| 118 return ''.join(out) | 119 return ''.join(out) |
| OLD | NEW |