]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/textparser.cpp
Fix EOF handling
[libs/datafile.git] / source / textparser.cpp
index 78d2f1df6334b32dbf67a7871975deda4dafb0a4..f7c830d0030ebcf5428c3c0abf06c63ba043ce60 100644 (file)
@@ -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();