summaryrefslogtreecommitdiff
path: root/src/expr.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr.cc')
-rw-r--r--src/expr.cc26
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;