]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/textparser.cpp
Don't throw on empty files
[libs/datafile.git] / source / textparser.cpp
index d8e422ee7ff4d4d710a764a62383955f377305f5..0076c1b4bab954f8a893abf9f2e6a4ff7da5039a 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspdatafile
-Copyright © 2007-2008  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2008, 2010  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -77,20 +77,19 @@ Statement TextParser::parse_statement(const Token *t)
                else if(token.str==";")
                        break;
                else if(token.type==Token::INTEGER)
-                       result.args.push_back(Value(INTEGER, token.str));
+                       result.append(lexical_cast<IntType::Store>(token.str));
                else if(token.type==Token::FLOAT)
-                       result.args.push_back(Value(FLOAT, token.str));
+                       result.append(lexical_cast<FloatType::Store>(token.str));
                else if(token.type==Token::STRING)
-                       result.args.push_back(Value(STRING, token.str));
+                       result.append(token.str);
                else if(token.type==Token::IDENTIFIER)
                {
                        if(token.str=="true")
-                               result.args.push_back(Value(BOOLEAN, "1"));
+                               result.append(true);
                        else if(token.str=="false")
-                               result.args.push_back(Value(BOOLEAN, "0"));
+                               result.append(false);
                        else
-                               result.args.push_back(Value(ENUM, token.str));
-                       //result.args.push_back(resolve_identifiertoken.str);
+                               result.append(Symbol(token.str));
                }
                else if(token.str=="")
                        throw_at(ParseError("Unexcepted end of input"), get_location());
@@ -122,7 +121,7 @@ Token TextParser::parse_token()
                        comment = 3;
                else if(comment==3)   // Skip the second character of block comment end
                        comment = 0;
-               else if(!isspace(c) && !comment)
+               else if(c!=-1 && !isspace(c) && !comment)
                        comment = -1;
        }