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