Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a parsing error in presence of # sign #746

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/sfizz/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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