I dont think you can use regex to match a whole expression like that but you can use it to pick off bits and pieces. Just make a regex that matches all of the possible commands + options and run that through, advancing the string position each time. Eg

"o4l8cdefg" => string code;
string matches[0];
"((o)([0-9]+)|([abcdefg])(1|2|4|8|16)?|(l)([0-9]+))" => string pattern;

for(0 => int i; i < code.length(); )
{
    if(RegEx.match(pattern, code.substring(i), matches))
    {
        if(matches[2] == "o")
            <<< "octave:", matches[3] >>>;
        else if(matches[4] == "a")
            <<< "a" >>>;
        // etc.
        
        matches[0].length() +=> i;
    }
    else
    {
        <<< "invalid code" >>>;
        break;
    }
}

I dont know anything about MML so I dont know what the final regex would look like. 

Another option is to just go through the string iteratively and look at each character one at a time. If whitespace is undesirable StringTokenizer might be hurting more than helping here. 

for(0 => int i; i < code.length(); )
{
    int c = code.charAt(i);
    if(c == 'o')
    {
         // look for number
    }
    else if(c == 'a' || c == 'b' || ... )
    {
         // see if number follows
    }
}

spencer



On Tue, Sep 6, 2016 at 6:32 PM, Colton Hill <colton-hill2014@hotmail.com> wrote:
I also want to make sure I have a customizable play function that will
handle my playing. Here's the code I've been using for my current mml
parser in chuck, actually does take a code string and a play function,
and operates well. Only issue is including doesn't work... So have a test.


On 9/6/2016 3:33 AM, Hans Åberg wrote:
>> On 5 Sep 2016, at 23:16, Colton Hill <colton-hill2014@hotmail.com> wrote:
>>
>> I know regular expressions syntax, but I really don't know how I would
>> manage to make an mml parser that actually works. Turn o4l8cdefg into
>> octave 4, length 8, and c d e f g notes with an 8th note length since no
>> length is specified. Then there's c4., which is c4^c8... Just bla…
> There are free MML parsers in C out there. Linking to ChucK, which is written in C++, might be a way.
>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users@lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users


_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users




--
Spencer Salazar
Doctoral Candidate
Center for Computer Research in Music and Acoustics
Stanford University

+1 831.277.4654