From e162455ebb545ea33580e58f52ebe424ef9e68fa Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sun, 5 Sep 2010 01:38:47 -0400 Subject: Minor simplifications to valexpr parser The most significant change is the way CONS sequences are parsed, and that now instead of =/:=, the operators are ==/=. --- src/expr.cc | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/expr.cc') 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 stream; + string pathname; if (args.has(0)) { - stream.reset(new ifstream(path(args.get(0)))); + pathname = args.get(0); + stream.reset(new ifstream(path(pathname))); in = stream.get(); } else { + pathname = ""; 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; -- cgit v1.2.3