LispIterator.cs 680 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // $Id$
  2. namespace Lisp
  3. {
  4. public sealed class LispIterator {
  5. private List IterList;
  6. private int Pos;
  7. private string ChildKey;
  8. private List ChildList;
  9. public string Key {
  10. get {
  11. return ChildKey;
  12. }
  13. }
  14. public List List {
  15. get {
  16. return ChildList;
  17. }
  18. }
  19. public LispIterator(List List) {
  20. IterList = List;
  21. }
  22. public bool MoveNext() {
  23. List list;
  24. do {
  25. if(Pos >= IterList.Length)
  26. return false;
  27. object o = IterList[Pos++];
  28. if(! (o is List))
  29. continue;
  30. list = (List) o;
  31. if(list.Length == 0 || ! (list[0] is Symbol))
  32. continue;
  33. break;
  34. } while(true);
  35. ChildKey = ((Symbol) list[0]).Name;
  36. ChildList = list;
  37. return true;
  38. }
  39. }
  40. }