Chromium Code Reviews| Index: build/android/gyp/java_cpp_enum.py |
| diff --git a/build/android/gyp/java_cpp_enum.py b/build/android/gyp/java_cpp_enum.py |
| index d645a678ed4aba5706be1d5700ce08047bfe1748..25e2bb8789047251dc8f6cbb534e1dc841d904a5 100755 |
| --- a/build/android/gyp/java_cpp_enum.py |
| +++ b/build/android/gyp/java_cpp_enum.py |
| @@ -130,7 +130,7 @@ class DirectiveSet(object): |
| class HeaderParser(object): |
| - single_line_comment_re = re.compile(r'\s*//\s*([^\n]+)') |
| + single_line_comment_re = re.compile(r'\s*//\s*([^\n]*)') |
| multi_line_comment_start_re = re.compile(r'\s*/\*') |
| enum_line_re = re.compile(r'^\s*(\w+)(\s*\=\s*([^,\n]+))?,?') |
| enum_end_re = re.compile(r'^\s*}\s*;\.*$') |
| @@ -159,6 +159,7 @@ class HeaderParser(object): |
| self._current_comments = [] |
| self._generator_directives = DirectiveSet() |
| self._multi_line_generator_directive = None |
| + self._current_enum_entry = '' |
| def _ApplyGeneratorDirectives(self): |
| self._generator_directives.UpdateDefinition(self._current_definition) |
| @@ -178,21 +179,15 @@ class HeaderParser(object): |
| self._ParseEnumLine(line) |
| def _ParseEnumLine(self, line): |
| - enum_comment = HeaderParser.single_line_comment_re.match(line) |
| - if enum_comment: |
| - self._current_comments.append(enum_comment.groups()[0]) |
| - return |
| - if HeaderParser.multi_line_comment_start_re.match(line): |
| - raise Exception('Multi-line comments in enums are not supported in ' + |
| - self._path) |
| - enum_end = HeaderParser.enum_end_re.match(line) |
| - enum_entry = HeaderParser.enum_line_re.match(line) |
| - if enum_end: |
| - self._ApplyGeneratorDirectives() |
| - self._current_definition.Finalize() |
| - self._enum_definitions.append(self._current_definition) |
| - self._in_enum = False |
| - elif enum_entry: |
| + def _ParseCurrentEnumEntry(): |
|
agrieve
2016/10/04 15:57:28
Looks like these helpers don't use their outer con
estevenson
2016/10/04 16:15:25
Done.
|
| + if not self._current_enum_entry: |
| + return |
| + |
| + enum_entry = HeaderParser.enum_line_re.match(self._current_enum_entry) |
| + if not enum_entry: |
| + raise Exception('Unexpected error while attempting to parse %s as enum ' |
| + 'entry.' % self._current_enum_entry) |
| + |
| enum_key = enum_entry.groups()[0] |
| enum_value = enum_entry.groups()[2] |
| self._current_definition.AppendEntry(enum_key, enum_value) |
| @@ -200,6 +195,34 @@ class HeaderParser(object): |
| self._current_definition.AppendEntryComment( |
| enum_key, ' '.join(self._current_comments)) |
| self._current_comments = [] |
| + self._current_enum_entry = '' |
| + |
| + def _AddToCurrentEnumEntry(line): |
| + self._current_enum_entry += ' ' + line.strip() |
| + |
| + def _FinalizeCurrentEnumEntry(): |
| + if self._current_enum_entry: |
| + _ParseCurrentEnumEntry() |
| + self._ApplyGeneratorDirectives() |
| + self._current_definition.Finalize() |
| + self._enum_definitions.append(self._current_definition) |
| + self._in_enum = False |
| + |
| + if HeaderParser.multi_line_comment_start_re.match(line): |
| + raise Exception('Multi-line comments in enums are not supported in ' + |
| + self._path) |
| + |
| + enum_comment = HeaderParser.single_line_comment_re.match(line) |
| + if enum_comment: |
| + comment = enum_comment.groups()[0] |
| + if comment: |
| + self._current_comments.append(comment) |
| + elif HeaderParser.enum_end_re.match(line): |
| + _FinalizeCurrentEnumEntry() |
| + else: |
| + _AddToCurrentEnumEntry(line) |
| + if ',' in line: |
| + _ParseCurrentEnumEntry() |
| def _ParseMultiLineDirectiveLine(self, line): |
| multi_line_directive_continuation = ( |