Skip to content
This repository has been archived by the owner on Aug 30, 2020. It is now read-only.

Commit

Permalink
Use regex for matching placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
ozars committed Aug 1, 2019
1 parent 590302c commit 6959741
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions config_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,18 @@ def generate_ycm_conf(flags, config_file, template_file):
with open(config_file, "w") as output:
output.write("# Generated by YCM Generator at {}\n\n".format(str(datetime.datetime.today())))

placeholder_regex = re.compile(r"^(\s*)# INSERT FLAGS HERE$")

for line in template:
if(line == " # INSERT FLAGS HERE\n"):
match = placeholder_regex.match(line)
if(match):
# insert generated code
indent = match.group(1)
for flag in flags:
if(isinstance(flag, basestring)):
output.write(" '{}',\n".format(flag))
output.write("{}'{}',\n".format(indent, flag))
else: # is tuple
output.write(" '{}', '{}',\n".format(*flag))
output.write("{}'{}', '{}',\n".format(indent, *flag))

else:
# copy template
Expand Down

0 comments on commit 6959741

Please sign in to comment.