X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flisp%2Flexer.cpp;h=cd4ab641cc2f72ffe6381b697741885608006acd;hb=b49cbc5f242edb7023153f8bae9ceb444a2460da;hp=451cb9aff706383bed1567cc0d50c247a4473ac5;hpb=aee6c4dede5a9c4fa0f7eb134fba61fef738a573;p=supertux.git diff --git a/src/lisp/lexer.cpp b/src/lisp/lexer.cpp index 451cb9aff..cd4ab641c 100644 --- a/src/lisp/lexer.cpp +++ b/src/lisp/lexer.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // Copyright (C) 2006 Matthias Braun // -// 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 @@ -14,22 +12,26 @@ // 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 +// along with this program. If not, see . + +#include "lisp/lexer.hpp" +#include #include -#include #include -#include - -#include "lexer.hpp" - -namespace lisp -{ - -Lexer::Lexer(std::istream& newstream) - : stream(newstream), eof(false), linenumber(0) +#include + +namespace lisp { + +Lexer::Lexer(std::istream& newstream) : + stream(newstream), + eof(false), + linenumber(0), + bufend(), + bufpos(), + c(), + token_string(), + token_length() { // trigger a refill of the buffer bufpos = NULL; @@ -44,7 +46,7 @@ Lexer::~Lexer() void Lexer::nextChar() { - if(bufpos >= bufend) { + if(bufpos >= bufend || (bufpos == NULL && bufend == NULL) /* Initial refill trigger */) { if(eof) { c = EOF; return; @@ -102,39 +104,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 +206,5 @@ string_finished: } } // end of namespace lisp + +/* EOF */