diff options
-rw-r--r-- | src/eval_env.cc | 9 | ||||
-rw-r--r-- | src/eval_env.h | 6 | ||||
-rw-r--r-- | src/lexer.cc | 12 | ||||
-rw-r--r-- | src/lexer.in.cc | 12 | ||||
-rw-r--r-- | src/state_test.cc | 8 |
5 files changed, 26 insertions, 21 deletions
diff --git a/src/eval_env.cc b/src/eval_env.cc index 57c20c6..81a8765 100644 --- a/src/eval_env.cc +++ b/src/eval_env.cc @@ -38,14 +38,17 @@ string EvalString::Evaluate(Env* env) const { return result; } -void EvalString::Add(TokenType type, StringPiece text) { +void EvalString::AddText(StringPiece text) { // Add it to the end of an existing RAW token if possible. - if (type == RAW && !parsed_.empty() && parsed_.back().second == RAW) { + if (!parsed_.empty() && parsed_.back().second == RAW) { parsed_.back().first.append(text.str_, text.len_); } else { - parsed_.push_back(make_pair(text.AsString(), type)); + parsed_.push_back(make_pair(text.AsString(), RAW)); } } +void EvalString::AddSpecial(StringPiece text) { + parsed_.push_back(make_pair(text.AsString(), SPECIAL)); +} string EvalString::Serialize() const { string result; diff --git a/src/eval_env.h b/src/eval_env.h index 8c144f0..2341bcb 100644 --- a/src/eval_env.h +++ b/src/eval_env.h @@ -48,13 +48,15 @@ struct EvalString { void Clear() { parsed_.clear(); } bool empty() const { return parsed_.empty(); } - enum TokenType { RAW, SPECIAL }; - void Add(TokenType type, StringPiece text); + void AddText(StringPiece text); + void AddSpecial(StringPiece text); /// Construct a human-readable representation of the parsed state, /// for use in tests. string Serialize() const; +private: + enum TokenType { RAW, SPECIAL }; typedef vector<pair<string, TokenType> > TokenList; TokenList parsed_; }; diff --git a/src/lexer.cc b/src/lexer.cc index 0371371..40d7def 100644 --- a/src/lexer.cc +++ b/src/lexer.cc @@ -592,7 +592,7 @@ bool Lexer::ReadEvalString(EvalString* eval, bool path, string* err) { goto yy117; yy90: { - eval->Add(EvalString::RAW, StringPiece(start, p - start)); + eval->AddText(StringPiece(start, p - start)); continue; } yy91: @@ -604,7 +604,7 @@ yy91: } else { if (*start == '\n') break; - eval->Add(EvalString::RAW, StringPiece(start, 1)); + eval->AddText(StringPiece(start, 1)); continue; } } @@ -653,13 +653,13 @@ yy98: yy99: ++p; { - eval->Add(EvalString::RAW, StringPiece(" ", 1)); + eval->AddText(StringPiece(" ", 1)); continue; } yy101: ++p; { - eval->Add(EvalString::RAW, StringPiece("$", 1)); + eval->AddText(StringPiece("$", 1)); continue; } yy103: @@ -668,7 +668,7 @@ yy103: goto yy115; yy104: { - eval->Add(EvalString::SPECIAL, StringPiece(start + 1, p - start - 1)); + eval->AddSpecial(StringPiece(start + 1, p - start - 1)); continue; } yy105: @@ -698,7 +698,7 @@ yy109: yy112: ++p; { - eval->Add(EvalString::SPECIAL, StringPiece(start + 2, p - start - 3)); + eval->AddSpecial(StringPiece(start + 2, p - start - 3)); continue; } yy114: diff --git a/src/lexer.in.cc b/src/lexer.in.cc index 1df1f06..c5d73e1 100644 --- a/src/lexer.in.cc +++ b/src/lexer.in.cc @@ -180,7 +180,7 @@ bool Lexer::ReadEvalString(EvalString* eval, bool path, string* err) { start = p; /*!re2c [^$ :\n|\000]+ { - eval->Add(EvalString::RAW, StringPiece(start, p - start)); + eval->AddText(StringPiece(start, p - start)); continue; } [ :|\n] { @@ -190,27 +190,27 @@ bool Lexer::ReadEvalString(EvalString* eval, bool path, string* err) { } else { if (*start == '\n') break; - eval->Add(EvalString::RAW, StringPiece(start, 1)); + eval->AddText(StringPiece(start, 1)); continue; } } "$$" { - eval->Add(EvalString::RAW, StringPiece("$", 1)); + eval->AddText(StringPiece("$", 1)); continue; } "$ " { - eval->Add(EvalString::RAW, StringPiece(" ", 1)); + eval->AddText(StringPiece(" ", 1)); continue; } "$\n"[ ]* { continue; } "${"varname"}" { - eval->Add(EvalString::SPECIAL, StringPiece(start + 2, p - start - 3)); + eval->AddSpecial(StringPiece(start + 2, p - start - 3)); continue; } "$"simple_varname { - eval->Add(EvalString::SPECIAL, StringPiece(start + 1, p - start - 1)); + eval->AddSpecial(StringPiece(start + 1, p - start - 1)); continue; } "$". { diff --git a/src/state_test.cc b/src/state_test.cc index ca4e60c..e9d8174 100644 --- a/src/state_test.cc +++ b/src/state_test.cc @@ -23,10 +23,10 @@ TEST(State, Basic) { State state; Rule* rule = new Rule("cat"); - rule->command_.Add(EvalString::RAW, "cat "); - rule->command_.Add(EvalString::SPECIAL, "in"); - rule->command_.Add(EvalString::RAW, " > "); - rule->command_.Add(EvalString::SPECIAL, "out"); + rule->command_.AddText("cat "); + rule->command_.AddSpecial("in"); + rule->command_.AddText(" > "); + rule->command_.AddSpecial("out"); state.AddRule(rule); Edge* edge = state.AddEdge(rule); |