/* -*- C++ -*- * Copyright ©2004 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #ifndef CONFIGLEXER_H #define CONFIGLEXER_H #include #include #include class UnexpectedEOF { }; typedef enum { UNINITIALISED, END, FLOAT, INTEGER, TOKEN, STRING, CHAR } LexType; typedef std::pair Token; class ConfigLexer { public: ConfigLexer(std::istream* is) : input(is), currentvalue(Token(UNINITIALISED, "")), parsestate(WS), line(1) { } virtual ~ConfigLexer() { } ConfigLexer& operator++(void); ConfigLexer* next(void); // Move to the next token bool eos(void); // Move to next token. Return // false if current token is the // end of section. ConfigLexer* section_next(void); // Move to the beginning of the // next section ConfigLexer* directive_next(void); // Move to the beginning of the // next directive const LexType& type(void) const { // std::cerr << "Type=" << currentvalue.first << std::endl; return currentvalue.first; } const std::string& value(void) const { // std::cerr << "Value=" << currentvalue.second << std::endl; return currentvalue.second; } int lineno(void) const { return line; } private: std::istream* input; Token currentvalue; int line; enum { WS, TEXT, NUMBER, DECIMAL, QUOTEDSTRING, PERLCOMMENT, POSSCOMMENT, CCOMMENT, CPPCOMMENT, POSSCOMMENTEND } parsestate; }; extern ConfigLexer* lex; #endif