On Sat, Jul 26, 2008 at 00:03, Anders Dahnielson <anders@email-addr-hiddenwrote:
>
>
> On Wed, Jul 23, 2008 at 18:13, Anders Dahnielson <anders@email-addr-hiddenwrote:
>
>>
>> Here's a simple tokenizer for SFZ I wrote once upon a time in Python. Not
>> sure if I got it completely right.
>>
>
> Nope. E.g. it matches lokey= twice (once as lokey= with a value and as key=
> without a value). *Blushes*. LOL.
>
>
Ok, this is now an old thread. But to not appear as a complete fool I will
post some code that actually works. ;-)
[BEGIN PYTHON]
import sys
def parse(f):
token_stack = []
string_stack = []
for line in f:
# COMMENT
if line.startswith('//'):
continue
# DEFINITION
for token in line.split():
if token.startswith('<') and token.endswith('>'):
# HEAD
if string_stack:
token_stack.append(" ".join(string_stack))
string_stack[:] = []
string_stack.append(token)
elif token.find('=') != -1:
# HEAD
if string_stack:
token_stack.append(" ".join(string_stack))
string_stack[:] = []
string_stack.append(token)
else:
# TAIL
string_stack.append(token)
# EOL
if string_stack:
token_stack.append(" ".join(string_stack))
string_stack[:] = []
return token_stack
if __name__ == '__main__':
sfzf = open(sys.argv[1], 'r')
print parse(sfzf)
sfzf.close()
[END PYTHON]
-- Anders Dahnielson <anders@email-addr-hidden>
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Sat Sep 6 04:15:02 2008
This archive was generated by hypermail 2.1.8 : Sat Sep 06 2008 - 04:15:03 EEST