source: pyyaml/trunk/lib/yaml/events.py @ 131

Revision 131, 2.5 KB checked in by xi, 8 years ago (diff)

Working on emitter: implement the state machine.

RevLine 
[51]1
[130]2# Abstract classes.
3
[51]4class Event:
[130]5    def __init__(self, start_mark=None, end_mark=None):
[116]6        self.start_mark = start_mark
7        self.end_mark = end_mark
[51]8    def __repr__(self):
[130]9        attributes = [key for key in ['anchor', 'tag', 'value']
10                if hasattr(self, key)]
[51]11        arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
12                for key in attributes])
13        return '%s(%s)' % (self.__class__.__name__, arguments)
14
15class NodeEvent(Event):
[130]16    def __init__(self, anchor, start_mark=None, end_mark=None):
[51]17        self.anchor = anchor
[116]18        self.start_mark = start_mark
19        self.end_mark = end_mark
[51]20
[130]21class CollectionStartEvent(NodeEvent):
22    def __init__(self, anchor, tag, start_mark=None, end_mark=None,
23            flow_style=None):
[51]24        self.anchor = anchor
25        self.tag = tag
[116]26        self.start_mark = start_mark
27        self.end_mark = end_mark
[130]28        self.flow_style = flow_style
[51]29
[130]30class CollectionEndEvent(Event):
31    pass
32
33# Implementations.
34
35class StreamStartEvent(Event):
36    def __init__(self, start_mark=None, end_mark=None,
[131]37            encoding=None, line_break=None, canonical=None,
38            indent=None, width=None):
[116]39        self.start_mark = start_mark
40        self.end_mark = end_mark
[130]41        self.encoding = encoding
[131]42        self.line_break = line_break
[130]43        self.canonical = canonical
44        self.indent = indent
45        self.width = width
[51]46
[130]47class StreamEndEvent(Event):
[51]48    pass
49
[130]50class DocumentStartEvent(Event):
51    def __init__(self, start_mark=None, end_mark=None,
52            implicit=None, version=None, tags=None):
53        self.start_mark = start_mark
54        self.end_mark = end_mark
55        self.implicit = implicit
56        self.version = version
57        self.tags = tags
[51]58
[130]59class DocumentEndEvent(Event):
60    def __init__(self, start_mark=None, end_mark=None,
61            implicit=None):
62        self.start_mark = start_mark
63        self.end_mark = end_mark
64        self.implicit = implicit
65
66class AliasEvent(NodeEvent):
[51]67    pass
68
[130]69class ScalarEvent(NodeEvent):
70    def __init__(self, anchor, tag, value, start_mark=None, end_mark=None,
71            implicit=None, style=None):
72        self.anchor = anchor
73        self.tag = tag
74        self.value = value
75        self.start_mark = start_mark
76        self.end_mark = end_mark
77        self.implicit = implicit
78        self.style = style
79
80class SequenceStartEvent(CollectionStartEvent):
[118]81    pass
82
[130]83class SequenceEndEvent(CollectionEndEvent):
[118]84    pass
85
[130]86class MappingStartEvent(CollectionStartEvent):
[118]87    pass
88
[130]89class MappingEndEvent(CollectionEndEvent):
[51]90    pass
91
Note: See TracBrowser for help on using the repository browser.