X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Flisp%2Flexer.cpp;h=90f4aa28c831f87c6690451f210c4a0bf7e21df3;hb=b917bb4789b14d1bb1445b9777ab494e9623fd50;hp=e1a4220f51bc3c2279bb8d91c1e74275dd3e1428;hpb=ea0629af91963ee2e4ab6b41124b5a7075ddd309;p=supertux.git diff --git a/src/lisp/lexer.cpp b/src/lisp/lexer.cpp index e1a4220f5..90f4aa28c 100644 --- a/src/lisp/lexer.cpp +++ b/src/lisp/lexer.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #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;