Tatooine
shaderstageparser.h
Go to the documentation of this file.
1#ifndef TATOOINE_GL_SHADERSTAGEPARSER_H
2#define TATOOINE_GL_SHADERSTAGEPARSER_H
3//==============================================================================
4#include <exception>
5#include <fstream>
6#include <iostream>
7#include <optional>
8#include <regex>
9
11#include <tatooine/gl/glslvar.h>
14//==============================================================================
15namespace tatooine::gl {
16//==============================================================================
18 private:
19 static std::regex const regex_var;
20 static std::regex const regex_include;
21 public:
22 //------------------------------------------------------------------------------
23 DLL_API static auto parse(std::filesystem::path const& path,
24 std::vector<GLSLVar>& vars, include_tree& it)
25 -> shadersource;
26 DLL_API static auto parse(shadersource const& source,
27 std::vector<GLSLVar>& vars, include_tree& it)
28 -> shadersource;
29 DLL_API static auto parse_varname(std::string const& line)
30 -> std::optional<GLSLVar>;
31 DLL_API static auto parse_include(std::string const& line)
32 -> std::optional<std::string>;
33
34 private:
35 template <typename Stream>
36 static auto parse_stream(Stream& stream, std::vector<GLSLVar>& vars,
37 include_tree& it, std::string const& folder = "")
38 -> shadersource {
39 std::string line;
40 shadersource content;
41
42 auto line_number = std::size_t{};
43
44 while (std::getline(stream, line)) {
45 if (auto parsed_var = parse_varname(line); parsed_var)
46 vars.push_back(parsed_var.value());
47
48 if (auto parsed_include = parse_include(line); parsed_include) {
49 it.nested_include_trees().emplace_back(line_number, 0,
50 parsed_include.value(), it);
51 content.string() += parse(folder + parsed_include.value(), vars,
52 it.nested_include_trees().back()).string();
53 } else
54 content.string() += line + '\n';
55
56 ++line_number;
57 }
58 it.num_lines() = line_number;
59
60 return content;
61 }
62};
63//==============================================================================
64} // namespace tatooine::gl
65//==============================================================================
66#endif
Definition: shaderstageparser.h:17
static DLL_API auto parse(shadersource const &source, std::vector< GLSLVar > &vars, include_tree &it) -> shadersource
static DLL_API auto parse(std::filesystem::path const &path, std::vector< GLSLVar > &vars, include_tree &it) -> shadersource
static std::regex const regex_var
Definition: shaderstageparser.h:19
static DLL_API auto parse_include(std::string const &line) -> std::optional< std::string >
static DLL_API auto parse_varname(std::string const &line) -> std::optional< GLSLVar >
static auto parse_stream(Stream &stream, std::vector< GLSLVar > &vars, include_tree &it, std::string const &folder="") -> shadersource
Definition: shaderstageparser.h:36
static std::regex const regex_include
Definition: shaderstageparser.h:20
Definition: ansiformat.h:6
Definition: includetree.h:11
Definition: shadersource.h:8
auto string() const -> auto const &
Definition: shadersource.h:26
Definition: line.h:35