[Super-tux-commit] supertux/lib/lisp lexer.cpp,1.1,1.2
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-12-01 19:49:16
|
Update of /cvsroot/super-tux/supertux/lib/lisp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10379/lib/lisp Modified Files: lexer.cpp Log Message: don't use istream::readsome Index: lexer.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/lisp/lexer.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- lexer.cpp 28 Nov 2004 14:57:45 -0000 1.1 +++ lexer.cpp 1 Dec 2004 19:49:08 -0000 1.2 @@ -20,6 +20,7 @@ #include <sstream> #include <stdexcept> +#include <iostream> #include "lexer.h" @@ -36,7 +37,7 @@ try { // trigger a refill of the buffer c = 0; - bufend = c + 1; + bufend = 0; nextChar(); } catch(EOFException& e) { } @@ -53,15 +54,16 @@ if(c >= bufend) { if(eof) throw EOFException(); - std::streamsize n = stream.readsome(buffer, BUFFER_SIZE); - + stream.read(buffer, BUFFER_SIZE); + size_t bytes_read = stream.gcount(); + c = buffer; - bufend = buffer + n; + bufend = buffer + bytes_read; // the following is a hack that appends an additional ' ' at the end of // the file to avoid problems when parsing symbols/elements and a sudden // EOF. This is faster than relying on unget and IMO also nicer. - if(n == 0 || stream.eof()) { + if(bytes_read == 0 || stream.eof()) { eof = true; *bufend = ' '; ++bufend; @@ -85,7 +87,7 @@ switch(*c) { case ';': // comment - while(!stream.eof()) { + while(true) { nextChar(); if(*c == '\n') { ++linenumber; @@ -103,12 +105,6 @@ int startline = linenumber; try { while(1) { - if(stream.eof()) { - std::stringstream msg; - msg << "Parse Error in line " << startline << ": " - << "Couldn't find end of string."; - throw std::runtime_error(msg.str()); - } nextChar(); if(*c == '"') break; |