Added a way to parse from a string
This commit is contained in:
parent
51b992617d
commit
847af7b731
4 changed files with 52 additions and 1 deletions
|
|
@ -23,13 +23,18 @@ void Parser::addDefinition(absl::string_view id, absl::string_view value)
|
|||
_definitions[id] = std::string(value);
|
||||
}
|
||||
|
||||
void Parser::parseFile(const fs::path& path)
|
||||
void Parser::reset()
|
||||
{
|
||||
_pathsIncluded.clear();
|
||||
_currentHeader.reset();
|
||||
_currentOpcodes.clear();
|
||||
_errorCount = 0;
|
||||
_warningCount = 0;
|
||||
}
|
||||
|
||||
void Parser::parseFile(const fs::path& path)
|
||||
{
|
||||
reset();
|
||||
|
||||
if (_listener)
|
||||
_listener->onParseBegin();
|
||||
|
|
@ -42,6 +47,21 @@ void Parser::parseFile(const fs::path& path)
|
|||
_listener->onParseEnd();
|
||||
}
|
||||
|
||||
void Parser::parseString(absl::string_view sfzView)
|
||||
{
|
||||
reset();
|
||||
|
||||
if (_listener)
|
||||
_listener->onParseBegin();
|
||||
|
||||
_included.push_back(absl::make_unique<StringViewReader>(sfzView));
|
||||
processTopLevel();
|
||||
flushCurrentHeader();
|
||||
|
||||
if (_listener)
|
||||
_listener->onParseEnd();
|
||||
}
|
||||
|
||||
void Parser::includeNewFile(const fs::path& path)
|
||||
{
|
||||
fs::path fullPath =
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
void addDefinition(absl::string_view id, absl::string_view value);
|
||||
void parseFile(const fs::path& path);
|
||||
void parseString(absl::string_view sfzView);
|
||||
|
||||
void setRecursiveIncludeGuardEnabled(bool en) { _recursiveIncludeGuardEnabled = en; }
|
||||
void setMaximumIncludeDepth(size_t depth) { _maxIncludeDepth = depth; }
|
||||
|
|
@ -66,6 +67,7 @@ private:
|
|||
void processDirective();
|
||||
void processHeader();
|
||||
void processOpcode();
|
||||
void reset();
|
||||
|
||||
// errors and warnings
|
||||
void emitError(const SourceRange& range, const std::string& message);
|
||||
|
|
|
|||
|
|
@ -139,4 +139,18 @@ int FileReader::getNextStreamByte()
|
|||
return _fileStream.get();
|
||||
}
|
||||
|
||||
StringViewReader::StringViewReader(absl::string_view sfzView)
|
||||
: Reader({}), _sfzView(sfzView)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int StringViewReader::getNextStreamByte()
|
||||
{
|
||||
if (position < _sfzView.length())
|
||||
return _sfzView[position++];
|
||||
|
||||
return kEof;
|
||||
}
|
||||
|
||||
} // namespace sfz
|
||||
|
|
|
|||
|
|
@ -119,6 +119,21 @@ private:
|
|||
fs::ifstream _fileStream;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief String-view-based version of Reader.
|
||||
*/
|
||||
class StringViewReader : public Reader {
|
||||
public:
|
||||
explicit StringViewReader(absl::string_view sfzView);
|
||||
|
||||
protected:
|
||||
int getNextStreamByte() override;
|
||||
|
||||
private:
|
||||
absl::string_view _sfzView;
|
||||
size_t position { 0 };
|
||||
};
|
||||
|
||||
} // namespace sfz
|
||||
|
||||
#include "ParserPrivate.hpp"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue