Last active
November 11, 2016 20:28
-
-
Save andik/48490834e1e46e451eae to your computer and use it in GitHub Desktop.
super simple SFZ Parser in Python (Python 2.7)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# i claim no copyright on this code and place it in the public domain. | |
# do whatever you want with this code... | |
import argparse | |
parser = argparse.ArgumentParser(description='show differences of two views') | |
o = parser.add_argument | |
o('files', type=str, help='files to process', nargs='+') | |
#o('-b', '--boolarg', action='store_true', help="") | |
#o('-s', '--strarg', help="") | |
args = parser.parse_args() | |
import re | |
comments = re.compile(r'//.*$', re.M) | |
lookfor = re.compile(r'<(\w+)>|(\w+)=([^\s]+)') | |
groupdata = {} | |
regiondata = {} | |
regions = [] | |
for fn in args.files: | |
text = open(fn).read() | |
text = re.sub(comments, '', text) | |
current = None | |
for m in re.finditer(lookfor, text): | |
if m.group(1) == 'group': | |
groupdata = {} | |
current = groupdata | |
elif m.group(1) == 'region': | |
if regiondata != {}: | |
regions.append(regiondata) | |
regiondata = {} | |
regiondata.update(groupdata) | |
current = regiondata | |
else: | |
current[m.group(2)] = m.group(3) | |
print regions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment