aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-09 01:57:52 +0000
committerDavid Robillard <d@drobilla.net>2010-12-09 01:57:52 +0000
commit39af9fe79809a67c837485d8edcae6b9246c5fa6 (patch)
tree159b854110774669e410116f89de10f85d3e2b2d /src
parente759ca41e4ba831279b1495c6713d79ad10ab6f9 (diff)
downloadresp-39af9fe79809a67c837485d8edcae6b9246c5fa6.tar.gz
resp-39af9fe79809a67c837485d8edcae6b9246c5fa6.tar.bz2
resp-39af9fe79809a67c837485d8edcae6b9246c5fa6.zip
Const-correct parser.
git-svn-id: http://svn.drobilla.net/resp/resp@323 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src')
-rw-r--r--src/parse.cpp16
-rw-r--r--src/repl.cpp6
-rw-r--r--src/resp.cpp2
-rw-r--r--src/resp.hpp3
4 files changed, 13 insertions, 14 deletions
diff --git a/src/parse.cpp b/src/parse.cpp
index 420a8ea..43fb681 100644
--- a/src/parse.cpp
+++ b/src/parse.cpp
@@ -49,7 +49,7 @@ eat_char(Cursor& cur, istream& in, const char character)
THROW_IF(c != character, cur, (format("expected `%1%'") % character).str());
}
-static AST*
+static const AST*
read_string(Cursor& cur, istream& in)
{
Cursor loc = cur;
@@ -83,10 +83,10 @@ read_line_comment(Cursor& cur, istream& in)
while (read_char(cur, in) != '\n') {}
}
-static AST*
+static const AST*
read_list(PEnv& penv, Cursor& cur, istream& in)
{
- List<ATuple, AST> list;
+ List<ATuple, const AST> list;
eat_char(cur, in, '(');
while (true) {
@@ -101,7 +101,7 @@ read_list(PEnv& penv, Cursor& cur, istream& in)
assert(false);
}
-static AST*
+static const AST*
read_special(Cursor& cur, istream& in)
{
eat_char(cur, in, '#');
@@ -120,7 +120,7 @@ read_special(Cursor& cur, istream& in)
assert(false);
}
-static AST*
+static const AST*
read_number(Cursor& cur, istream& in)
{
Cursor loc = cur;
@@ -139,7 +139,7 @@ read_number(Cursor& cur, istream& in)
return new ALiteral<float>(T_FLOAT, strtod(str.c_str(), NULL), loc);
}
-static AST*
+static const AST*
read_symbol(PEnv& penv, Cursor& cur, istream& in)
{
string str;
@@ -155,7 +155,7 @@ read_symbol(PEnv& penv, Cursor& cur, istream& in)
}
/// Read an expression from @a in
-AST*
+const AST*
read_expression(PEnv& penv, Cursor& cur, istream& in)
{
while (!cin.eof()) {
@@ -175,7 +175,7 @@ read_expression(PEnv& penv, Cursor& cur, istream& in)
throw Error(cur, "unexpected `)'");
case '#':
{
- AST* ret = read_special(cur, in);
+ const AST* ret = read_special(cur, in);
if (ret)
return ret;
break;
diff --git a/src/repl.cpp b/src/repl.cpp
index ae49b00..114ff58 100644
--- a/src/repl.cpp
+++ b/src/repl.cpp
@@ -27,7 +27,7 @@
using namespace std;
static bool
-readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, const AST*& ast)
+readParseType(CEnv& cenv, Cursor& cursor, istream& is, const AST*& exp, const AST*& ast)
{
try {
exp = read_expression(cenv.penv, cursor, is);
@@ -81,7 +81,7 @@ callPrintCollect(CEnv& cenv, CFunc f, const AST* result, const AType* resultT, b
int
eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute)
{
- AST* exp = NULL;
+ const AST* exp = NULL;
const AST* ast = NULL;
typedef list<const AST*> Parsed;
@@ -160,7 +160,7 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute)
int
repl(CEnv& cenv)
{
- AST* exp = NULL;
+ const AST* exp = NULL;
const AST* ast = NULL;
const string replFnName = cenv.penv.gensymstr("_repl");
while (1) {
diff --git a/src/resp.cpp b/src/resp.cpp
index 9e959f5..e745455 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);
- AST* exp = read_expression(cenv->penv, loc, is);
+ const AST* exp = read_expression(cenv->penv, 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 aa4d624..459e923 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -119,7 +119,7 @@ ostream& operator<<(ostream& out, const Env<K,V>& env) {
struct PEnv;
struct AST;
-AST* read_expression(PEnv& penv, Cursor& cur, std::istream& in);
+const AST* read_expression(PEnv& penv, Cursor& cur, std::istream& in);
/***************************************************************************
@@ -528,7 +528,6 @@ AST::operator==(const AST& rhs) const
}
return false; // never reached
}
-
case T_UNKNOWN:
case T_STRING:
case T_SYMBOL: