@@ -249,10 +249,14 @@ pub(crate) enum SfzToken {
249249
250250 /// Parses an Opcode, including the value
251251 ///
252- /// Opcodes and assigned opcode values are separated by the equal to sign (=),
253- /// without spaces between the opcode and the sign.
252+ /// Opcodes and assigned opcode values are separated by the equal- to sign
253+ /// `=`, without spaces between the opcode and the sign.
254254 ///
255- #[ regex( "[a-zA-Z0-9_]+=.+" , Opcode :: parse_opcode) ]
255+ /// All opcodes can be in the same line, separated by spaces, except for
256+ /// **sample**, which must not have any other opcode after it in the same
257+ /// line, in order to recognize filenames with spaces.
258+ #[ regex( "sample=.+" , Opcode :: parse_opcode) ]
259+ #[ regex( "[a-zA-Z0-9_]+=[\\ w.]+" , Opcode :: parse_opcode) ]
256260 Opcode ( Opcode ) ,
257261
258262 #[ regex( r"[ \t\n\f]+" , logos:: skip) ]
@@ -354,12 +358,10 @@ mod tests_token {
354358 let mut lex = SfzToken :: lexer (
355359 "<region>
356360sample=MOHorn_mute_A#1_v1_1.wav
357- lokey=46
358- hikey=48
361+ lokey=46 hikey=48
359362pitch_keycenter=46
360- lovel=0
361- hivel=62
362- volume=17" ,
363+ lovel=0 hivel=62
364+ volume=2.0" ,
363365 ) ;
364366
365367 assert_eq ! ( lex. next( ) , Some ( SfzToken :: Header ( Header :: Region ) ) ) ;
@@ -371,12 +373,13 @@ volume=17",
371373 "MOHorn_mute_A#1_v1_1.wav"
372374 ) ) ) )
373375 ) ;
376+ // recognize multiple opcodes in the same line
374377 assert_eq ! ( lex. next( ) , Some ( SfzToken :: Opcode ( Opcode :: lokey( 46 ) ) ) ) ;
375- // assert_eq!(lex.next(), Some(SfzToken::Opcode(Opcode::hikey(48))));
376- // assert_eq!(lex.next(), Some(SfzToken::Opcode(Opcode::pitch_keycenter(46))));
377- // assert_eq!(lex.next(), Some(SfzToken::Opcode(Opcode::lovel(0))));
378- // assert_eq!(lex.next(), Some(SfzToken::Opcode(Opcode::hivel(62))));
379- // assert_eq!(lex.next(), Some(SfzToken::Opcode(Opcode::volume(17 .0))));
378+ assert_eq ! ( lex. next( ) , Some ( SfzToken :: Opcode ( Opcode :: hikey( 48 ) ) ) ) ;
379+ assert_eq ! ( lex. next( ) , Some ( SfzToken :: Opcode ( Opcode :: pitch_keycenter( 46 ) ) ) ) ;
380+ assert_eq ! ( lex. next( ) , Some ( SfzToken :: Opcode ( Opcode :: lovel( 0 ) ) ) ) ;
381+ assert_eq ! ( lex. next( ) , Some ( SfzToken :: Opcode ( Opcode :: hivel( 62 ) ) ) ) ;
382+ assert_eq ! ( lex. next( ) , Some ( SfzToken :: Opcode ( Opcode :: volume( 2 .0) ) ) ) ;
380383 }
381384}
382385
0 commit comments