move over rewritten lispreader from tuxkart (with additional fixes), generalized...
[supertux.git] / lib / lisp / list_iterator.cpp
1 #include <config.h>
2
3 #include "list_iterator.h"
4 #include <stdexcept>
5
6 namespace lisp
7 {
8
9 ListIterator::ListIterator(const lisp::Lisp* newlisp)
10   : current_lisp(0), cur(newlisp)
11 {
12 }
13
14 bool
15 ListIterator::next()
16 {
17   if(cur == 0)
18     return false;
19
20   const lisp::Lisp* child = cur->get_car();
21   if(!child)
22     throw new std::runtime_error("child is 0 in list entry");
23   if(child->get_type() != lisp::Lisp::TYPE_CONS)
24     throw new std::runtime_error("Expected CONS");
25   const lisp::Lisp* name = child->get_car();
26   if(!name || name->get_type() != lisp::Lisp::TYPE_SYMBOL)
27     throw new std::runtime_error("Expected symbol");
28   name->get(current_item);
29   current_lisp = child->get_cdr();
30
31   cur = cur->get_cdr();
32   return true;
33 }
34
35 }