From 014171f81533b2dd4009a470589ed441143bf107 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 25 Mar 2021 13:40:32 +0100 Subject: [PATCH] Fix a parsing error in presence of # sign --- src/sfizz/parser/Parser.cpp | 14 ++++++++++++-- tests/ParsingT.cpp | 8 ++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/sfizz/parser/Parser.cpp b/src/sfizz/parser/Parser.cpp index ba35fc963..40306431c 100644 --- a/src/sfizz/parser/Parser.cpp +++ b/src/sfizz/parser/Parser.cpp @@ -310,9 +310,19 @@ 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; + 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;