Fix a parsing error in presence of # sign
This commit is contained in:
parent
257ed120b7
commit
014171f815
2 changed files with 18 additions and 4 deletions
|
|
@ -310,9 +310,19 @@ void Parser::processOpcode()
|
||||||
// if there aren't non-space characters following, do not extract
|
// if there aren't non-space characters following, do not extract
|
||||||
if (i == valueSize)
|
if (i == valueSize)
|
||||||
stop = true;
|
stop = true;
|
||||||
// if a "<" or "#" character is next, a header or a directive follows
|
// if a "<" character is next, a header follows
|
||||||
else if (valueRaw[i] == '<' || valueRaw[i] == '#')
|
else if (valueRaw[i] == '<')
|
||||||
stop = true;
|
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
|
// if sequence of identifier chars and then "=", an opcode follows
|
||||||
else if (isIdentifierChar(valueRaw[i])) {
|
else if (isIdentifierChar(valueRaw[i])) {
|
||||||
++i;
|
++i;
|
||||||
|
|
|
||||||
|
|
@ -585,13 +585,17 @@ TEST_CASE("[Parsing] Opcode value with inline directives")
|
||||||
ParsingMocker mock;
|
ParsingMocker mock;
|
||||||
parser.setListener(&mock);
|
parser.setListener(&mock);
|
||||||
parser.parseString("/opcodeValueWithInlineDirective.sfz",
|
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 = {
|
std::vector<std::vector<sfz::Opcode>> expectedMembers = {
|
||||||
{{"sample", "v1.wav"}},
|
{{"sample", "v1.wav"}},
|
||||||
|
{{"sample", "v2.wav #notAdirective 123"}},
|
||||||
};
|
};
|
||||||
std::vector<std::string> expectedHeaders = {
|
std::vector<std::string> expectedHeaders = {
|
||||||
"region"
|
"region", "region"
|
||||||
};
|
};
|
||||||
std::vector<sfz::Opcode> expectedOpcodes;
|
std::vector<sfz::Opcode> expectedOpcodes;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue