def create_ebnf_parser(files):
flag = False<EOL>for belspec_fn in files:<EOL><INDENT>if config["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>tmpl_fn = get_ebnf_template()<EOL><DEDENT>ebnf_fn = belspec_fn.replace("<STR_LIT>", "<STR_LIT>")<EOL>if not os.path.exists(ebnf_fn) or os.path.getmtime(belspec_fn) > os.path.getmtime(ebnf_fn):<EOL><INDENT>with open(belspec_fn, "<STR_LIT:r>") as f:<EOL><INDENT>belspec = yaml.load(f, Loader=yaml.SafeLoader)<EOL><DEDENT>tmpl_dir = os.path.dirname(tmpl_fn)<EOL>tmpl_basename = os.path.basename(tmpl_fn)<EOL>bel_major_version = belspec["<STR_LIT:version>"].split("<STR_LIT:.>")[<NUM_LIT:0>]<EOL>env = jinja2.Environment(<EOL>loader=jinja2.FileSystemLoader(tmpl_dir)<EOL>)  <EOL>template = env.get_template(tmpl_basename)  <EOL>relations_list = [<EOL>(relation, belspec["<STR_LIT>"]["<STR_LIT:info>"][relation]["<STR_LIT>"])<EOL>for relation in belspec["<STR_LIT>"]["<STR_LIT:info>"]<EOL>]<EOL>relations_list = sorted(list(itertools.chain(*relations_list)), key=len, reverse=True)<EOL>functions_list = [<EOL>(function, belspec["<STR_LIT>"]["<STR_LIT:info>"][function]["<STR_LIT>"])<EOL>for function in belspec["<STR_LIT>"]["<STR_LIT:info>"]<EOL>if belspec["<STR_LIT>"]["<STR_LIT:info>"][function]["<STR_LIT:type>"] == "<STR_LIT>"<EOL>]<EOL>functions_list = sorted(list(itertools.chain(*functions_list)), key=len, reverse=True)<EOL>modifiers_list = [<EOL>(function, belspec["<STR_LIT>"]["<STR_LIT:info>"][function]["<STR_LIT>"])<EOL>for function in belspec["<STR_LIT>"]["<STR_LIT:info>"]<EOL>if belspec["<STR_LIT>"]["<STR_LIT:info>"][function]["<STR_LIT:type>"] == "<STR_LIT>"<EOL>]<EOL>modifiers_list = sorted(list(itertools.chain(*modifiers_list)), key=len, reverse=True)<EOL>created_time = datetime.datetime.now().strftime("<STR_LIT>")<EOL>ebnf = template.render(<EOL>functions=functions_list,<EOL>m_functions=modifiers_list,<EOL>relations=relations_list,<EOL>bel_version=belspec["<STR_LIT:version>"],<EOL>bel_major_version=bel_major_version,<EOL>created_time=created_time,<EOL>)<EOL>with open(ebnf_fn, "<STR_LIT:w>") as f:<EOL><INDENT>f.write(ebnf)<EOL><DEDENT>parser_fn = ebnf_fn.replace("<STR_LIT>", "<STR_LIT>")<EOL>parser = tatsu.to_python_sourcecode(ebnf, filename=parser_fn)<EOL>flag = True<EOL>with open(parser_fn, "<STR_LIT>") as f:<EOL><INDENT>f.write(parser)<EOL><DEDENT><DEDENT><DEDENT>if flag:<EOL><INDENT>importlib.invalidate_caches()<EOL><DEDENT>
Create EBNF files and EBNF-based parsers