- while getToken():
- if token in ("#ifdef", "#ifndef", "#include",
- "#endif", "#elif", "#else", '#define'):
- skipDirective()
- elif match('enum'):
- forceId()
- enum_tag = token
- getToken()
-
- forceMatch("{")
-
- constants = []
- while isId(token):
- constants.append(token)
- getToken()
- if match('='):
- while token != ',' and token != '}':
- getToken()
- match(',')
-
- forceMatch('}')
-
- if enum_tag == "ofp_error_type":
- error_types = {}
- for error_type in constants:
- error_types[error_type] = []
- elif enum_tag == 'nx_vendor_code':
- pass
- elif enum_tag.endswith('_code'):
- error_type = 'OFPET_%s' % '_'.join(enum_tag.split('_')[1:-1]).upper()
- if error_type not in error_types:
- fatal("enum %s looks like an error code enumeration but %s is unknown" % (enum_tag, error_type))
- error_types[error_type] += constants
- elif token in ('struct', 'union'):
- getToken()
- forceId()
- getToken()
- forceMatch('{')
- while not match('}'):
- getToken()
- elif match('OFP_ASSERT') or match('BOOST_STATIC_ASSERT'):
- while token != ';':
- getToken()
- else:
- fatal("parse error")
+
+ while True:
+ getLine()
+ if re.match('enum ofperr', line):
+ break
+
+ while True:
+ getLine()
+ if line.startswith('/*') or not line or line.isspace():
+ continue
+ elif re.match('}', line):
+ break
+
+ m = re.match('\s+/\* ((?:.(?!\. ))+.)\. (.*)$', line)
+ if not m:
+ fatal("unexpected syntax between errors")
+
+ dsts, comment = m.groups()
+
+ comment.rstrip()
+ while not comment.endswith('*/'):
+ getLine()
+ if line.startswith('/*') or not line or line.isspace():
+ fatal("unexpected syntax within error")
+ comment += ' %s' % line.lstrip('* \t').rstrip(' \t\r\n')
+ comment = comment[:-2].rstrip()
+
+ getLine()
+ m = re.match('\s+(?:OFPERR_((?:OFP|NX)[A-Z0-9_]+))(\s*=\s*OFPERR_OFS)?,',
+ line)
+ if not m:
+ fatal("syntax error expecting enum value")
+
+ enum = m.group(1)
+
+ comments.append(comment)
+ names.append(enum)
+
+ for dst in dsts.split(', '):
+ m = re.match(r'([A-Z0-9.]+)\((\d+)(?:,(\d+))?\)$', dst)
+ if not m:
+ fatal("%s: syntax error in destination" % dst)
+ targets = m.group(1)
+ type_ = int(m.group(2))
+ if m.group(3):
+ code = int(m.group(3))
+ else:
+ code = None
+
+ target_map = {"OF": ("OF1.0", "OF1.1"),
+ "OF1.0": ("OF1.0",),
+ "OF1.1": ("OF1.1",),
+ "NX": ("OF1.0", "OF1.1"),
+ "NX1.0": ("OF1.0",),
+ "NX1.1": ("OF1.1",)}
+ if targets not in target_map:
+ fatal("%s: unknown error domain" % target)
+ for target in target_map[targets]:
+ if type_ not in domain[target]:
+ domain[target][type_] = {}
+ if code in domain[target][type_]:
+ fatal("%s: duplicate assignment in domain" % dst)
+ domain[target][type_][code] = enum
+ reverse[target][enum] = (type_, code)
+