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
diff --git a/tools/generate-operator-out.py b/tools/generate-operator-out.py
index 88753b5..aa0c00e 100755
--- a/tools/generate-operator-out.py
+++ b/tools/generate-operator-out.py
@@ -103,8 +103,14 @@
in_enum = False
continue
- # Strip // comments.
- line = re.sub(r'^ *//.*', '', raw_line)
+ # The only useful thing in comments is the <<alternate text>> 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 @@
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 @@
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