X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fparser.h;fp=source%2Fglsl%2Fparser.h;h=c9588bfbdd99486a0e759df55ebd7c520ebeefb0;hb=c1b0303f65ee966a973197cbdbf177c571478674;hp=0000000000000000000000000000000000000000;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/glsl/parser.h b/source/glsl/parser.h new file mode 100644 index 00000000..c9588bfb --- /dev/null +++ b/source/glsl/parser.h @@ -0,0 +1,120 @@ +#ifndef MSP_GL_SL_PARSER_H_ +#define MSP_GL_SL_PARSER_H_ + +#include +#include +#include +#include +#include +#include "syntax.h" + +namespace Msp { +namespace GL { +namespace SL { + +class Parser +{ +private: + enum OperatorType + { + NO_OPERATOR, + BINARY, + PREFIX, + POSTFIX + }; + + enum Associativity + { + LEFT_TO_RIGHT, + RIGHT_TO_LEFT + }; + + struct Operator + { + const char token[4]; + unsigned precedence; + OperatorType type; + Associativity assoc; + }; + + std::string source; + std::string source_name; + unsigned source_index; + unsigned current_line; + std::string::const_iterator iter; + std::string::const_iterator source_end; + bool allow_preprocess; + bool allow_stage_change; + std::string last_token; + std::deque next_tokens; + Module *module; + Stage *cur_stage; + std::set declared_types; + + static Operator operators[]; + +public: + Parser(); + ~Parser(); + + Module &parse(const std::string &, const std::string &, unsigned = 0); + Module &parse(IO::Base &, const std::string &, unsigned = 0); + +private: + void parse_source(); + + std::string format_error(const std::string &); + std::string format_syntax_error(const std::string &); + + const std::string &peek_token(unsigned = 0); + const std::string &parse_token(); + std::string parse_token_(); + std::string parse_identifier(); + std::string parse_number(); + std::string parse_other(); + void skip_comment_and_whitespace(); + void expect(const std::string &); + std::string expect_type(); + std::string expect_identifier(); + bool check(const std::string &); + + static bool is_interface_qualifier(const std::string &); + static bool is_sampling_qualifier(const std::string &); + static bool is_interpolation_qualifier(const std::string &); + static bool is_precision_qualifier(const std::string &); + static bool is_qualifier(const std::string &); + static bool is_builtin_type(const std::string &); + bool is_type(const std::string &); + bool is_identifier(const std::string &); + + void preprocess(); + void preprocess_version(); + void preprocess_pragma(); + void preprocess_pragma_msp(); + void preprocess_stage(); + + RefPtr parse_global_declaration(); + RefPtr parse_statement(); + RefPtr parse_import(); + RefPtr parse_precision(); + RefPtr parse_layout(); + void parse_block(Block &, bool); + RefPtr parse_expression(unsigned = 0); + RefPtr parse_binary(const RefPtr &, const Operator *); + RefPtr parse_function_call(const VariableReference &); + RefPtr parse_struct_declaration(); + RefPtr parse_variable_declaration(); + RefPtr parse_function_declaration(); + RefPtr parse_interface_block(); + RefPtr parse_conditional(); + RefPtr parse_for(); + RefPtr parse_while(); + RefPtr parse_passthrough(); + RefPtr parse_return(); +}; + +} // namespace SL +} // namespace GL +} // namespace Msp + +#endif