diff --git a/src/sfizz/parser/Parser.cpp b/src/sfizz/parser/Parser.cpp index ba35fc963..4787e7064 100644 --- a/src/sfizz/parser/Parser.cpp +++ b/src/sfizz/parser/Parser.cpp @@ -310,9 +310,21 @@ void Parser::processOpcode() // if there aren't non-space characters following, do not extract if (i == valueSize) stop = true; - // if a "<" or "#" character is next, a header or a directive follows - else if (valueRaw[i] == '<' || valueRaw[i] == '#') + // if a "<" character is next, a header follows + else if (valueRaw[i] == '<') stop = true; + // if a "#" character is next, check if a directive follows + else if (valueRaw[i] == '#') { + size_t dirStart = i + 1; + while (dirStart < valueSize && isSpaceChar(valueRaw[dirStart])) + ++dirStart; + size_t dirEnd = dirStart; + while (dirEnd < valueSize && isIdentifierChar(valueRaw[dirEnd])) + ++dirEnd; + absl::string_view dir(&valueRaw[dirStart], dirEnd - dirStart); + if (dir == "define" || dir == "include") + stop = true; + } // if sequence of identifier chars and then "=", an opcode follows else if (isIdentifierChar(valueRaw[i])) { ++i; diff --git a/tests/ParsingT.cpp b/tests/ParsingT.cpp index 99afbefda..cb1096ce5 100644 --- a/tests/ParsingT.cpp +++ b/tests/ParsingT.cpp @@ -585,13 +585,17 @@ TEST_CASE("[Parsing] Opcode value with inline directives") ParsingMocker mock; parser.setListener(&mock); parser.parseString("/opcodeValueWithInlineDirective.sfz", -R"(#define $VEL v1 sample=$VEL.wav #define $FOO bar)"); +R"( +#define $VEL v1 sample=$VEL.wav #define $FOO bar +#define $VEL v2 sample=$VEL.wav #notAdirective 123 +)"); std::vector> expectedMembers = { {{"sample", "v1.wav"}}, + {{"sample", "v2.wav #notAdirective 123"}}, }; std::vector expectedHeaders = { - "region" + "region", "region" }; std::vector expectedOpcodes;