Skip to content

Instantly share code, notes, and snippets.

@erikaderstedt
Last active December 5, 2019 17:40
Show Gist options
  • Save erikaderstedt/6b238875ef9824a2a6a87eb42e276ded to your computer and use it in GitHub Desktop.
Save erikaderstedt/6b238875ef9824a2a6a87eb42e276ded to your computer and use it in GitHub Desktop.
import sys
import re
x = re.compile('(\S+):')
s = open(sys.argv[1],'r').readlines()
s = [x.strip() for x in s]
s = [x for x in s if x[:2] != '//' and x != '']
cmds = []
tags = {}
for r in s:
m = x.match(r)
if m is not None:
tags[m.groups()[0]] = len(cmds)
else:
cmds.extend([x for x in r.split(',') if x != ''])
cmds = [tags.get(x) if x in tags else int(x) for x in cmds]
print(','.join([str(x) for x in cmds]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment