Delete the old parser

This commit is contained in:
Jean Pierre Cimalando 2021-02-03 19:14:51 +01:00
parent 3ee7812bd8
commit 6eef90149f
8 changed files with 0 additions and 464 deletions

View file

@ -97,7 +97,6 @@ SFIZZ_SOURCES = \
src/sfizz/Opcode.cpp \
src/sfizz/Oversampler.cpp \
src/sfizz/Panning.cpp \
src/sfizz/Parser.cpp \
src/sfizz/parser/Parser.cpp \
src/sfizz/parser/ParserPrivate.cpp \
src/sfizz/PolyphonyGroup.cpp \
@ -109,7 +108,6 @@ SFIZZ_SOURCES = \
src/sfizz/sfizz.cpp \
src/sfizz/sfizz_wrapper.cpp \
src/sfizz/SfzFilter.cpp \
src/sfizz/SfzHelpers.cpp \
src/sfizz/SIMDHelpers.cpp \
src/sfizz/simd/HelpersSSE.cpp \
src/sfizz/simd/HelpersAVX.cpp \

View file

@ -12,11 +12,9 @@ clang-tidy \
src/sfizz/MidiState.cpp \
src/sfizz/Opcode.cpp \
src/sfizz/Oversampler.cpp \
src/sfizz/Parser.cpp \
src/sfizz/Panning.cpp \
src/sfizz/sfizz.cpp \
src/sfizz/Region.cpp \
src/sfizz/SfzHelpers.cpp \
src/sfizz/SIMDHelpers.cpp \
src/sfizz/simd/HelpersSSE.cpp \
src/sfizz/simd/HelpersAVX.cpp \

View file

@ -128,7 +128,6 @@ set(SFIZZ_SOURCES
sfizz/Voice.cpp
sfizz/ScopedFTZ.cpp
sfizz/MidiState.cpp
sfizz/SfzHelpers.cpp
sfizz/Oversampler.cpp
sfizz/ADSREnvelope.cpp
sfizz/Logger.cpp
@ -193,7 +192,6 @@ set(SFIZZ_PARSER_HEADERS
sfizz/Range.h
sfizz/Opcode.h
sfizz/Macros.h
sfizz/Parser.h
sfizz/parser/Parser.h
sfizz/parser/ParserPrivate.h
sfizz/parser/ParserPrivate.hpp
@ -201,10 +199,8 @@ set(SFIZZ_PARSER_HEADERS
sfizz/StringViewHelpers.h)
set(SFIZZ_PARSER_SOURCES
sfizz/Parser.cpp
sfizz/Opcode.cpp
sfizz/OpcodeCleanup.cpp
sfizz/SfzHelpers.cpp
sfizz/parser/Parser.cpp
sfizz/parser/ParserPrivate.cpp)

View file

@ -1,132 +0,0 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "Parser.h"
#include "StringViewHelpers.h"
#include "SfzHelpers.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_cat.h"
#include <algorithm>
#include <fstream>
void removeCommentOnLine(absl::string_view& line)
{
auto position = line.find("//");
if (position != line.npos)
line.remove_suffix(line.size() - position);
}
bool sfz::OldParser::loadSfzFile(const fs::path& file)
{
includedFiles.clear();
const auto sfzFile =
(file.empty() || file.is_absolute()) ? file : originalDirectory / file;
if (!fs::exists(sfzFile))
return false;
originalDirectory = sfzFile.parent_path();
includedFiles.push_back(sfzFile);
std::vector<std::string> lines;
readSfzFile(sfzFile, lines);
aggregatedContent = absl::StrJoin(lines, " ");
absl::string_view aggregatedView { aggregatedContent };
absl::string_view header;
absl::string_view members;
std::vector<Opcode> currentMembers;
while (findHeader(aggregatedView, header, members)) {
absl::string_view opcode;
absl::string_view value;
// Store or handle members
while(findOpcode(members, opcode, value))
currentMembers.emplace_back(opcode, value);
callback(header, currentMembers);
currentMembers.clear();
}
return true;
}
void sfz::OldParser::readSfzFile(const fs::path& fileName, std::vector<std::string>& lines) noexcept
{
std::ifstream fileStream(fileName.c_str());
if (!fileStream)
return;
std::string tmpString;
std::string includePath;
absl::string_view variable;
absl::string_view value;
while (std::getline(fileStream, tmpString)) {
absl::string_view tmpView { tmpString };
removeCommentOnLine(tmpView);
trimInPlace(tmpView);
if (tmpView.empty())
continue;
// New #include
if (findInclude(tmpView, includePath)) {
std::replace(includePath.begin(), includePath.end(), '\\', '/');
const auto newFile = originalDirectory / includePath;
auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile);
if (fs::exists(newFile)) {
if (alreadyIncluded == includedFiles.end()) {
includedFiles.push_back(newFile);
readSfzFile(newFile, lines);
} else if (!recursiveIncludeGuard) {
readSfzFile(newFile, lines);
}
}
continue;
}
// New #define
if (findDefine(tmpView, variable, value)) {
defines[std::string(variable)] = std::string(value);
continue;
}
// Replace defined variables starting with $
std::string newString;
newString.reserve(tmpView.length());
std::string::size_type lastPos = 0;
std::string::size_type findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
while (findPos < tmpView.npos) {
absl::StrAppend(&newString, tmpView.substr(lastPos, findPos - lastPos));
const auto defineEnd = tmpView.find_first_of("= \r\t\n\f\v", findPos);
const auto candidate = tmpView.substr(findPos, defineEnd - findPos);
for (auto& definePair : defines) {
if (candidate == definePair.first) {
absl::StrAppend(&newString, definePair.second);
lastPos = findPos + definePair.first.length();
break;
}
}
if (lastPos <= findPos) {
newString += sfz::config::defineCharacter;
lastPos = findPos + 1;
}
findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
}
// Copy the rest of the string
absl::StrAppend(&newString, tmpView.substr(lastPos));
lines.push_back(std::move(newString));
}
}

View file

@ -1,36 +0,0 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
#include "Config.h"
#include "Opcode.h"
#include "ghc/fs_std.hpp"
#include <map>
#include <string>
#include "absl/strings/string_view.h"
#include <vector>
namespace sfz {
class OldParser {
public:
virtual ~OldParser() = default;
virtual bool loadSfzFile(const fs::path& file);
const std::map<std::string, std::string>& getDefines() const noexcept { return defines; }
const std::vector<fs::path>& getIncludedFiles() const noexcept { return includedFiles; }
void disableRecursiveIncludeGuard() { recursiveIncludeGuard = false; }
void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; }
protected:
virtual void callback(absl::string_view header, const std::vector<Opcode>& members) = 0;
fs::path originalDirectory { fs::current_path() };
private:
bool recursiveIncludeGuard { false };
std::map<std::string, std::string> defines;
std::vector<fs::path> includedFiles;
std::string aggregatedContent {};
void readSfzFile(const fs::path& fileName, std::vector<std::string>& lines) noexcept;
};
} // namespace sfz

View file

@ -1,106 +0,0 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "SfzHelpers.h"
#include "StringViewHelpers.h"
namespace sfz {
bool findHeader(absl::string_view& source, absl::string_view& header, absl::string_view& members)
{
auto openHeader = source.find("<");
if (openHeader == absl::string_view::npos)
return false;
auto closeHeader = source.find(">", openHeader);
if (openHeader == absl::string_view::npos)
return false;
auto nextHeader = source.find("<", closeHeader);
header = source.substr(openHeader + 1, closeHeader - openHeader - 1);
if (nextHeader == absl::string_view::npos) {
members = trim(source.substr(closeHeader + 1));
source.remove_prefix(source.length());
} else {
members = trim(source.substr(closeHeader + 1, nextHeader - closeHeader - 1));
source.remove_prefix(nextHeader);
}
return true;
}
bool findOpcode(absl::string_view& source, absl::string_view& opcode, absl::string_view& value)
{
auto opcodeEnd = source.find("=");
if (opcodeEnd == absl::string_view::npos)
return false;
const auto valueStart = opcodeEnd + 1;
const auto nextOpcodeEnd = source.find("=", valueStart);
if (nextOpcodeEnd == absl::string_view::npos) {
opcode = source.substr(0, opcodeEnd);
value = source.substr(valueStart);
source.remove_prefix(source.length());
return true;
}
auto valueEnd = nextOpcodeEnd;
while (source[valueEnd] != ' ' && valueEnd != valueStart)
valueEnd--;
opcode = source.substr(0, opcodeEnd);
value = source.substr(valueStart, valueEnd - valueStart);
source.remove_prefix(valueEnd);
return true;
}
bool findDefine(absl::string_view line, absl::string_view& variable, absl::string_view& value)
{
const auto defPosition = line.find("#define");
if (defPosition == absl::string_view::npos)
return false;
const auto variableStart = line.find("$", 7);
if (variableStart == absl::string_view::npos)
return false;
const auto variableEnd = line.find_first_of(" \r\t\n\f\v", variableStart);
if (variableEnd == absl::string_view::npos)
return false;
const auto valueStart = line.find_first_not_of(" \r\t\n\f\v", variableEnd);
if (valueStart == absl::string_view::npos)
return false;
const auto valueEnd = line.find_first_of(" \r\t\n\f\v", valueStart);
variable = line.substr(variableStart, variableEnd - variableStart);
value = valueEnd != absl::string_view::npos
? line.substr(valueStart, valueEnd - valueStart)
: line.substr(valueStart);
return true;
}
bool findInclude(absl::string_view line, std::string& path)
{
const auto defPosition = line.find("#include");
if (defPosition == absl::string_view::npos)
return false;
const auto pathStart = line.find("\"", 8);
if (pathStart == absl::string_view::npos)
return false;
const auto pathEnd = line.find("\"", pathStart + 1);
if (pathEnd == absl::string_view::npos)
return false;
path = std::string(line.substr(pathStart + 1, pathEnd - pathStart - 1));
return true;
}
}

