8128b13d7e6690c59ee48d6ddf74edc991341d1d
[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
20 #ifndef __LISPLEXER_H__
21 #define __LISPLEXER_H__
22
23 namespace lisp
24 {
25
26 class Lexer
27 {
28 public:
29   enum TokenType {
30     TOKEN_EOF,
31     TOKEN_OPEN_PAREN,
32     TOKEN_CLOSE_PAREN,
33     TOKEN_SYMBOL,
34     TOKEN_STRING,
35     TOKEN_INTEGER,
36     TOKEN_REAL,
37     TOKEN_TRUE,
38     TOKEN_FALSE
39   };
40     
41   Lexer(std::istream& stream);
42   ~Lexer();
43
44   TokenType getNextToken();
45   const char* getString() const
46   { return token_string; }
47   int getLineNumber() const
48   { return linenumber; }
49     
50 private:
51   enum {
52     MAX_TOKEN_LENGTH = 16384,
53     BUFFER_SIZE = 1024
54   };
55     
56   inline void nextChar();
57     
58   std::istream& stream;
59   bool eof;
60   int linenumber;
61   char buffer[BUFFER_SIZE+1];
62   char* bufend;
63   char* c;
64   char token_string[MAX_TOKEN_LENGTH + 1];
65   int token_length;
66 };
67
68 } // end of namespace lisp
69
70 #endif
71