#pragma once #ifndef LEXER_AttributeLexer_H #define LEXER_AttributeLexer_H #include #include #include class AttributeLexer { public: class NoMoreTokens : public std::exception {}; class NoMatch : public std::exception {}; enum TokenType { nonmatching, ATTRIBUTE, ATTRIBUTE_CONTENT_DOUBLE_QUOTES, ATTRIBUTE_CONTENT_SINGLE_QUOTES, BRACKET, ELEMENT, WHITESPACE, ignore, }; struct Token { TokenType type; std::string content; }; AttributeLexer(std::istream& in); ~AttributeLexer(); /** * Get the next token * * @throws NoMoreTokens if no more tokens are available * @throws NoMatch if no match was found */ Token nextToken(); /** * Skip the following `n` bytes. * * @param n The number of bytes to skip */ void skip(std::size_t n); /** * Peek at the current head of the input stream, useful in error reporting when a character mismatches for example * * @throws NoMoreTokens if the input stream is at an end */ char peek(); /** * Get the current byte offset */ std::size_t getByteOffset(); private: std::size_t m_offset; std::istream& m_input; }; #endif //LEXER_AttributeLexer_H