Index: pyyaml/trunk/lib/yaml/composer.py
===================================================================
--- pyyaml/trunk/lib/yaml/composer.py	(revision 137)
+++ pyyaml/trunk/lib/yaml/composer.py	(revision 142)
@@ -12,6 +12,5 @@
 
     def __init__(self):
-        self.all_anchors = {}
-        self.complete_anchors = {}
+        self.anchors = {}
 
     def check_node(self):
@@ -44,5 +43,4 @@
         self.get_event()
 
-        self.all_anchors = {}
         self.complete_anchors = {}
         return node
@@ -52,43 +50,37 @@
             event = self.get_event()
             anchor = event.anchor
-            if anchor not in self.all_anchors:
+            if anchor not in self.anchors:
                 raise ComposerError(None, None, "found undefined alias %r"
                         % anchor.encode('utf-8'), event.start_mark)
-            if anchor not in self.complete_anchors:
-                collection_event = self.all_anchors[anchor]
-                raise ComposerError("while composing a collection",
-                        collection_event.start_mark,
-                        "found recursive anchor %r" % anchor.encode('utf-8'),
-                        event.start_mark)
-            return self.complete_anchors[anchor]
+            return self.anchors[anchor]
         event = self.peek_event()
         anchor = event.anchor
         if anchor is not None:
-            if anchor in self.all_anchors:
+            if anchor in self.anchors:
                 raise ComposerError("found duplicate anchor %r; first occurence"
-                        % anchor.encode('utf-8'), self.all_anchors[anchor].start_mark,
+                        % anchor.encode('utf-8'), self.anchors[anchor].start_mark,
                         "second occurence", event.start_mark)
-            self.all_anchors[anchor] = event
         self.descend_resolver(parent, index)
         if self.check_event(ScalarEvent):
-            node = self.compose_scalar_node()
+            node = self.compose_scalar_node(anchor)
         elif self.check_event(SequenceStartEvent):
-            node = self.compose_sequence_node()
+            node = self.compose_sequence_node(anchor)
         elif self.check_event(MappingStartEvent):
-            node = self.compose_mapping_node()
-        if anchor is not None:
-            self.complete_anchors[anchor] = node
+            node = self.compose_mapping_node(anchor)
         self.ascend_resolver()
         return node
 
-    def compose_scalar_node(self):
+    def compose_scalar_node(self, anchor):
         event = self.get_event()
         tag = event.tag
         if tag is None or tag == u'!':
             tag = self.resolve(ScalarNode, event.value, event.implicit)
-        return ScalarNode(tag, event.value,
+        node = ScalarNode(tag, event.value,
                 event.start_mark, event.end_mark, style=event.style)
+        if anchor is not None:
+            self.anchors[anchor] = node
+        return node
 
-    def compose_sequence_node(self):
+    def compose_sequence_node(self, anchor):
         start_event = self.get_event()
         tag = start_event.tag
@@ -98,4 +90,6 @@
                 start_event.start_mark, None,
                 flow_style=start_event.flow_style)
+        if anchor is not None:
+            self.anchors[anchor] = node
         index = 0
         while not self.check_event(SequenceEndEvent):
@@ -106,5 +100,5 @@
         return node
 
-    def compose_mapping_node(self):
+    def compose_mapping_node(self, anchor):
         start_event = self.get_event()
         tag = start_event.tag
@@ -114,4 +108,6 @@
                 start_event.start_mark, None,
                 flow_style=start_event.flow_style)
+        if anchor is not None:
+            self.anchors[anchor] = node
         while not self.check_event(MappingEndEvent):
             key_event = self.peek_event()
