alda-lang / alda-core

The core machinery of Alda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rests at the end of event sequence blocks throw a parser error

elydpg opened this issue · comments

This one is best explained with examples

[c d c ] #parsed correctly
[c d c] #parsed correctly
[c d c r ] #parsed correctly
[c d c r] #throws parse error

Good catch! I think this should be an easy fix.

Hm... I'm still not all that familiar with the clojure code though I could take a look if I knew where...

Sure, that would be great!

In this case, I think I know exactly where the problem is. While we're tokenizing the input and parsing through the characters in a rest, we only consider the rest to be "done" when we encounter a space, newline, EOF, or a digit representing duration, and we throw an exception otherwise. The code for that logic is here.

I was having the same problem for notes, and I fixed it by doing this: when an unknown character (e.g. a ]) is encountered, instead of throwing an error, we just say that the note is "done" and start trying to parse a new token (e.g. a "close event sequence" event).

I think that if we do the same thing in the "else" branch for rests, that will fix this problem.

I'd like to add test cases, too, so we can make sure this stays fixed in the future.