]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/tokenizer.h
Split tokenizer and preprocessor out of the GLSL parser
[libs/gl.git] / source / glsl / tokenizer.h
1 #ifndef MSP_GL_SL_TOKENIZER_H_
2 #define MSP_GL_SL_TOKENIZER_H_
3
4 #include <deque>
5 #include <string>
6 #include <sigc++/signal.h>
7
8 namespace Msp {
9 namespace GL {
10 namespace SL {
11
12 class Preprocessor;
13
14 struct Location
15 {
16         std::string name;
17         unsigned line;
18 };
19
20 class Tokenizer
21 {
22 public:
23         sigc::signal<void> signal_preprocess;
24
25 private:
26         std::string::const_iterator iter;
27         std::string::const_iterator source_end;
28         Location location;
29         bool allow_preprocess;
30         std::string last_token;
31         std::deque<std::string> next_tokens;
32
33 public:
34         Tokenizer();
35
36         void begin(const std::string &, const std::string &);
37         const std::string &peek_token(unsigned = 0);
38         const std::string &parse_token();
39         void expect(const std::string &);
40         const Location &get_location() const { return location; }
41 private:
42         std::string parse_token_();
43         void preprocess();
44         std::string parse_identifier();
45         std::string parse_number();
46         std::string parse_other();
47         void skip_comment_and_whitespace();
48 };
49
50 } // namespace SL
51 } // namespace GL
52 } // namespace Msp
53
54 #endif