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

Revision 127, 3.1 KB checked in by xi, 8 years ago (diff)

Parser now provides style information. Allow empty plain scalars if a tag or anchor is given.

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>'
[127]27    def __init__(self, name, value, start_mark=None, end_mark=None):
28        self.name = name
29        self.value = value
30        self.start_mark = start_mark
31        self.end_mark = end_mark
[46]32
33class DocumentEndToken(Token):
[51]34    id = '<document end>'
[46]35
[118]36class StreamStartToken(Token):
37    id = '<stream start>'
[127]38    def __init__(self, start_mark=None, end_mark=None,
39            encoding=None):
40        self.start_mark = start_mark
41        self.end_mark = end_mark
42        self.encoding = encoding
[118]43
[47]44class StreamEndToken(Token):
[51]45    id = '<stream end>'
[46]46
47class BlockSequenceStartToken(Token):
[51]48    id = '<block sequence start>'
[127]49    def __init__(self, start_mark=None, end_mark=None,
50            inline=None):
51        self.start_mark = start_mark
52        self.end_mark = end_mark
53        self.inline = inline
[46]54
55class BlockMappingStartToken(Token):
[52]56    id = '<block mapping start>'
[127]57    def __init__(self, start_mark=None, end_mark=None,
58            inline=None):
59        self.start_mark = start_mark
60        self.end_mark = end_mark
61        self.inline = inline
[46]62
63class BlockEndToken(Token):
[51]64    id = '<block end>'
[46]65
66class FlowSequenceStartToken(Token):
[51]67    id = '['
[46]68
69class FlowMappingStartToken(Token):
[51]70    id = '{'
[46]71
72class FlowSequenceEndToken(Token):
[51]73    id = ']'
[46]74
75class FlowMappingEndToken(Token):
[51]76    id = '}'
[46]77
78class KeyToken(Token):
[51]79    id = '?'
[46]80
81class ValueToken(Token):
[51]82    id = ':'
[46]83
[51]84class BlockEntryToken(Token):
85    id = '-'
[46]86
[51]87class FlowEntryToken(Token):
88    id = ','
89
[46]90class AliasToken(Token):
[51]91    id = '<alias>'
[122]92    def __init__(self, value, start_mark=None, end_mark=None):
[46]93        self.value = value
[116]94        self.start_mark = start_mark
95        self.end_mark = end_mark
[46]96
97class AnchorToken(Token):
[51]98    id = '<anchor>'
[122]99    def __init__(self, value, start_mark=None, end_mark=None):
[46]100        self.value = value
[116]101        self.start_mark = start_mark
102        self.end_mark = end_mark
[46]103
104class TagToken(Token):
[51]105    id = '<tag>'
[122]106    def __init__(self, value, start_mark=None, end_mark=None):
[46]107        self.value = value
[116]108        self.start_mark = start_mark
109        self.end_mark = end_mark
[46]110
111class ScalarToken(Token):
[51]112    id = '<scalar>'
[127]113    def __init__(self, value, plain, start_mark=None, end_mark=None,
114            style=None):
[46]115        self.value = value
116        self.plain = plain
[116]117        self.start_mark = start_mark
118        self.end_mark = end_mark
[127]119        self.style = style
[46]120
Note: See TracBrowser for help on using the repository browser.