Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[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   std::istream& stream;
58   bool eof;
59   int linenumber;
60   char buffer[BUFFER_SIZE+1];
61   char* bufend;
62   char* bufpos;
63   int  c;
64   char token_string[MAX_TOKEN_LENGTH + 1];
65   int token_length;
66
67 private:
68   Lexer(const Lexer&);
69   Lexer & operator=(const Lexer&);
70 };
71
72 } // end of namespace lisp
73
74 #endif
75
76 /* EOF */