Changeset 142 for pyyaml/trunk/lib/yaml/composer.py
- Timestamp:
- 04/18/06 13:15:54 (7 years ago)
- File:
-
- 1 edited
-
pyyaml/trunk/lib/yaml/composer.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/lib/yaml/composer.py
r137 r142 12 12 13 13 def __init__(self): 14 self.all_anchors = {} 15 self.complete_anchors = {} 14 self.anchors = {} 16 15 17 16 def check_node(self): … … 44 43 self.get_event() 45 44 46 self.all_anchors = {}47 45 self.complete_anchors = {} 48 46 return node … … 52 50 event = self.get_event() 53 51 anchor = event.anchor 54 if anchor not in self.a ll_anchors:52 if anchor not in self.anchors: 55 53 raise ComposerError(None, None, "found undefined alias %r" 56 54 % anchor.encode('utf-8'), event.start_mark) 57 if anchor not in self.complete_anchors: 58 collection_event = self.all_anchors[anchor] 59 raise ComposerError("while composing a collection", 60 collection_event.start_mark, 61 "found recursive anchor %r" % anchor.encode('utf-8'), 62 event.start_mark) 63 return self.complete_anchors[anchor] 55 return self.anchors[anchor] 64 56 event = self.peek_event() 65 57 anchor = event.anchor 66 58 if anchor is not None: 67 if anchor in self.a ll_anchors:59 if anchor in self.anchors: 68 60 raise ComposerError("found duplicate anchor %r; first occurence" 69 % anchor.encode('utf-8'), self.a ll_anchors[anchor].start_mark,61 % anchor.encode('utf-8'), self.anchors[anchor].start_mark, 70 62 "second occurence", event.start_mark) 71 self.all_anchors[anchor] = event72 63 self.descend_resolver(parent, index) 73 64 if self.check_event(ScalarEvent): 74 node = self.compose_scalar_node( )65 node = self.compose_scalar_node(anchor) 75 66 elif self.check_event(SequenceStartEvent): 76 node = self.compose_sequence_node( )67 node = self.compose_sequence_node(anchor) 77 68 elif self.check_event(MappingStartEvent): 78 node = self.compose_mapping_node() 79 if anchor is not None: 80 self.complete_anchors[anchor] = node 69 node = self.compose_mapping_node(anchor) 81 70 self.ascend_resolver() 82 71 return node 83 72 84 def compose_scalar_node(self ):73 def compose_scalar_node(self, anchor): 85 74 event = self.get_event() 86 75 tag = event.tag 87 76 if tag is None or tag == u'!': 88 77 tag = self.resolve(ScalarNode, event.value, event.implicit) 89 returnScalarNode(tag, event.value,78 node = ScalarNode(tag, event.value, 90 79 event.start_mark, event.end_mark, style=event.style) 80 if anchor is not None: 81 self.anchors[anchor] = node 82 return node 91 83 92 def compose_sequence_node(self ):84 def compose_sequence_node(self, anchor): 93 85 start_event = self.get_event() 94 86 tag = start_event.tag … … 98 90 start_event.start_mark, None, 99 91 flow_style=start_event.flow_style) 92 if anchor is not None: 93 self.anchors[anchor] = node 100 94 index = 0 101 95 while not self.check_event(SequenceEndEvent): … … 106 100 return node 107 101 108 def compose_mapping_node(self ):102 def compose_mapping_node(self, anchor): 109 103 start_event = self.get_event() 110 104 tag = start_event.tag … … 114 108 start_event.start_mark, None, 115 109 flow_style=start_event.flow_style) 110 if anchor is not None: 111 self.anchors[anchor] = node 116 112 while not self.check_event(MappingEndEvent): 117 113 key_event = self.peek_event()
Note: See TracChangeset
for help on using the changeset viewer.
