]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/tokenizer.h
Recognize the #line directive in 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         Location(): line(0) { }
20         Location(const std::string &n, unsigned l): name(n), line(l) { }
21 };
22
23 class Tokenizer
24 {
25 public:
26         sigc::signal<void> signal_preprocess;
27
28 private:
29         std::string::const_iterator iter;
30         std::string::const_iterator source_end;
31         Location location;
32         bool allow_preprocess;
33         bool suppress_line_advance;
34         std::string last_token;
35         std::deque<std::string> next_tokens;
36
37 public:
38         Tokenizer();
39
40         void begin(const std::string &, const std::string &);
41         const std::string &peek_token(unsigned = 0);
42         const std::string &parse_token();
43         void expect(const std::string &);
44         void set_location(const Location &);
45         const Location &get_location() const { return location; }
46 private:
47         std::string parse_token_();
48         void preprocess();
49         std::string parse_identifier();
50         std::string parse_number();
51         std::string parse_string();
52         std::string parse_other();
53         void skip_comment_and_whitespace();
54 };
55
56 } // namespace SL
57 } // namespace GL
58 } // namespace Msp
59
60 #endif