Patch by Matt McCutchen to find levels in current directory when selected from comman...
[supertux.git] / src / lisp / lexer.cpp
index e1a4220..90f4aa2 100644 (file)
@@ -22,6 +22,7 @@
 #include <cstring>
 #include <stdexcept>
 #include <iostream>
+#include <stdio.h>
 
 #include "lexer.hpp"
 
@@ -65,6 +66,16 @@ Lexer::nextChar()
     }
   }
   c = *bufpos++;
+  if(c == '\n')
+    ++linenumber;
+}
+
+void
+Lexer::addChar()
+{
+  if(token_length < MAX_TOKEN_LENGTH)
+    token_string[token_length++] = c;
+  nextChar();
 }
 
 Lexer::TokenType
@@ -73,21 +84,15 @@ Lexer::getNextToken()
   static const char* delims = "\"();";
 
   while(isspace(c)) {
-    if(c == '\n')
-      ++linenumber;
     nextChar();
-  };
+  }
 
   token_length = 0;
 
   switch(c) {
     case ';': // comment
-      while(true) {
+      while(c != '\n') {
         nextChar();
-        if(c == '\n') {
-          ++linenumber;
-          break;
-        }
       }
       return getNextToken(); // and again
     case '(':
@@ -107,7 +112,6 @@ Lexer::getNextToken()
         case '\r':
           continue;
         case '\n':
-          linenumber++;
           break;
         case '\\':
           nextChar();
@@ -140,9 +144,7 @@ string_finished:
       nextChar();
 
       while(isalnum(c) || c == '_') {
-        if(token_length < MAX_TOKEN_LENGTH)
-          token_string[token_length++] = c;
-        nextChar();
+        addChar();
       }
       token_string[token_length] = 0;
 
@@ -176,10 +178,7 @@ string_finished:
           else if(isalnum(c) || c == '_')
             have_nondigits = true;
 
-          if(token_length < MAX_TOKEN_LENGTH)
-            token_string[token_length++] = c;
-
-          nextChar();
+          addChar();
         } while(!isspace(c) && !strchr(delims, c));
 
         token_string[token_length] = 0;
@@ -194,9 +193,7 @@ string_finished:
           return TOKEN_INTEGER;
       } else {
         do {
-          if(token_length < MAX_TOKEN_LENGTH)
-            token_string[token_length++] = c;
-          nextChar();
+          addChar();
         } while(!isspace(c) && !strchr(delims, c));
         token_string[token_length] = 0;