4 AT_LEAST_THREE_DASHES = re.compile(
r'^\-{3,}\r?$')
5 FIELD_LINE = re.compile(
r'([\w_/]+)(\[\d*\])?\s+([\w_]+)\s*(=.*)?(\s*\#.*)?$', re.DOTALL)
6 PRIMITIVES = [
'bool',
'int8',
'uint8',
'int16',
'uint16',
'int32',
'uint32',
'int64',
'uint64',
7 'float32',
'float64',
'string',
'time',
'duration']
11 def __init__(self, field_type, is_array, name, value):
35 stripped = line.strip()
36 if not stripped
or stripped[0] ==
'#':
39 m = FIELD_LINE.match(line)
41 field_type, is_array, name, value, comment = m.groups()
50 raise Exception(
'Unable to parse generator line: ' + repr(line))
53 return ''.join(map(str, self.
contents))
60 parts = os.path.splitext(rel_fn)
63 self.
name = os.path.basename(rel_fn)
69 with open(file_path)
as f:
72 for line
in self.
contents.split(
'\n'):
73 if AT_LEAST_THREE_DASHES.match(line):
80 for field
in section.fields:
81 if '/' not in field.type:
83 package, part = field.type.split(
'/')
84 if package != self.
name:
87 if self.
type ==
'action':
91 return '---\n'.join(map(str, self.
sections))
def __init__(self, rel_fn, file_path)
def __init__(self, field_type, is_array, name, value)