Shader: Add attribute parsing
This commit is contained in:
@@ -16,6 +16,12 @@ namespace Nz::ShaderAst
|
||||
Simple //< =
|
||||
};
|
||||
|
||||
enum class AttributeType
|
||||
{
|
||||
Entry, //< Entry point (function only) - has argument type
|
||||
Layout //< Struct layout (struct only) - has argument style
|
||||
};
|
||||
|
||||
enum class BasicType
|
||||
{
|
||||
Boolean, //< bool
|
||||
|
||||
@@ -25,6 +25,12 @@ namespace Nz::ShaderLang
|
||||
public:
|
||||
using exception::exception;
|
||||
};
|
||||
|
||||
class UnknownAttribute : public std::exception
|
||||
{
|
||||
public:
|
||||
using exception::exception;
|
||||
};
|
||||
|
||||
class UnknownType : public std::exception
|
||||
{
|
||||
@@ -49,10 +55,13 @@ namespace Nz::ShaderLang
|
||||
private:
|
||||
// Flow control
|
||||
const Token& Advance();
|
||||
void Consume(std::size_t count = 1);
|
||||
const Token& Expect(const Token& token, TokenType type);
|
||||
const Token& Expect(TokenType type);
|
||||
const Token& Peek(std::size_t advance = 0);
|
||||
|
||||
std::vector<ShaderAst::Attribute> ParseAttributes();
|
||||
|
||||
// Statements
|
||||
std::vector<ShaderAst::StatementPtr> ParseFunctionBody();
|
||||
ShaderAst::StatementPtr ParseFunctionDeclaration();
|
||||
@@ -70,6 +79,7 @@ namespace Nz::ShaderLang
|
||||
ShaderAst::ExpressionPtr ParseParenthesisExpression();
|
||||
ShaderAst::ExpressionPtr ParsePrimaryExpression();
|
||||
|
||||
ShaderAst::AttributeType ParseIdentifierAsAttributeType();
|
||||
const std::string& ParseIdentifierAsName();
|
||||
ShaderAst::ShaderExpressionType ParseIdentifierAsType();
|
||||
|
||||
@@ -77,6 +87,7 @@ namespace Nz::ShaderLang
|
||||
|
||||
struct Context
|
||||
{
|
||||
std::vector<ShaderAst::Attribute> pendingAttributes;
|
||||
std::unique_ptr<ShaderAst::MultiStatement> root;
|
||||
std::size_t tokenCount;
|
||||
std::size_t tokenIndex = 0;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/ShaderAstTypes.hpp>
|
||||
#include <Nazara/Shader/ShaderConstantValue.hpp>
|
||||
#include <Nazara/Shader/ShaderEnums.hpp>
|
||||
#include <Nazara/Shader/ShaderAstTypes.hpp>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -25,6 +25,12 @@ namespace Nz::ShaderAst
|
||||
class AstExpressionVisitor;
|
||||
class AstStatementVisitor;
|
||||
|
||||
struct Attribute
|
||||
{
|
||||
AttributeType type;
|
||||
std::string args;
|
||||
};
|
||||
|
||||
struct NAZARA_SHADER_API Node
|
||||
{
|
||||
Node() = default;
|
||||
|
||||
Reference in New Issue
Block a user