Add a few helper functions

This commit is contained in:
Jérôme Leclercq
2021-05-14 02:09:25 +02:00
parent f280cff0a2
commit 830ec6ac94
5 changed files with 36 additions and 0 deletions

View File

@@ -1006,5 +1006,25 @@ namespace Nz::ShaderLang
case TokenType::Dot: return 50;
default: return -1;
}
}
ShaderAst::StatementPtr Parse(const std::filesystem::path& sourcePath)
{
File file(sourcePath);
if (!file.Open(OpenMode_ReadOnly | OpenMode_Text))
{
NazaraError("Failed to open \"" + sourcePath.generic_u8string() + '"');
return {};
}
std::size_t length = static_cast<std::size_t>(file.GetSize());
std::vector<Nz::UInt8> source(length);
if (file.Read(&source[0], length) != length)
{
NazaraError("Failed to read program file");
return {};
}
return Parse(Tokenize(std::string_view(reinterpret_cast<const char*>(source.data()), source.size())));
}