- added fullscreen/window switch to F11 (gnome-like)
[supertux.git] / src / lisp / parser.cpp
index dbed7ac..526d57a 100644 (file)
@@ -60,7 +60,10 @@ static std::string dirname(std::string filename)
 Lisp*
 Parser::parse(const std::string& filename)
 {
-  IFileStream in(filename);
+  IFileStreambuf ins(filename);
+  std::istream in(&ins);
+
+  this->filename = filename;
   if(!in.good()) {
     std::stringstream msg;
     msg << "Parser problem: Couldn't open file '" << filename << "'.";
@@ -71,7 +74,7 @@ Parser::parse(const std::string& filename)
     dictionary_manager->add_directory(dirname(filename));
     dictionary = & (dictionary_manager->get_dictionary());
   }
-  
+
   return parse(in);
 }
 
@@ -85,11 +88,20 @@ Parser::parse(std::istream& stream)
   Lisp* result = new Lisp(Lisp::TYPE_CONS);
   result->v.cons.car = read();
   result->v.cons.cdr = 0;
-  
+
   delete lexer;
   lexer = 0;
 
-  return result;    
+  return result;
+}
+
+void
+Parser::parse_error(const char* msg)
+{
+  std::stringstream emsg;
+  emsg << "Parse Error at '" << filename << "' line " << lexer->getLineNumber()
+         << ": " << msg;
+  throw std::runtime_error(emsg.str());
 }
 
 Lisp*
@@ -98,20 +110,14 @@ Parser::read()
   Lisp* result;
   switch(token) {
     case Lexer::TOKEN_EOF: {
-      std::stringstream msg;
-      msg << "Parse Error at line " << lexer->getLineNumber() << ": "
-        << "Unexpected EOF.";
-      throw std::runtime_error(msg.str());
+         parse_error("Unexpected EOF.");
     }
     case Lexer::TOKEN_CLOSE_PAREN: {
-      std::stringstream msg;
-      msg << "Parse Error at line " << lexer->getLineNumber() << ": "
-        << "Unexpected ')'.";
-      throw std::runtime_error(msg.str());
+      parse_error("Unexpected ')'.");
     }
     case Lexer::TOKEN_OPEN_PAREN: {
       result = new Lisp(Lisp::TYPE_CONS);
-      
+
       token = lexer->getNextToken();
       if(token == Lexer::TOKEN_CLOSE_PAREN) {
         result->v.cons.car = 0;
@@ -124,21 +130,21 @@ Parser::read()
         // evaluate translation function (_ str) in place here
         token = lexer->getNextToken();
         if(token != Lexer::TOKEN_STRING)
-          throw std::runtime_error("Expected string after '(_'");
-        
+                 parse_error("Expected string after '(_'");
+
         result = new Lisp(Lisp::TYPE_STRING);
         if(dictionary) {
           std::string translation = dictionary->translate(lexer->getString());
           result->v.string = new char[translation.size()+1];
           memcpy(result->v.string, translation.c_str(), translation.size()+1);
         } else {
-          size_t len = strlen(lexer->getString()) + 1;                                
+          size_t len = strlen(lexer->getString()) + 1;
           result->v.string = new char[len];
           memcpy(result->v.string, lexer->getString(), len);
         }
         token = lexer->getNextToken();
         if(token != Lexer::TOKEN_CLOSE_PAREN)
-          throw std::runtime_error("Expected ')' after '(_ string'");
+                 parse_error("Expected ')' after '(_ string'");
         break;
       }