def add_data(self, filenames):
def _parse_table(table):<EOL><INDENT>def _parse_line(line):<EOL><INDENT>return line.split('<STR_LIT:\t>')<EOL><DEDENT>lines = (_parse_line(one) for one in table.splitlines()<EOL>if re.match(r'<STR_LIT>', one))<EOL>return (remove_false(one) for one in lines)<EOL><DEDENT>def _parse_decl(decl):<EOL><INDENT>index = len('<STR_LIT>')<EOL>argc = decl[index]<EOL>rest = decl[index + <NUM_LIT:1>:][<NUM_LIT:1>:-<NUM_LIT:1>].split('<STR_LIT:U+002C>')<EOL>name = rest[<NUM_LIT:0>]<EOL>args = '<STR_LIT:U+002C>'.join(rest[<NUM_LIT:1>:])<EOL>return name, argc, args<EOL><DEDENT>def _parse_line(line):<EOL><INDENT>index = line.find('<STR_LIT::>')<EOL>if index == -<NUM_LIT:1>:<EOL><INDENT>raise RuntimeError('<STR_LIT>', line)<EOL><DEDENT>filename = line[:index]<EOL>decl = line[index + <NUM_LIT:1>:]<EOL>return filename, _parse_decl(decl)<EOL><DEDENT>def _split_into_lines(grep_output):<EOL><INDENT>lines = grep_output.replace('<STR_LIT>', '<STR_LIT:\n>')<EOL>lines = lines.replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT:\t>', '<STR_LIT:U+0020>')<EOL>return lines.strip().splitlines()<EOL><DEDENT>for one in filenames:<EOL><INDENT>if one.name.endswith('<STR_LIT>'):<EOL><INDENT>for item in _parse_table(one.read()):<EOL><INDENT>args = list(item)<EOL>if len(args) != <NUM_LIT:5>:<EOL><INDENT>args += ['<STR_LIT>'] * (<NUM_LIT:5> - len(args))<EOL><DEDENT>self.session.add(<EOL>Item(name=args[<NUM_LIT:2>], abi=args[<NUM_LIT:1>],<EOL>number=args[<NUM_LIT:0>], entry=args[<NUM_LIT:3>],<EOL>compat=args[<NUM_LIT:4>]))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for line in _split_into_lines(one.read()):<EOL><INDENT>filename, rest = (_parse_line(line))<EOL>self.session.add(<EOL>Decl(name=rest[<NUM_LIT:0>], filename=filename,<EOL>argc=rest[<NUM_LIT:1>], args=rest[<NUM_LIT:2>]))<EOL><DEDENT><DEDENT><DEDENT>self.session.commit()<EOL>
Add data.