source: pyyaml/branches/working-on-emitter/lib/yaml/tokens.py @ 122

Revision 122, 2.3 KB checked in by xi, 9 years ago (diff)

Add a skeleton of the emitter.

RevLine 
[46]1
2class Token:
[122]3    def __init__(self, start_mark=None, end_mark=None):
[116]4        self.start_mark = start_mark
5        self.end_mark = end_mark
[51]6    def __repr__(self):
7        attributes = [key for key in self.__dict__
[116]8                if not key.endswith('_mark')]
[51]9        attributes.sort()
10        arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
11                for key in attributes])
12        return '%s(%s)' % (self.__class__.__name__, arguments)
[46]13
[51]14#class BOMToken(Token):
15#    id = '<byte order mark>'
16
[46]17class DirectiveToken(Token):
[51]18    id = '<directive>'
[122]19    def __init__(self, name, value, start_mark=None, end_mark=None):
[46]20        self.name = name
[48]21        self.value = value
[116]22        self.start_mark = start_mark
23        self.end_mark = end_mark
[46]24
25class DocumentStartToken(Token):
[51]26    id = '<document start>'
[46]27
28class DocumentEndToken(Token):
[51]29    id = '<document end>'
[46]30
[118]31class StreamStartToken(Token):
32    id = '<stream start>'
33
[47]34class StreamEndToken(Token):
[51]35    id = '<stream end>'
[46]36
37class BlockSequenceStartToken(Token):
[51]38    id = '<block sequence start>'
[46]39
40class BlockMappingStartToken(Token):
[52]41    id = '<block mapping start>'
[46]42
43class BlockEndToken(Token):
[51]44    id = '<block end>'
[46]45
46class FlowSequenceStartToken(Token):
[51]47    id = '['
[46]48
49class FlowMappingStartToken(Token):
[51]50    id = '{'
[46]51
52class FlowSequenceEndToken(Token):
[51]53    id = ']'
[46]54
55class FlowMappingEndToken(Token):
[51]56    id = '}'
[46]57
58class KeyToken(Token):
[51]59    id = '?'
[46]60
61class ValueToken(Token):
[51]62    id = ':'
[46]63
[51]64class BlockEntryToken(Token):
65    id = '-'
[46]66
[51]67class FlowEntryToken(Token):
68    id = ','
69
[46]70class AliasToken(Token):
[51]71    id = '<alias>'
[122]72    def __init__(self, value, start_mark=None, end_mark=None):
[46]73        self.value = value
[116]74        self.start_mark = start_mark
75        self.end_mark = end_mark
[46]76
77class AnchorToken(Token):
[51]78    id = '<anchor>'
[122]79    def __init__(self, value, start_mark=None, end_mark=None):
[46]80        self.value = value
[116]81        self.start_mark = start_mark
82        self.end_mark = end_mark
[46]83
84class TagToken(Token):
[51]85    id = '<tag>'
[122]86    def __init__(self, value, start_mark=None, end_mark=None):
[46]87        self.value = value
[116]88        self.start_mark = start_mark
89        self.end_mark = end_mark
[46]90
91class ScalarToken(Token):
[51]92    id = '<scalar>'
[122]93    def __init__(self, value, plain, start_mark=None, end_mark=None):
[46]94        self.value = value
95        self.plain = plain
[116]96        self.start_mark = start_mark
97        self.end_mark = end_mark
[46]98
Note: See TracBrowser for help on using the repository browser.