]> git.tdb.fi Git - libs/datafile.git/blobdiff - source/statement.h
Move token-to-argument conversion to Statement
[libs/datafile.git] / source / statement.h
index 378ddabdb4ab1c8efc5d19a2853998197d703920..9aad48d953226ba0ab1b3b209d88d10460d56f39 100644 (file)
@@ -1,35 +1,69 @@
-/*
-This file is part of libmspparser
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-#ifndef MSP_PARSER_STATEMENT_H_
-#define MSP_PARSER_STATEMENT_H_
+#ifndef MSP_DATAFILE_STATEMENT_H_
+#define MSP_DATAFILE_STATEMENT_H_
 
 #include <list>
-#include <sstream>
-#include <vector>
 #include "value.h"
 
 namespace Msp {
-namespace Parser {
+namespace DataFile {
+
+struct Token;
 
 class Statement
 {
 public:
+       typedef std::vector<Value> Arguments;
+
        std::string keyword;
-       ValueArray  args;
-       bool        valid;
+       Arguments args;
+       bool valid;
+       bool control;
        std::string source;
-       unsigned    line;
+       unsigned line;
        std::list<Statement> sub;
 
-       Statement(): valid(false), line(0) { }
-       std::string get_location() const
-       { std::ostringstream ss; ss<<source<<':'<<line; return ss.str(); }
+       Statement();
+       Statement(const std::string &);
+       std::string get_location() const;
+       std::string get_signature() const;
+       
+       template<typename T>
+       Statement &append(const T &v)
+       {
+               args.push_back(v);
+               return *this;
+       }
+
+       Statement &append_from_token(const Token &);
+
+       template<typename T>
+       Statement &operator,(const T &v)
+       { return append(v); }
+};
+
+struct StatementKey
+{
+       std::string keyword;
+       std::string signature;
+
+       StatementKey() { }
+       StatementKey(const std::string &k, const std::string &s): keyword(k), signature(s) { }
+
+       bool operator<(const StatementKey &o) const
+       { return keyword<o.keyword || (keyword==o.keyword && signature<o.signature); }
+};
+
+struct StatementInfo
+{
+       StatementKey key;
+       unsigned args_size;
+       std::vector<unsigned> arg_offsets;
+
+       StatementInfo();
+       StatementInfo(const std::string &, const std::string &);
 };
 
-} // namespace Parser
+} // namespace DataFile
 } // namespace Msp
 
 #endif