* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+#include <config.h>
+
#include <iostream>
#include <vector>
+#include <stdexcept>
#include <string>
#include <cctype>
#include <cstdlib>
#include <cstring>
+#include <cassert>
#include "app/globals.h"
#include "app/setup.h"
-#include "utils/lispreader.h"
+#include "lispreader.h"
using namespace SuperTux;
_token_append (char c)
{
if (token_length >= MAX_TOKEN_LENGTH)
- throw LispReaderException("_token_append()", __FILE__, __LINE__);
+ throw std::runtime_error("token too long.");
token_string[token_length++] = c;
token_string[token_length] = '\0';
return stream->v.any.next_char(stream->v.any.data);
}
- throw LispReaderException("_next_char()", __FILE__, __LINE__);
+ assert(false);
return EOF;
}
break;
default :
- throw LispReaderException("_unget_char()", __FILE__, __LINE__);
+ assert(false);
}
}
}
}
- throw LispReaderException("_scan()", __FILE__, __LINE__);
+ throw std::runtime_error("invalid token in lisp file");
return TOKEN_ERROR;
}
void (*unget_char) (char c, void *data))
{
if (next_char == 0 || unget_char == 0)
- throw LispReaderException("lisp_stream_init_any()", __FILE__, __LINE__);
+ throw std::runtime_error("no data");
stream->type = LISP_STREAM_ANY;
stream->v.any.data = data;
return lisp_make_boolean(0);
}
- throw LispReaderException("lisp_read()", __FILE__, __LINE__);
+ throw std::runtime_error("syntax error in lisp file");
return &error_object;
}
_match_pattern_var (lisp_object_t *pattern, lisp_object_t *obj, lisp_object_t **vars)
{
if (lisp_type(pattern) != LISP_TYPE_PATTERN_VAR)
- throw LispReaderException("_match_pattern_var", __FILE__, __LINE__);
+ throw std::runtime_error("type is not a var");
switch (pattern->v.pattern.type)
{
for (sub = pattern->v.pattern.sub; sub != 0; sub = lisp_cdr(sub))
{
if (lisp_type(sub) != LISP_TYPE_CONS)
- throw LispReaderException("_match_pattern_var()", __FILE__, __LINE__);
+ throw std::runtime_error("type isn't a car/cons");
if (_match_pattern(lisp_car(sub), obj, vars))
matched = 1;
break;
default :
- throw LispReaderException("_match_pattern_var()", __FILE__, __LINE__);
+ assert(false);
}
if (vars != 0)
break;
default :
- throw LispReaderException("_match_pattern()", __FILE__, __LINE__);
+ assert(false);
}
return 0;
SuperTux::lisp_integer (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_INTEGER)
- throw LispReaderException("lisp_integer()", __FILE__, __LINE__);
+ throw std::runtime_error("expected integer");
return obj->v.integer;
}
SuperTux::lisp_symbol (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_SYMBOL)
- throw LispReaderException("lisp_symbol()", __FILE__, __LINE__);
+ throw std::runtime_error("expected symbol");
return obj->v.string;
}
SuperTux::lisp_string (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_STRING)
- throw LispReaderException("lisp_string()", __FILE__, __LINE__);
+ throw std::runtime_error("expected string");
return obj->v.string;
}
SuperTux::lisp_boolean (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_BOOLEAN)
- throw LispReaderException("lisp_boolean()", __FILE__, __LINE__);
+ throw std::runtime_error("expected boolean");
return obj->v.integer;
}
SuperTux::lisp_real (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_REAL && obj->type != LISP_TYPE_INTEGER)
- throw LispReaderException("lisp_real()", __FILE__, __LINE__);
+ throw std::runtime_error("expected real");
if (obj->type == LISP_TYPE_INTEGER)
return obj->v.integer;
SuperTux::lisp_car (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
- throw LispReaderException("lisp_car()", __FILE__, __LINE__);
+ throw std::runtime_error("expected car");
return obj->v.cons.car;
}
SuperTux::lisp_cdr (lisp_object_t *obj)
{
if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
- throw LispReaderException("lisp_cdr()", __FILE__, __LINE__);
+ throw std::runtime_error("expected cons");
return obj->v.cons.cdr;
}
else if (x[i] == 'd')
obj = lisp_cdr(obj);
else
- throw LispReaderException("lisp_cxr()", __FILE__, __LINE__);
+ throw std::runtime_error("couldn't parse cxr");
return obj;
}
while (obj != 0)
{
if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
- throw LispReaderException("lisp_list_length()", __FILE__, __LINE__);
+ throw std::runtime_error("expected cons");
++length;
obj = obj->v.cons.cdr;
while (index > 0)
{
if (obj == 0)
- throw LispReaderException("lisp_list_nth_cdr()", __FILE__, __LINE__);
+ throw std::runtime_error("list too short");
if (obj->type != LISP_TYPE_CONS && obj->type != LISP_TYPE_PATTERN_CONS)
- throw LispReaderException("lisp_list_nth_cdr()", __FILE__, __LINE__);
+ throw std::runtime_error("expected cons");
--index;
obj = obj->v.cons.cdr;
obj = lisp_list_nth_cdr(obj, index);
if (obj == 0)
- throw LispReaderException("lisp_list_nth()", __FILE__, __LINE__);
+ throw std::runtime_error("list too short");
return obj->v.cons.car;
}
break;
default :
- throw LispReaderException("lisp_dump()", __FILE__, __LINE__);
+ throw std::runtime_error("unknown list type");
}
}
if(obj->type == LISP_TYPE_EOF || obj->type == LISP_TYPE_PARSE_ERROR) {
lisp_free(obj);
- throw LispReaderException("LispReader::load", __FILE__, __LINE__);
+ throw std::runtime_error("Error while parsing lispfile");
}
if(toplevellist != lisp_symbol(lisp_car(obj))) {
lisp_car(obj);
- throw LispReaderException("LispReader::load wrong toplevel symbol",
- __FILE__, __LINE__);
+ throw std::runtime_error("Worng toplevel symbol in lisp file");
}
LispReader* reader = new LispReader(lisp_cdr(obj));
if (!lisp_cons_p(cur) || !lisp_symbol_p (lisp_car(cur)))
{
lisp_dump(cur, stdout);
- //throw ConstruoError (std::string("LispReader: Read error in search_for ") + name);
printf("LispReader: Read error in search\n");
}
else
}
bool
+LispReader::read_uint (const char* name, unsigned int& i)
+{
+ lisp_object_t* obj = search_for (name);
+ if(!obj)
+ return false;
+
+ if (!lisp_integer_p(lisp_car(obj)))
+ return false;
+
+ i = (unsigned int) lisp_integer(lisp_car(obj));
+ return true;
+}
+
+bool
LispReader::read_lisp(const char* name, lisp_object_t*& b)
{
lisp_object_t* obj = search_for (name);
return false;
if (!lisp_real_p(lisp_car(obj)) && !lisp_integer_p(lisp_car(obj)))
- st_abort("LispReader expected type real at token: ", name);
+ Termination::abort("LispReader expected type real at token: ", name);
f = lisp_real(lisp_car(obj));
return true;
while(!lisp_nil_p(obj))
{
if (!lisp_string_p(lisp_car(obj)))
- st_abort("LispReader expected type string at token: ", name);
+ Termination::abort("LispReader expected type string at token: ", name);
vec.push_back(lisp_string(lisp_car(obj)));
obj = lisp_cdr(obj);
}
while(!lisp_nil_p(obj))
{
if (!lisp_integer_p(lisp_car(obj)))
- st_abort("LispReader expected type integer at token: ", name);
+ Termination::abort("LispReader expected type integer at token: ", name);
vec.push_back(lisp_integer(lisp_car(obj)));
obj = lisp_cdr(obj);
}
while(!lisp_nil_p(obj))
{
if (!lisp_integer_p(lisp_car(obj)))
- st_abort("LispReader expected type integer at token: ", name);
+ Termination::abort("LispReader expected type integer at token: ", name);
vec.push_back(lisp_integer(lisp_car(obj)));
obj = lisp_cdr(obj);
}
return false;
if (!lisp_string_p(lisp_car(obj)))
- st_abort("LispReader expected type string at token: ", name);
+ Termination::abort("LispReader expected type string at token: ", name);
str = lisp_string(lisp_car(obj));
return true;
}
return false;
if (!lisp_boolean_p(lisp_car(obj)))
- st_abort("LispReader expected type bool at token: ", name);
+ Termination::abort("LispReader expected type bool at token: ", name);
b = lisp_boolean(lisp_car(obj));
return true;
}
return obj;
}
-
-// EOF //