From c27e97b2294951e5db6e9c9fa6f6f0de2c5243e6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 9 Dec 2010 04:08:51 +0000 Subject: read_expression => PEnv::parse. git-svn-id: http://svn.drobilla.net/resp/resp@325 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/parse.cpp | 10 +++++----- src/repl.cpp | 2 +- src/resp.cpp | 2 +- src/resp.hpp | 12 +++--------- 4 files changed, 10 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/parse.cpp b/src/parse.cpp index e0948fe..8b563cf 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -95,7 +95,7 @@ read_list(PEnv& penv, Cursor& cur, istream& in) eat_char(cur, in, ')'); return list.head; } else { - list.push_back(read_expression(penv, cur, in)); + list.push_back(penv.parse(cur, in)); } } assert(false); @@ -156,7 +156,7 @@ read_symbol(PEnv& penv, Cursor& cur, istream& in) /// Read an expression from @a in const AST* -read_expression(PEnv& penv, Cursor& cur, istream& in) +PEnv::parse(Cursor& cur, istream& in) { while (!cin.eof()) { skip_space(cur, in); @@ -170,7 +170,7 @@ read_expression(PEnv& penv, Cursor& cur, istream& in) case '"': return read_string(cur, in); case '(': - return read_list(penv, cur, in); + return read_list(*this, cur, in); case ')': throw Error(cur, "unexpected `)'"); case '#': @@ -188,13 +188,13 @@ read_expression(PEnv& penv, Cursor& cur, istream& in) return read_number(cur, in); } else { in.putback(c); - return read_symbol(penv, cur, in); + return read_symbol(*this, cur, in); } default: if (isdigit(c)) return read_number(cur, in); else - return read_symbol(penv, cur, in); + return read_symbol(*this, cur, in); } } return NULL; diff --git a/src/repl.cpp b/src/repl.cpp index 114ff58..88fefab 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -30,7 +30,7 @@ static bool readParseType(CEnv& cenv, Cursor& cursor, istream& is, const AST*& exp, const AST*& ast) { try { - exp = read_expression(cenv.penv, cursor, is); + exp = cenv.penv.parse(cursor, is); } catch (Error e) { is.ignore(std::numeric_limits::max(), '\n'); // Skip REPL junk throw e; diff --git a/src/resp.cpp b/src/resp.cpp index cef2d0c..49c4643 100644 --- a/src/resp.cpp +++ b/src/resp.cpp @@ -143,7 +143,7 @@ main(int argc, char** argv) try { while (is.good() && !is.eof()) { Cursor loc(*f); - const AST* exp = read_expression(cenv->penv, loc, is); + const AST* exp = cenv->penv.parse(loc, is); if (!exp || (exp->to_tuple() && exp->to_tuple()->tup_len() == 1)) break; diff --git a/src/resp.hpp b/src/resp.hpp index a453b88..1fbf3cf 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -68,15 +68,6 @@ struct Error { }; -/*************************************************************************** - * Lexer: Text (istream) -> S-Expressions (SExp) * - ***************************************************************************/ - -struct PEnv; -struct AST; -const AST* read_expression(PEnv& penv, Cursor& cur, std::istream& in); - - /*************************************************************************** * Backend Types * ***************************************************************************/ @@ -544,6 +535,7 @@ ostream& operator<<(ostream& out, const Env& env) { return out; } + /*************************************************************************** * Parser: S-Expressions (SExp) -> AST Nodes (AST) * ***************************************************************************/ @@ -564,6 +556,8 @@ struct PEnv : private map { return new ASymbol(str, c); } } + + const AST* parse(Cursor& cur, std::istream& in); const AST* expand(const AST* exp); typedef std::set Primitives; -- cgit v1.2.1