]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/tokenizer.h
Check the flat qualifier from the correct member
[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 = 0;
18
19         Location() = default;
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 progress_mark = false;
33         bool allow_preprocess = true;
34         bool suppress_line_advance = false;
35         std::string last_token;
36         std::deque<std::string> next_tokens;
37
38 public:
39         Tokenizer();
40
41         void begin(const std::string &, const std::string &);
42         const std::string &peek_token(unsigned = 0);
43         const std::string &parse_token();
44         const std::string &get_last_token() const { return last_token; }
45         void expect(const std::string &);
46         void set_location(const Location &);
47         void clear_progress_mark() { progress_mark = false; }
48         bool get_progress_mark() const { return progress_mark; }
49         const Location &get_location() const { return location; }
50 private:
51         std::string parse_token_();
52         void preprocess();
53         std::string parse_identifier();
54         std::string parse_number();
55         std::string parse_string();
56         std::string parse_other();
57         void skip_comment_and_whitespace();
58 };
59
60 } // namespace SL
61 } // namespace GL
62 } // namespace Msp
63
64 #endif