- added check for 'region' symbol
[supertux.git] / src / lisp / lexer.cpp
index 58febf6..4e4f2fb 100644 (file)
@@ -1,7 +1,7 @@
 //  $Id$
 //
-//  Copyright (C) 2004 Matthias Braun <matze@braunis.de>
-//  code in this file based on lispreader from Mark Probst
+//  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
@@ -39,7 +39,7 @@ Lexer::Lexer(std::istream& newstream)
     c = 0;
     bufend = 0;
     nextChar();
-  } catch(EOFException& e) {
+  } catch(EOFException& ) {
   }
 }
 
@@ -56,7 +56,7 @@ Lexer::nextChar()
       throw EOFException();
     stream.read(buffer, BUFFER_SIZE);
     size_t bytes_read = stream.gcount();
-    
+
     c = buffer;
     bufend = buffer + bytes_read;
 
@@ -82,9 +82,9 @@ Lexer::getNextToken()
         ++linenumber;
       nextChar();
     };
-    
+
     token_length = 0;
-    
+
     switch(*c) {
       case ';': // comment
         while(true) {
@@ -108,6 +108,8 @@ Lexer::getNextToken()
             nextChar();
             if(*c == '"')
               break;
+            else if (*c == '\r') // XXX this breaks with pure \r EOL
+              continue;
             else if(*c == '\n')
               linenumber++;
             else if(*c == '\\') {
@@ -137,7 +139,7 @@ Lexer::getNextToken()
       case '#': // constant
         try {
           nextChar();
-          
+
           while(isalnum(*c) || *c == '_') {
             if(token_length < MAX_TOKEN_LENGTH)
               token_string[token_length++] = *c;
@@ -170,15 +172,15 @@ Lexer::getNextToken()
           bool have_nondigits = false;
           bool have_digits = false;
           int have_floating_point = 0;
-          
+
           do {
             if(isdigit(*c))
               have_digits = true;
             else if(*c == '.')
               ++have_floating_point;
             else if(isalnum(*c) || *c == '_')
-              have_nondigits = true;  
-            
+              have_nondigits = true;
+
             if(token_length < MAX_TOKEN_LENGTH)
               token_string[token_length++] = *c;
 
@@ -186,7 +188,7 @@ Lexer::getNextToken()
           } while(!isspace(*c) && !strchr(delims, *c));
 
           token_string[token_length] = 0;
-          
+
           // no nextChar
 
           if(have_nondigits || !have_digits || have_floating_point > 1)
@@ -202,11 +204,11 @@ Lexer::getNextToken()
             nextChar();
           } while(!isspace(*c) && !strchr(delims, *c));
           token_string[token_length] = 0;
-          
+
           // no nextChar
 
           return TOKEN_SYMBOL;
-        }       
+        }
     }
   } catch(EOFException& ) {
     return TOKEN_EOF;
@@ -214,4 +216,3 @@ Lexer::getNextToken()
 }
 
 } // end of namespace lisp
-