From a9719eb4167b544438268d46692389761652fc5d Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 7 Jun 2012 11:09:48 -0700 Subject: Clean up the confusing comment-related logic a bit. This still passes 034, but is a bit clearer because we get all comments out of the way early on. Change-Id: I580ebdca24a4a0738ee102536c8d5b076427264d --- tools/generate-operator-out.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'tools/generate-operator-out.py') diff --git a/tools/generate-operator-out.py b/tools/generate-operator-out.py index 88753b55fb..aa0c00e743 100755 --- a/tools/generate-operator-out.py +++ b/tools/generate-operator-out.py @@ -103,8 +103,14 @@ def ProcessFile(filename): in_enum = False continue - # Strip // comments. - line = re.sub(r'^ *//.*', '', raw_line) + # The only useful thing in comments is the <> syntax for + # overriding the default enum value names. Pull that out... + enum_text = None + m_comment = re.compile(r'// <<(.*?)>>').search(raw_line) + if m_comment: + enum_text = m_comment.group(1) + # ...and then strip // comments. + line = re.sub(r'//.*', '', raw_line) # Strip whitespace. line = line.strip() @@ -113,17 +119,18 @@ def ProcessFile(filename): if len(line) == 0: continue - # Is this another enum value? + # Since we know we're in an enum type, and we're not looking at a comment + # or a blank line, this line should be the next enum value... m = _ENUM_VALUE_RE.search(line) if not m: Confused(filename, line_number, raw_line) - enum_value = m.group(1) # By default, we turn "kSomeValue" into "SomeValue". - enum_text = enum_value - if enum_text.startswith('k'): - enum_text = enum_text[1:] + if enum_text == None: + enum_text = enum_value + if enum_text.startswith('k'): + enum_text = enum_text[1:] # Lose literal values because we don't care; turn "= 123, // blah" into ", // blah". rest = m.group(2).strip() @@ -141,14 +148,10 @@ def ProcessFile(filename): rest = rest[1:] rest = rest.strip() - # Anything left should be a comment. - if len(rest) and not rest.startswith('// '): + # There shouldn't be anything left. + if len(rest): Confused(filename, line_number, raw_line) - m_comment = re.compile(r'<<(.*?)>>').search(rest) - if m_comment: - enum_text = m_comment.group(1) - if len(enclosing_classes) > 0: enum_value = '::'.join(enclosing_classes) + '::' + enum_value -- cgit v1.2.3-59-g8ed1b