Updated addon repository URL and improved debug output on download
[supertux.git] / src / lisp / lexer.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_LISP_LEXER_HPP
18 #define HEADER_SUPERTUX_LISP_LEXER_HPP
19
20 #include <istream>
21
22 namespace lisp {
23
24 class Lexer
25 {
26 public:
27   enum TokenType {
28     TOKEN_EOF,
29     TOKEN_OPEN_PAREN,
30     TOKEN_CLOSE_PAREN,
31     TOKEN_SYMBOL,
32     TOKEN_STRING,
33     TOKEN_INTEGER,
34     TOKEN_REAL,
35     TOKEN_TRUE,
36     TOKEN_FALSE
37   };
38
39   Lexer(std::istream& stream);
40   ~Lexer();
41
42   TokenType getNextToken();
43   const char* getString() const
44   { return token_string; }
45   int getLineNumber() const
46   { return linenumber; }
47
48 private:
49   enum {
50     MAX_TOKEN_LENGTH = 16384,
51     BUFFER_SIZE = 1024
52   };
53
54   inline void nextChar();
55   inline void addChar();
56
57 private:
58   std::istream& stream;
59   bool eof;
60   int linenumber;
61   char buffer[BUFFER_SIZE+1];
62   char* bufend;
63   char* bufpos;
64   int  c;
65   char token_string[MAX_TOKEN_LENGTH + 1];
66   int token_length;
67
68 private:
69   Lexer(const Lexer&);
70   Lexer & operator=(const Lexer&);
71 };
72
73 } // end of namespace lisp
74
75 #endif
76
77 /* EOF */