]> git.tdb.fi Git - libs/datafile.git/commitdiff
Move token-to-argument conversion to Statement
authorMikko Rasa <tdb@tdb.fi>
Fri, 2 Sep 2016 12:34:15 +0000 (15:34 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 2 Sep 2016 12:34:15 +0000 (15:34 +0300)
source/statement.cpp
source/statement.h
source/textparser.cpp

index b1ff05826e314441fd3e93ced8c5117f295b5824..9dfb54421a47c6f041b344cc175a6c67e232f43c 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/strings/format.h>
 #include "statement.h"
+#include "token.h"
 #include "type.h"
 
 using namespace std;
@@ -36,6 +37,27 @@ string Statement::get_signature() const
        return result;
 }
 
+Statement &Statement::append_from_token(const Token &token)
+{
+       if(token.type==Token::INTEGER)
+               return append(lexical_cast<IntType::Store>(token.str));
+       else if(token.type==Token::FLOAT)
+               return append(lexical_cast<FloatType::Store>(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)
index 184ef9955cbc78af80231eabda307bb45605be54..9aad48d953226ba0ab1b3b209d88d10460d56f39 100644 (file)
@@ -7,6 +7,8 @@
 namespace Msp {
 namespace DataFile {
 
+struct Token;
+
 class Statement
 {
 public:
@@ -32,6 +34,8 @@ public:
                return *this;
        }
 
+       Statement &append_from_token(const Token &);
+
        template<typename T>
        Statement &operator,(const T &v)
        { return append(v); }
index a7e8ee9d6abaf4d5198824fde47e811651996777..7dc4bde7e46ed659368498798bf0b6b3b62fa246 100644 (file)
@@ -66,21 +66,8 @@ Statement TextParser::parse_statement(const Token *t)
                        sub = 1;
                else if(token.str==";")
                        break;
-               else if(token.type==Token::INTEGER)
-                       result.append(lexical_cast<IntType::Store>(token.str));
-               else if(token.type==Token::FLOAT)
-                       result.append(lexical_cast<FloatType::Store>(token.str));
-               else if(token.type==Token::STRING)
-                       result.append(token.str);
-               else if(token.type==Token::IDENTIFIER)
-               {
-                       if(token.str=="true")
-                               result.append(true);
-                       else if(token.str=="false")
-                               result.append(false);
-                       else
-                               result.append(Symbol(token.str));
-               }
+               else if(token.type!=Token::SPECIAL)
+                       result.append_from_token(token);
                else
                        throw syntax_error(token.str);
        }