Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / lisp / parser.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_PARSER_HPP
18 #define HEADER_SUPERTUX_LISP_PARSER_HPP
19
20 #include "lisp/lexer.hpp"
21 #include "obstack/obstack.h"
22
23 namespace TinyGetText {
24 class Dictionary;
25 class DictionaryManager;
26 }
27
28 namespace lisp {
29
30 class Lisp;
31 class LispFile;
32
33 class Parser
34 {
35 public:
36   Parser(bool translate = true);
37   ~Parser();
38
39   /**
40    * Parses a lispfile and returns the s-expression structure.
41    * Note that all memory is held by the parser so don't destroy the parser
42    * before you are finished with the lisp tree
43    */
44   const Lisp* parse(const std::string& filename);
45   /**
46    * Same as parse but reads from a generic std::istream. The sourcename is
47    * used for errormessages to indicate the source of the data.
48    */
49   const Lisp* parse(std::istream& stream, const std::string& sourcename);
50
51 private:
52   void parse_error(const char* msg) const __attribute__((__noreturn__));
53   const Lisp* read();
54
55   Lexer* lexer;
56   std::string filename;
57   TinyGetText::DictionaryManager* dictionary_manager;
58   TinyGetText::Dictionary* dictionary;
59   Lexer::TokenType token;
60
61   struct obstack obst;
62
63 private:
64   Parser(const Parser&);
65   Parser & operator=(const Parser&);
66 };
67
68 } // end of namespace lisp
69
70 #endif
71
72 /* EOF */