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 # $if VAR | 11 # $if VAR |
11 # $else | 12 # $else |
12 # $endif | 13 # $endif |
13 # | 14 # |
14 # VAR must be defined in the conditions dictionary. | 15 # VAR must be defined in the conditions dictionary. |
15 | 16 |
16 import os | 17 import os |
17 | 18 |
18 class TemplateLoader(object): | 19 class TemplateLoader(object): |
19 """Loads template files from a path.""" | 20 """Loads template files from a path.""" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 95 |
95 elif directive == '$endif': | 96 elif directive == '$endif': |
96 if not condition_stack: | 97 if not condition_stack: |
97 error(lineno, '$endif without $if') | 98 error(lineno, '$endif without $if') |
98 (active, seen_else) = condition_stack.pop() | 99 (active, seen_else) = condition_stack.pop() |
99 | 100 |
100 else: | 101 else: |
101 # Something else, like '$!MEMBERS' | 102 # Something else, like '$!MEMBERS' |
102 if active: | 103 if active: |
103 out.append(full_line) | 104 out.append(full_line) |
| 105 elif line.startswith('//$'): |
| 106 pass # Ignore pre-processor comment. |
104 | 107 |
105 else: | 108 else: |
106 if active: | 109 if active: |
107 out.append(full_line) | 110 out.append(full_line) |
108 continue | 111 continue |
109 | 112 |
110 if condition_stack: | 113 if condition_stack: |
111 error(len(lines), 'Unterminated $if') | 114 error(len(lines), 'Unterminated $if') |
112 | 115 |
113 return ''.join(out) | 116 return ''.join(out) |
OLD | NEW |