X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstatement.cpp;h=6d1c3b1f22767b5eba0d6cca5bb52b0ef0651794;hb=14f031aead619ce8a3fff1c283c3d205d421cd1f;hp=3b6f7165b0ef1fa50874c255b12cd987c2563b22;hpb=3b78eeb8b92dc3524d6a0456b4daf0a0f3dbf813;p=libs%2Fdatafile.git diff --git a/source/statement.cpp b/source/statement.cpp index 3b6f716..6d1c3b1 100644 --- a/source/statement.cpp +++ b/source/statement.cpp @@ -1,5 +1,6 @@ #include #include "statement.h" +#include "token.h" #include "type.h" using namespace std; @@ -9,12 +10,14 @@ namespace DataFile { Statement::Statement(): valid(false), + control(false), line(0) { } Statement::Statement(const string &kw): keyword(kw), valid(true), + control(!kw.compare(0, 2, "__")), line(0) { } @@ -29,11 +32,32 @@ string Statement::get_location() const string Statement::get_signature() const { string result; - for(Arguments::const_iterator i = args.begin(); i!=args.end(); ++i) + for(Arguments::const_iterator i=args.begin(); i!=args.end(); ++i) result += i->get_signature(); return result; } +Statement &Statement::append_from_token(const Token &token) +{ + if(token.type==Token::INTEGER) + return append(lexical_cast(token.str, Fmt().autobase())); + else if(token.type==Token::FLOAT) + return append(lexical_cast(token.str)); + else if(token.type==Token::STRING) + return append(token.str); + else if(token.type==Token::IDENTIFIER) + { + if(token.str=="true") + return append(true); + else if(token.str=="false") + return append(false); + else + return append(Symbol(token.str)); + } + else + throw invalid_argument("Statement::append_from_token"); +} + StatementInfo::StatementInfo(): args_size(0)