Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: build/android/gyp/java_cpp_enum.py

Issue 2505703002: Update error message in java_cpp_enum.py. (Closed)
Patch Set: Fix //net/base/request_priority.h empty prefix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/android/gyp/java_cpp_enum_tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import collections 7 import collections
8 from datetime import date 8 from datetime import date
9 import re 9 import re
10 import optparse 10 import optparse
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 DirectiveSet.enum_package_key) 127 DirectiveSet.enum_package_key)
128 definition.prefix_to_strip = self._directives.get( 128 definition.prefix_to_strip = self._directives.get(
129 DirectiveSet.prefix_to_strip_key) 129 DirectiveSet.prefix_to_strip_key)
130 130
131 131
132 class HeaderParser(object): 132 class HeaderParser(object):
133 single_line_comment_re = re.compile(r'\s*//\s*([^\n]*)') 133 single_line_comment_re = re.compile(r'\s*//\s*([^\n]*)')
134 multi_line_comment_start_re = re.compile(r'\s*/\*') 134 multi_line_comment_start_re = re.compile(r'\s*/\*')
135 enum_line_re = re.compile(r'^\s*(\w+)(\s*\=\s*([^,\n]+))?,?') 135 enum_line_re = re.compile(r'^\s*(\w+)(\s*\=\s*([^,\n]+))?,?')
136 enum_end_re = re.compile(r'^\s*}\s*;\.*$') 136 enum_end_re = re.compile(r'^\s*}\s*;\.*$')
137 generator_error_re = re.compile(r'^\s*//\s+GENERATED_JAVA_(\w+)\s*:\s*$')
137 generator_directive_re = re.compile( 138 generator_directive_re = re.compile(
138 r'^\s*//\s+GENERATED_JAVA_(\w+)\s*:\s*([\.\w]+)$') 139 r'^\s*//\s+GENERATED_JAVA_(\w+)\s*:\s*([\.\w]+)$')
139 multi_line_generator_directive_start_re = re.compile( 140 multi_line_generator_directive_start_re = re.compile(
140 r'^\s*//\s+GENERATED_JAVA_(\w+)\s*:\s*\(([\.\w]*)$') 141 r'^\s*//\s+GENERATED_JAVA_(\w+)\s*:\s*\(([\.\w]*)$')
141 multi_line_directive_continuation_re = re.compile( 142 multi_line_directive_continuation_re = re.compile(r'^\s*//\s+([\.\w]+)$')
142 r'^\s*//\s+([\.\w]+)$') 143 multi_line_directive_end_re = re.compile(r'^\s*//\s+([\.\w]*)\)$')
143 multi_line_directive_end_re = re.compile(
144 r'^\s*//\s+([\.\w]*)\)$')
145 144
146 optional_class_or_struct_re = r'(class|struct)?' 145 optional_class_or_struct_re = r'(class|struct)?'
147 enum_name_re = r'(\w+)' 146 enum_name_re = r'(\w+)'
148 optional_fixed_type_re = r'(\:\s*(\w+\s*\w+?))?' 147 optional_fixed_type_re = r'(\:\s*(\w+\s*\w+?))?'
149 enum_start_re = re.compile(r'^\s*(?:\[cpp.*\])?\s*enum\s+' + 148 enum_start_re = re.compile(r'^\s*(?:\[cpp.*\])?\s*enum\s+' +
150 optional_class_or_struct_re + '\s*' + enum_name_re + '\s*' + 149 optional_class_or_struct_re + '\s*' + enum_name_re + '\s*' +
151 optional_fixed_type_re + '\s*{\s*$') 150 optional_fixed_type_re + '\s*{\s*$')
152 151
153 def __init__(self, lines, path=None): 152 def __init__(self, lines, path=''):
154 self._lines = lines 153 self._lines = lines
155 self._path = path 154 self._path = path
156 self._enum_definitions = [] 155 self._enum_definitions = []
157 self._in_enum = False 156 self._in_enum = False
158 self._current_definition = None 157 self._current_definition = None
159 self._current_comments = [] 158 self._current_comments = []
160 self._generator_directives = DirectiveSet() 159 self._generator_directives = DirectiveSet()
161 self._multi_line_generator_directive = None 160 self._multi_line_generator_directive = None
162 self._current_enum_entry = '' 161 self._current_enum_entry = ''
163 162
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 directive_value = "".join(self._multi_line_generator_directive[1]) 237 directive_value = "".join(self._multi_line_generator_directive[1])
239 directive_value += multi_line_directive_end.groups()[0] 238 directive_value += multi_line_directive_end.groups()[0]
240 self._multi_line_generator_directive = None 239 self._multi_line_generator_directive = None
241 self._generator_directives.Update(directive_name, directive_value) 240 self._generator_directives.Update(directive_name, directive_value)
242 else: 241 else:
243 raise Exception('Malformed multi-line directive declaration in ' + 242 raise Exception('Malformed multi-line directive declaration in ' +
244 self._path) 243 self._path)
245 244
246 def _ParseRegularLine(self, line): 245 def _ParseRegularLine(self, line):
247 enum_start = HeaderParser.enum_start_re.match(line) 246 enum_start = HeaderParser.enum_start_re.match(line)
247 generator_directive_error = HeaderParser.generator_error_re.match(line)
248 generator_directive = HeaderParser.generator_directive_re.match(line) 248 generator_directive = HeaderParser.generator_directive_re.match(line)
249 multi_line_generator_directive_start = ( 249 multi_line_generator_directive_start = (
250 HeaderParser.multi_line_generator_directive_start_re.match(line)) 250 HeaderParser.multi_line_generator_directive_start_re.match(line))
251 251
252 if generator_directive: 252 if generator_directive_error:
253 raise Exception('Malformed directive declaration in ' + self._path +
254 '. Use () for multi-line directives. E.g.\n' +
255 '// GENERATED_JAVA_ENUM_PACKAGE: (\n' +
256 '// foo.package)')
257 elif generator_directive:
253 directive_name = generator_directive.groups()[0] 258 directive_name = generator_directive.groups()[0]
254 directive_value = generator_directive.groups()[1] 259 directive_value = generator_directive.groups()[1]
255 self._generator_directives.Update(directive_name, directive_value) 260 self._generator_directives.Update(directive_name, directive_value)
256 elif multi_line_generator_directive_start: 261 elif multi_line_generator_directive_start:
257 directive_name = multi_line_generator_directive_start.groups()[0] 262 directive_name = multi_line_generator_directive_start.groups()[0]
258 directive_value = multi_line_generator_directive_start.groups()[1] 263 directive_value = multi_line_generator_directive_start.groups()[1]
259 self._multi_line_generator_directive = (directive_name, [directive_value]) 264 self._multi_line_generator_directive = (directive_name, [directive_value])
260 elif enum_start: 265 elif enum_start:
261 if self._generator_directives.empty: 266 if self._generator_directives.empty:
262 return 267 return
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar: 386 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar:
382 for output_path, data in DoGenerate(input_paths): 387 for output_path, data in DoGenerate(input_paths):
383 build_utils.AddToZipHermetic(srcjar, output_path, data=data) 388 build_utils.AddToZipHermetic(srcjar, output_path, data=data)
384 389
385 if options.depfile: 390 if options.depfile:
386 build_utils.WriteDepfile(options.depfile, options.srcjar) 391 build_utils.WriteDepfile(options.depfile, options.srcjar)
387 392
388 393
389 if __name__ == '__main__': 394 if __name__ == '__main__':
390 DoMain(sys.argv[1:]) 395 DoMain(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | build/android/gyp/java_cpp_enum_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698