Generalize the define regex
Handle underscore in the variable name and negative numbers
This commit is contained in:
parent
0d0298b1be
commit
3f2184227a
4 changed files with 12 additions and 3 deletions
|
|
@ -5,7 +5,7 @@ namespace sfz
|
|||
namespace Regexes
|
||||
{
|
||||
static std::regex includes { R"V(#include\s*"(.*?)".*$)V", std::regex::optimize };
|
||||
static std::regex defines { R"(#define\s*(\$[a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)(?=\s|$))", std::regex::optimize };
|
||||
static std::regex defines { R"(#define\s*(\$[a-zA-Z0-9_]+)\s+([a-zA-Z0-9-]+)(?=\s|$))", std::regex::optimize };
|
||||
static std::regex headers { R"(<(.*?)>(.*?)(?=<|$))", std::regex::optimize };
|
||||
static std::regex members { R"(([a-zA-Z0-9_]+)=([a-zA-Z0-9-_#.&\/\s\\\(\),\*]+)(?![a-zA-Z0-9_]*=))", std::regex::optimize };
|
||||
static std::regex opcodeParameters { R"(([a-zA-Z0-9_]+?)([0-9]+)$)", std::regex::optimize };
|
||||
|
|
|
|||
|
|
@ -127,10 +127,11 @@ TEST_CASE("[Files] Define test")
|
|||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/defines.sfz");
|
||||
REQUIRE(synth.getNumRegions() == 3);
|
||||
REQUIRE(synth.getNumRegions() == 4);
|
||||
REQUIRE(synth.getRegionView(0)->keyRange == sfz::Range<uint8_t>(36, 36));
|
||||
REQUIRE(synth.getRegionView(1)->keyRange == sfz::Range<uint8_t>(38, 38));
|
||||
REQUIRE(synth.getRegionView(2)->keyRange == sfz::Range<uint8_t>(42, 42));
|
||||
REQUIRE(synth.getRegionView(3)->volume == -12.0f);
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Group from AVL")
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "Regexes.h"
|
||||
#include <iostream>
|
||||
#include "catch2/catch.hpp"
|
||||
using namespace Catch::literals;
|
||||
|
||||
|
|
@ -29,6 +30,8 @@ void includeTest(const std::string& line, const std::string& fileName)
|
|||
{
|
||||
std::smatch includeMatch;
|
||||
auto found = std::regex_search(line, includeMatch, sfz::Regexes::includes);
|
||||
if (!found)
|
||||
std::cerr << "Define test failed: " << line << '\n';
|
||||
REQUIRE(found);
|
||||
REQUIRE(includeMatch[1] == fileName);
|
||||
}
|
||||
|
|
@ -70,6 +73,9 @@ TEST_CASE("[Regex] #define")
|
|||
defineTest("#define $alphanum asr1t44", "$alphanum", "asr1t44");
|
||||
defineTest("#define $whitespace asr1t44 ", "$whitespace", "asr1t44");
|
||||
defineTest("#define $lazyMatching matched bfasd ", "$lazyMatching", "matched");
|
||||
defineTest("#define $stircut -12", "$stircut", "-12");
|
||||
defineTest("#define $_ht_under_score_ 3fd", "$_ht_under_score_", "3fd");
|
||||
defineTest("#define $ht_under_score 3fd", "$ht_under_score", "3fd");
|
||||
defineFail("#define $symbols# 1");
|
||||
defineFail("#define $symbolsAgain $1");
|
||||
defineFail("#define $trailingSymbols 1$");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
#define $KICKKEY 36
|
||||
#define $SNAREKEY 38
|
||||
#define $HATKEY 42
|
||||
#define $vol_db -12
|
||||
|
||||
<region>key=$KICKKEY sample=kick.wav
|
||||
<region>key=$SNAREKEY sample=snare.wav
|
||||
<region>key=$HATKEY sample=closedhat.wav
|
||||
<region>key=$HATKEY sample=closedhat.wav
|
||||
<region>volume=$vol_db sample=*sine
|
||||
Loading…
Add table
Reference in a new issue