From e26f7e98e5d8a5666192a43348b3ca7a35f6b860 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 23 Jul 2008 13:02:32 +0000 Subject: [PATCH] Fix EOF handling --- source/input.cpp | 5 +++++ source/input.h | 2 +- source/textparser.cpp | 12 +++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/source/input.cpp b/source/input.cpp index e03a921..f3f8f23 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -34,5 +34,10 @@ int Input::peek() return next; } +Input::operator bool() const +{ + return next>=0 || !in.eof(); +} + } // namespace DataFile } // namespace Msp diff --git a/source/input.h b/source/input.h index eeb1840..ad921ec 100644 --- a/source/input.h +++ b/source/input.h @@ -19,7 +19,7 @@ public: int get(); int peek(); unsigned get_line_number() const { return line; } - operator bool() const { return !in.eof(); } + operator bool() const; private: IO::Base ∈ unsigned line; diff --git a/source/textparser.cpp b/source/textparser.cpp index 78d2f1d..f7c830d 100644 --- a/source/textparser.cpp +++ b/source/textparser.cpp @@ -104,10 +104,10 @@ Statement TextParser::parse_statement(const Token *t) Token TextParser::parse_token() { int c=0; - unsigned comment=0; + int comment=0; // Skip over comments and whitespace - while(in) + while(in && comment>=0) { c=in.get(); int next=in.peek(); @@ -123,11 +123,13 @@ Token TextParser::parse_token() else if(comment==3) // Skip the second character of block comment end comment=0; else if(!isspace(c) && !comment) - break; + comment=-1; } - if(comment) // Didn't hit any non-whitespace + if(comment>0) // EOF while in comment throw ParseError(src+": Unfinished comment at end of input", src, in.get_line_number()); + else if(comment==0) // Didn't hit any non-whitespace + return Token(Token::SPECIAL, ""); enum ParseState { @@ -167,7 +169,7 @@ Token TextParser::parse_token() string buf; bool escape=false; - while(in) + while(in || state==INIT) { if(state!=INIT) c=in.get(); -- 2.43.0