View file

@ -250,66 +250,4 @@ bool insertPairUniquely(std::vector<P>& pairVector, const T& key, U value, bool
return result;
}
/**
* @brief From a source view, find the next sfz header and its members and
* return them, while updating the source by removing this header
* and members from the beginning. The function "consumes" the
* header and its members from the source if found.
*
* No check is made to see if the header is "valid" in the sfz sense.
* The output parameters are set only if the method returns true.
*
* @param source A source view; can be updated and shortened
* @param header An output view on the header, without the <>
* @param members An output view on the members, untrimmed
* @return true if a header was found
* @return false otherwise
*/
bool findHeader(absl::string_view& source, absl::string_view& header, absl::string_view& members);
/**
* @brief From a source view, find the next sfz member opcode and its value.
* Return them while updating the source by removing this opcode
* and value from the beginning. The function "consumes" the
* opcode from the source if one is found.
*
* No check is made to see if the opcode is "valid" in the sfz sense.
* The output parameters are set only if the method returns true.
*
* @param source A source view; can be updated and shortened
* @param opcode An output view on the opcode name
* @param value An output view on the opcode value
* @return true if an opcode was found
* @return false
*/
bool findOpcode(absl::string_view& source, absl::string_view& opcode, absl::string_view& value);
/**
* @brief Find an SFZ #define statement on a line and return the variable and value as views.
*
* This function assums that there is a single define per line and that the variable and value
* are separated by whitespace.
* The output parameters are set only if the method returns true.
*
* @param line The source line
* @param variable An output view on the define variable
* @param value An output view on the define value
* @return true If a define was found
* @return false
*/
bool findDefine(absl::string_view line, absl::string_view& variable, absl::string_view& value);
/**
* @brief Find an SFZ #include statement on a line and return included path.
*
* This function assums that there is a single include per line and that the
* include path is within quotes.
* The output parameter is set only if the method returns true.
*
* @param line The source line
* @param path The path, if found
* @return true If an include was found
* @return false
*/
bool findInclude(absl::string_view line, std::string& path);
} // namespace sfz

View file

