aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.cpp')
-rw-r--r--src/parse.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/parse.cpp b/src/parse.cpp
index 2ac838f..63765c4 100644
--- a/src/parse.cpp
+++ b/src/parse.cpp
@@ -54,12 +54,13 @@ eat_char(Cursor& cur, istream& in, const char character)
static AST*
read_string(Cursor& cur, istream& in)
{
- string str;
- char c;
Cursor loc = cur;
+ string str;
+ char c;
eat_char(cur, in, '"');
while ((c = read_char(cur, in)) != '"') {
- if (c == '\\') { // string escape
+ switch (c) {
+ case '\\':
switch (c = read_char(cur, in)) {
case '"':
str.push_back('"');
@@ -71,7 +72,7 @@ read_string(Cursor& cur, istream& in)
cin.putback(c);
throw Error(cur, string("unknown string escape `\\") + (char)c + "'");
}
- } else { // any other character
+ default:
str.push_back(c);
}
}
@@ -97,9 +98,9 @@ read_list(PEnv& penv, Cursor& cur, istream& in)
if (in.peek() == ')') {
eat_char(cur, in, ')');
return list.head;
+ } else {
+ list.push_back(read_expression(penv, cur, in));
}
-
- list.push_back(read_expression(penv, cur, in));
}
assert(false);
}
@@ -121,15 +122,14 @@ read_special(Cursor& cur, istream& in)
throw Error(cur, (format("unknown special lexeme `%1%'") % in.peek()).str());
}
assert(false);
- return NULL;
}
static AST*
read_number(Cursor& cur, istream& in)
{
- string str;
- char c;
Cursor loc = cur;
+ string str;
+ char c;
while ((c = in.peek()) != EOF) {
if (isdigit(c) || c == '.')
str += read_char(cur, in);
@@ -146,15 +146,14 @@ read_number(Cursor& cur, istream& in)
static AST*
read_symbol(PEnv& penv, Cursor& cur, istream& in)
{
- string str;
- char c;
Cursor loc = cur;
+ string str;
+ char c;
while ((c = in.peek()) != EOF) {
- if (!isspace(c) && c != ')' && c != '(' && c != EOF && c != -1) {
+ if (!isspace(c) && c != ')' && c != '(' && c != EOF && c != -1)
str += read_char(cur, in);
- } else {
+ else
break;
- }
}
return penv.sym(str);