diff options
author | John Wiegley <johnw@newartisans.com> | 2010-09-05 01:38:47 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-09-05 01:38:47 -0400 |
commit | e162455ebb545ea33580e58f52ebe424ef9e68fa (patch) | |
tree | df9c98fb39f31b9003db07d7806815bf71031a2d /src/expr.cc | |
parent | 9fcf48482626f20151d75a2ebb81371b45d4540a (diff) | |
download | fork-ledger-e162455ebb545ea33580e58f52ebe424ef9e68fa.tar.gz fork-ledger-e162455ebb545ea33580e58f52ebe424ef9e68fa.tar.bz2 fork-ledger-e162455ebb545ea33580e58f52ebe424ef9e68fa.zip |
Minor simplifications to valexpr parser
The most significant change is the way CONS sequences are parsed, and
that now instead of =/:=, the operators are ==/=.
Diffstat (limited to 'src/expr.cc')
-rw-r--r-- | src/expr.cc | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/expr.cc b/src/expr.cc index bcf83edb..b3d4abcd 100644 --- a/src/expr.cc +++ b/src/expr.cc @@ -167,22 +167,38 @@ value_t source_command(call_scope_t& args) { std::istream * in = NULL; scoped_ptr<ifstream> stream; + string pathname; if (args.has(0)) { - stream.reset(new ifstream(path(args.get<string>(0)))); + pathname = args.get<string>(0); + stream.reset(new ifstream(path(pathname))); in = stream.get(); } else { + pathname = "<stdin>"; in = &std::cin; } - symbol_scope_t file_locals(args); + symbol_scope_t file_locals(args); + std::size_t linenum = 0; + char buf[4096]; + istream_pos_type pos; while (in->good() && ! in->eof()) { - char buf[4096]; + pos = in->tellg(); in->getline(buf, 4095); + linenum++; - if (buf[0] != ';') - expr_t(buf).calc(file_locals); + char * p = skip_ws(buf); + if (*p && *p != ';') { + try { + expr_t(p).calc(file_locals); + } + catch (const std::exception&) { + add_error_context(_("While parsing value expression on line %1:") + << linenum); + add_error_context(source_context(pathname, pos, in->tellg(), "> ")); + } + } } return true; |