Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / lisp / lexer.cpp
index 451cb9a..239e30a 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
 //
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#include <config.h>
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "lisp/lexer.hpp"
 
-#include <sstream>
 #include <cstring>
+#include <sstream>
 #include <stdexcept>
-#include <iostream>
-
-#include "lexer.hpp"
+#include <stdio.h>
 
-namespace lisp
-{
+namespace lisp {
 
 Lexer::Lexer(std::istream& newstream)
-    : stream(newstream), eof(false), linenumber(0)
+  : stream(newstream), eof(false), linenumber(0)
 {
   // trigger a refill of the buffer
   bufpos = NULL;
@@ -102,39 +97,40 @@ Lexer::getNextToken()
       return TOKEN_CLOSE_PAREN;
     case '"': {  // string
       int startline = linenumber;
-      nextChar();
       while(1) {
+        nextChar();
         switch(c) {
-        case '"':
-          nextChar();
-          goto string_finished;
-        case '\r':
-          continue;
-        case '\n':
-          break;
-        case '\\':
-          nextChar();
-          switch(c) {
-          case 'n':
-            c = '\n';
+          case '"':
+            nextChar();
+            goto string_finished;
+          case '\r':
+            continue;
+          case '\n':
             break;
-          case 't':
-            c = '\t';
+          case '\\':
+            nextChar();
+            switch(c) {
+              case 'n':
+                c = '\n';
+                break;
+              case 't':
+                c = '\t';
+                break;
+            }
             break;
+          case EOF: {
+            std::stringstream msg;
+            msg << "Parse error in line " << startline << ": "
+                << "EOF while parsing string.";
+            throw std::runtime_error(msg.str());
           }
-          break;
-        case EOF: {
-          std::stringstream msg;
-          msg << "Parse error in line " << startline << ": "
-              << "EOF while parsing string.";
-          throw std::runtime_error(msg.str());
-        }
-        default:
-          break;
+          default:
+            break;
         }
-        addChar();
+        if(token_length < MAX_TOKEN_LENGTH)
+          token_string[token_length++] = c;
       }
-string_finished:
+      string_finished:
       token_string[token_length] = 0;
       return TOKEN_STRING;
     }
@@ -203,3 +199,5 @@ string_finished:
 }
 
 } // end of namespace lisp
+
+/* EOF */