X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Ftokenizer.h;fp=source%2Fglsl%2Ftokenizer.h;h=a7329182df53fcf5c8d7fd0cc844eb206c4f408f;hb=d3ceb2186dc79130508093b3d0c944771a53534f;hp=0000000000000000000000000000000000000000;hpb=47286086863b6009192ffdb3d3471c83211ee943;p=libs%2Fgl.git diff --git a/source/glsl/tokenizer.h b/source/glsl/tokenizer.h new file mode 100644 index 00000000..a7329182 --- /dev/null +++ b/source/glsl/tokenizer.h @@ -0,0 +1,54 @@ +#ifndef MSP_GL_SL_TOKENIZER_H_ +#define MSP_GL_SL_TOKENIZER_H_ + +#include +#include +#include + +namespace Msp { +namespace GL { +namespace SL { + +class Preprocessor; + +struct Location +{ + std::string name; + unsigned line; +}; + +class Tokenizer +{ +public: + sigc::signal signal_preprocess; + +private: + std::string::const_iterator iter; + std::string::const_iterator source_end; + Location location; + bool allow_preprocess; + std::string last_token; + std::deque next_tokens; + +public: + Tokenizer(); + + void begin(const std::string &, const std::string &); + const std::string &peek_token(unsigned = 0); + const std::string &parse_token(); + void expect(const std::string &); + const Location &get_location() const { return location; } +private: + std::string parse_token_(); + void preprocess(); + std::string parse_identifier(); + std::string parse_number(); + std::string parse_other(); + void skip_comment_and_whitespace(); +}; + +} // namespace SL +} // namespace GL +} // namespace Msp + +#endif