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