]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/parser.h
Split tokenizer and preprocessor out of the GLSL parser
[libs/gl.git] / source / glsl / parser.h
index 743149d83362a84be8b91e5b13dad8789e90bede..6e4bb38b11dd436e4d289681abcf36f3a2687599 100644 (file)
@@ -1,63 +1,30 @@
 #ifndef MSP_GL_SL_PARSER_H_
 #define MSP_GL_SL_PARSER_H_
 
-#include <deque>
-#include <map>
 #include <set>
 #include <string>
 #include <msp/io/base.h>
+#include "preprocessor.h"
 #include "syntax.h"
+#include "tokenizer.h"
 
 namespace Msp {
 namespace GL {
 namespace SL {
 
-struct Location
-{
-       std::string name;
-       unsigned line;
-};
-
 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;
-       Location location;
-       std::string::const_iterator iter;
-       std::string::const_iterator source_end;
-       bool allow_preprocess;
+       Tokenizer tokenizer;
+       Preprocessor preprocessor;
        bool allow_stage_change;
-       std::string last_token;
-       std::deque<std::string> next_tokens;
        Module *module;
        Stage *cur_stage;
        std::set<std::string> declared_types;
 
-       static Operator operators[];
-
 public:
        Parser();
        ~Parser();
@@ -66,16 +33,10 @@ public:
        Module &parse(IO::Base &, const std::string &, unsigned = 0);
 
 private:
-       void parse_source();
+       void parse_source(const std::string &);
+       void set_required_version(const Version &);
+       void stage_change(StageType);
 
-       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 &);