Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 1 | #ifndef VALUE_H_ |
| 2 | #define VALUE_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | #include <string> |
| 6 | #include <vector> |
| 7 | |
| 8 | #include "string_piece.h" |
| 9 | |
| 10 | using namespace std; |
| 11 | |
| 12 | class Evaluator; |
| 13 | |
| 14 | class Evaluable { |
| 15 | public: |
| 16 | virtual void Eval(Evaluator* ev, string* s) const = 0; |
| 17 | virtual shared_ptr<string> Eval(Evaluator*) const; |
| 18 | |
| 19 | protected: |
| 20 | Evaluable(); |
| 21 | virtual ~Evaluable(); |
| 22 | }; |
| 23 | |
| 24 | class Value : public Evaluable { |
| 25 | public: |
| 26 | virtual ~Value(); |
| 27 | |
| 28 | virtual Value* Compact() { return this; } |
| 29 | |
| 30 | string DebugString() const; |
| 31 | |
| 32 | protected: |
| 33 | Value(); |
| 34 | virtual string DebugString_() const = 0; |
| 35 | }; |
| 36 | |
Shinichiro Hamaji | 66bd7bc | 2015-06-19 16:54:06 +0900 | [diff] [blame] | 37 | enum struct ParseExprOpt { |
| 38 | NORMAL = 0, |
| 39 | DEFINE, |
| 40 | COMMAND, |
| 41 | }; |
| 42 | |
| 43 | Value* ParseExprImpl(StringPiece s, const char* terms, ParseExprOpt opt, |
Shinichiro Hamaji | d146f4c | 2015-06-17 17:51:24 +0900 | [diff] [blame] | 44 | size_t* index_out, bool trim_right_space = false); |
Shinichiro Hamaji | 66bd7bc | 2015-06-19 16:54:06 +0900 | [diff] [blame] | 45 | Value* ParseExpr(StringPiece s, ParseExprOpt opt = ParseExprOpt::NORMAL); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 46 | |
Shinichiro Hamaji | 76ff983 | 2015-06-18 17:11:22 +0900 | [diff] [blame] | 47 | string JoinValues(const vector<Value*>& vals, const char* sep); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 48 | |
Shinichiro Hamaji | 4c469b3 | 2015-06-15 19:53:36 +0900 | [diff] [blame] | 49 | Value* NewExpr3(Value* v1, Value* v2, Value* v3); |
| 50 | |
Shinichiro Hamaji | b74b890 | 2015-06-22 18:22:30 +0900 | [diff] [blame^] | 51 | Value* NewLiteral(StringPiece s); |
Shinichiro Hamaji | 4c469b3 | 2015-06-15 19:53:36 +0900 | [diff] [blame] | 52 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 53 | #endif // VALUE_H_ |