From 206c01b4ba4c5e674e313d7ed7fe21c2b93f2d12 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 13 Jan 2011 04:07:44 +0000 Subject: Fix error location reporting. git-svn-id: http://svn.drobilla.net/resp/trunk@406 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/parse.cpp | 24 +++++++++++++----------- src/repl.cpp | 2 +- src/resp.cpp | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/parse.cpp b/src/parse.cpp index 4f2c723..b61b971 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -55,9 +55,9 @@ eat_char(Cursor& cur, istream& in, const char character) static const AST* read_string(Cursor& cur, istream& in) { - Cursor loc = cur; - string str; - char c; + const Cursor loc = cur; + string str; + char c; eat_char(cur, in, '"'); while ((c = read_char(cur, in)) != '"') { switch (c) { @@ -89,13 +89,14 @@ read_line_comment(Cursor& cur, istream& in) static const AST* read_list(PEnv& penv, Cursor& cur, istream& in) { - List list; - + const Cursor loc = cur; + List list; eat_char(cur, in, '('); while (true) { skip_space(cur, in); if (in.peek() == ')') { eat_char(cur, in, ')'); + list.head->loc = loc; return list.head; } else { list.push_back(penv.parse(cur, in)); @@ -127,9 +128,9 @@ read_special(Cursor& cur, istream& in) static const AST* read_number(Cursor& cur, istream& in) { - Cursor loc = cur; - string str; - char c; + const Cursor loc = cur; + string str; + char c; while ((c = in.peek()) != EOF) { if (isdigit(c) || c == '.') str += read_char(cur, in); @@ -146,8 +147,9 @@ read_number(Cursor& cur, istream& in) static const AST* read_symbol(PEnv& penv, Cursor& cur, istream& in) { - string str; - char c; + const Cursor loc = cur; + string str; + char c; while ((c = in.peek()) != EOF) { if (!isspace(c) && c != ')' && c != '(' && c != EOF && c != -1) str += read_char(cur, in); @@ -155,7 +157,7 @@ read_symbol(PEnv& penv, Cursor& cur, istream& in) break; } - return penv.sym(str, cur); + return penv.sym(str, loc); } /// Read an expression from @a in diff --git a/src/repl.cpp b/src/repl.cpp index c461526..8fe43f5 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -175,7 +175,7 @@ repl(CEnv& cenv) while (1) { cenv.out << "() "; cenv.out.flush(); - Cursor cursor("(stdin)"); + Cursor cursor("(stdin)", 1, 1); try { if (!readParseType(cenv, cursor, std::cin, exp, ast)) diff --git a/src/resp.cpp b/src/resp.cpp index 2b08fc3..e2f5a49 100644 --- a/src/resp.cpp +++ b/src/resp.cpp @@ -155,7 +155,7 @@ main(int argc, char** argv) ifstream is(*f); try { while (is.good() && !is.eof()) { - Cursor loc(*f); + Cursor loc(*f, 1, 1); const AST* exp = cenv->penv.parse(loc, is); if (!exp || (exp->to_tuple() && exp->to_tuple()->empty())) break; @@ -194,7 +194,7 @@ main(int argc, char** argv) ifstream is(*f); if (is.good()) { - Cursor cursor(filename); + Cursor cursor(filename, 1, 1); ret = ret | eval(*cenv, cursor, is, !batch); } else { cerr << argv[0] << ": " << *f << ": " << strerror(errno) << endl; -- cgit v1.2.1