sfizz/sfizz/Parser.h

52 lines
2.3 KiB
C
Raw Normal View History

2019-08-30 00:49:58 +02:00
// Copyright (c) 2019, Paul Ferrand
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2019-07-29 02:13:03 +02:00
#pragma once
#include "Opcode.h"
2019-09-19 02:29:43 +02:00
#include "compat/filesystem.h"
2019-07-29 02:13:03 +02:00
#include <map>
#include <string>
2019-09-21 01:06:47 +02:00
#include "absl/strings/string_view.h"
2019-08-25 14:01:03 +02:00
#include <vector>
2019-07-29 02:13:03 +02:00
2019-08-25 14:01:03 +02:00
namespace sfz {
class Parser {
2019-07-29 02:13:03 +02:00
public:
2019-09-21 13:01:50 +02:00
virtual bool loadSfzFile(const fs::path& file);
2019-07-29 02:13:03 +02:00
const std::map<std::string, std::string>& getDefines() const noexcept { return defines; }
2019-09-21 13:01:50 +02:00
const std::vector<fs::path>& getIncludedFiles() const noexcept { return includedFiles; }
void disableRecursiveIncludeGuard() { recursiveIncludeGuard = false; }
void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; }
2019-07-29 02:13:03 +02:00
protected:
virtual void callback(absl::string_view header, const std::vector<Opcode>& members) = 0;
2019-09-21 13:01:50 +02:00
fs::path rootDirectory { fs::current_path() };
2019-07-29 02:13:03 +02:00
private:
bool recursiveIncludeGuard { false };
2019-07-29 02:13:03 +02:00
std::map<std::string, std::string> defines;
2019-09-21 13:01:50 +02:00
std::vector<fs::path> includedFiles;
2019-08-25 14:01:03 +02:00
std::string aggregatedContent {};
2019-09-21 13:01:50 +02:00
void readSfzFile(const fs::path& fileName, std::vector<std::string>& lines) noexcept;
2019-07-29 02:13:03 +02:00
};
} // namespace sfz