diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-07 10:35:32 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-07 10:35:32 -0600 |
commit | c33d7480a60515e4d8b184e01e683e9e74fe7c21 (patch) | |
tree | 3fb5cad9c9838d78dd02ea80d5ad668dc419f0a1 /src/expr.cc | |
parent | be778e387967e56c711ed66e5aafda2d6d7bbc11 (diff) | |
download | fork-ledger-c33d7480a60515e4d8b184e01e683e9e74fe7c21.tar.gz fork-ledger-c33d7480a60515e4d8b184e01e683e9e74fe7c21.tar.bz2 fork-ledger-c33d7480a60515e4d8b184e01e683e9e74fe7c21.zip |
Created merged_expr_t class for chained expressions
Diffstat (limited to 'src/expr.cc')
-rw-r--r-- | src/expr.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/expr.cc b/src/expr.cc index 74d16ecc..8c8e995a 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -163,6 +163,47 @@ void expr_t::dump(std::ostream& out) const if (ptr) ptr->dump(out, 0); } +bool merged_expr_t::check_for_single_identifier(const string& expr) +{ + bool single_identifier = true; + for (const char * p = expr.c_str(); *p; ++p) + if (! std::isalnum(*p) || *p == '_') { + single_identifier = false; + break; + } + + if (single_identifier) { + set_base_expr(expr); + exprs.clear(); + return true; + } else { + return false; + } +} + +void merged_expr_t::compile(scope_t& scope) +{ + if (exprs.empty()) { + parse(base_expr); + } else { + std::ostringstream buf; + + buf << "__tmp_" << term << "=(" << term << "=(" << base_expr << ")"; + foreach (const string& expr, exprs) { + if (merge_operator == ";") + buf << merge_operator << term << "=" << expr; + else + buf << merge_operator << "(" << expr << ")"; + } + buf << ";" << term << ");__tmp_" << term; + + DEBUG("expr.merged.compile", "Compiled expr: " << buf.str()); + parse(buf.str()); + } + + expr_t::compile(scope); +} + value_t source_command(call_scope_t& args) { std::istream * in = NULL; |