Skip to content

Commit

Permalink
Fix a parsing error in presence of # sign
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcima committed Mar 25, 2021
1 parent 257ed12 commit f15023f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/sfizz/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions tests/ParsingT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,17 @@ TEST_CASE("[Parsing] Opcode value with inline directives")
ParsingMocker mock;
parser.setListener(&mock);
parser.parseString("/opcodeValueWithInlineDirective.sfz",
R"(<region>#define $VEL v1 sample=$VEL.wav #define $FOO bar)");
R"(
<region>#define $VEL v1 sample=$VEL.wav #define $FOO bar
<region>#define $VEL v2 sample=$VEL.wav #notAdirective 123
)");

std::vector<std::vector<sfz::Opcode>> expectedMembers = {
{{"sample", "v1.wav"}},
{{"sample", "v2.wav #notAdirective 123"}},
};
std::vector<std::string> expectedHeaders = {
"region"
"region", "region"
};
std::vector<sfz::Opcode> expectedOpcodes;

Expand Down

0 comments on commit f15023f

Please sign in to comment.