]> git.tdb.fi Git - libs/datafile.git/blob - source/statement.h
Move token-to-argument conversion to Statement
[libs/datafile.git] / source / statement.h
1 #ifndef MSP_DATAFILE_STATEMENT_H_
2 #define MSP_DATAFILE_STATEMENT_H_
3
4 #include <list>
5 #include "value.h"
6
7 namespace Msp {
8 namespace DataFile {
9
10 struct Token;
11
12 class Statement
13 {
14 public:
15         typedef std::vector<Value> Arguments;
16
17         std::string keyword;
18         Arguments args;
19         bool valid;
20         bool control;
21         std::string source;
22         unsigned line;
23         std::list<Statement> sub;
24
25         Statement();
26         Statement(const std::string &);
27         std::string get_location() const;
28         std::string get_signature() const;
29         
30         template<typename T>
31         Statement &append(const T &v)
32         {
33                 args.push_back(v);
34                 return *this;
35         }
36
37         Statement &append_from_token(const Token &);
38
39         template<typename T>
40         Statement &operator,(const T &v)
41         { return append(v); }
42 };
43
44 struct StatementKey
45 {
46         std::string keyword;
47         std::string signature;
48
49         StatementKey() { }
50         StatementKey(const std::string &k, const std::string &s): keyword(k), signature(s) { }
51
52         bool operator<(const StatementKey &o) const
53         { return keyword<o.keyword || (keyword==o.keyword && signature<o.signature); }
54 };
55
56 struct StatementInfo
57 {
58         StatementKey key;
59         unsigned args_size;
60         std::vector<unsigned> arg_offsets;
61
62         StatementInfo();
63         StatementInfo(const std::string &, const std::string &);
64 };
65
66 } // namespace DataFile
67 } // namespace Msp
68
69 #endif