@ -11,126 +11,6 @@
#include "absl/strings/string_view.h"
using namespace Catch::literals;
void includeTest(const std::string& line, const std::string& fileName)
{
std::string parsedPath;
auto found = sfz::findInclude(line, parsedPath);
if (!found)
std::cerr << "Include test failed: " << line << '\n';
REQUIRE(found);
REQUIRE(parsedPath == fileName);
}
TEST_CASE("[Parsing] #include")
{
includeTest("#include \"file.sfz\"", "file.sfz");
includeTest("#include \"../Programs/file.sfz\"", "../Programs/file.sfz");
includeTest("#include \"..\\Programs\\file.sfz\"", "..\\Programs\\file.sfz");
includeTest("#include \"file-1.sfz\"", "file-1.sfz");
includeTest("#include \"file~1.sfz\"", "file~1.sfz");
includeTest("#include \"file_1.sfz\"", "file_1.sfz");
includeTest("#include \"file$1.sfz\"", "file$1.sfz");
includeTest("#include \"file,1.sfz\"", "file,1.sfz");
includeTest("#include \"rubbishCharactersAfter.sfz\" blabldaljf///df", "rubbishCharactersAfter.sfz");
includeTest("#include \"lazyMatching.sfz\" b\"", "lazyMatching.sfz");
}
void defineTest(const std::string& line, const std::string& variable, const std::string& value)
{
absl::string_view variableMatch;
absl::string_view valueMatch;
auto found = sfz::findDefine(line, variableMatch, valueMatch);
REQUIRE(found);
REQUIRE(variableMatch == variable);
REQUIRE(valueMatch == value);
}
void defineFail(const std::string& line)
{
absl::string_view variableMatch;
absl::string_view valueMatch;
auto found = sfz::findDefine(line, variableMatch, valueMatch);
REQUIRE(!found);
}
TEST_CASE("[Parsing] #define")
{
defineTest("#define $number 1", "$number", "1");
defineTest("#define $letters QWERasdf", "$letters", "QWERasdf");
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$");
}
TEST_CASE("[Parsing] Header")
{
SECTION("Basic header match")
{
absl::string_view header;
absl::string_view members;
absl::string_view line { "<header>param1=value1 param2=value2<next>" };
auto found = sfz::findHeader(line, header, members);
REQUIRE(found);
REQUIRE(header == "header");
REQUIRE(members == "param1=value1 param2=value2");
REQUIRE(line == "<next>");
}
SECTION("EOL header match")
{
absl::string_view header;
absl::string_view members;
absl::string_view line { "<header>param1=value1 param2=value2" };
auto found = sfz::findHeader(line, header, members);
REQUIRE(found);
REQUIRE(header == "header");
REQUIRE(members == "param1=value1 param2=value2");
REQUIRE(line == "");
}
}
void memberTest(const std::string& line, const std::string& opcode, const std::string& value)
{
absl::string_view opcodeMatched;
absl::string_view valueMatched;
absl::string_view lineView { line };
auto found = sfz::findOpcode(lineView, opcodeMatched, valueMatched);
REQUIRE(found);
REQUIRE(opcodeMatched == opcode);
REQUIRE(valueMatched == value);
}
TEST_CASE("[Parsing] Member")
{
memberTest("param=value", "param", "value");
memberTest("param=113", "param", "113");
memberTest("param1=value", "param1", "value");
memberTest("param_1=value", "param_1", "value");
memberTest("param_1=value", "param_1", "value");
memberTest("ampeg_sustain_oncc74=-100", "ampeg_sustain_oncc74", "-100");
memberTest("lorand=0.750", "lorand", "0.750");
memberTest("sample=value", "sample", "value");
memberTest("sample=value-()*", "sample", "value-()*");
memberTest("sample=../sample.wav", "sample", "../sample.wav");
memberTest("sample=..\\sample.wav", "sample", "..\\sample.wav");
memberTest("sample=subdir\\subdir\\sample.wav", "sample", "subdir\\subdir\\sample.wav");
memberTest("sample=subdir/subdir/sample.wav", "sample", "subdir/subdir/sample.wav");
memberTest("sample=subdir_underscore\\sample.wav", "sample", "subdir_underscore\\sample.wav");
memberTest("sample=subdir space\\sample.wav", "sample", "subdir space\\sample.wav");
memberTest("sample=subdir space\\sample.wav next_member=value", "sample", "subdir space\\sample.wav");
memberTest("sample=..\\Samples\\pizz\\a0_vl3_rr3.wav", "sample", "..\\Samples\\pizz\\a0_vl3_rr3.wav");
memberTest("sample=..\\Samples\\SMD Cymbals Stereo (Samples)\\Hi-Hat (Samples)\\01 Hat Tight 1\\RR1\\09_Hat_Tight_Cnt_RR1.wav", "sample", "..\\Samples\\SMD Cymbals Stereo (Samples)\\Hi-Hat (Samples)\\01 Hat Tight 1\\RR1\\09_Hat_Tight_Cnt_RR1.wav");
memberTest("sample=..\\G&S CW-Drum Kit-1\\SnareFX\\SNR-OFF-V08-CustomWorks-6x13.wav", "sample", "..\\G&S CW-Drum Kit-1\\SnareFX\\SNR-OFF-V08-CustomWorks-6x13.wav");
}
// New parser
struct ParsingMocker: sfz::Parser::Listener
{
void onParseBegin() override