@@ -9,7 +9,8 @@ class Token(object):
9
9
"""
10
10
11
11
def __init__ (self , name , kind , serialization_code , unprefixed_kind = None ,
12
- text = None , classification = 'None' , is_keyword = False ):
12
+ text = None , classification = 'None' , is_keyword = False ,
13
+ requires_leading_space = False , requires_trailing_space = False ):
13
14
self .name = name
14
15
self .kind = kind
15
16
if unprefixed_kind is None :
@@ -20,6 +21,8 @@ def __init__(self, name, kind, serialization_code, unprefixed_kind=None,
20
21
self .text = text or ""
21
22
self .classification = classification_by_name (classification )
22
23
self .is_keyword = is_keyword
24
+ self .requires_leading_space = requires_leading_space
25
+ self .requires_trailing_space = requires_trailing_space
23
26
24
27
def swift_kind (self ):
25
28
name = lowercase_first_word (self .name )
@@ -37,7 +40,8 @@ def __init__(self, name, text, serialization_code,
37
40
classification = 'Keyword' ):
38
41
Token .__init__ (self , name , 'kw_' + text , serialization_code ,
39
42
unprefixed_kind = text , text = text ,
40
- classification = classification , is_keyword = True )
43
+ classification = classification , is_keyword = True ,
44
+ requires_trailing_space = True )
41
45
42
46
def macro_name (self ):
43
47
return "KEYWORD"
@@ -78,7 +82,8 @@ def __init__(self, name, kind, text, serialization_code,
78
82
classification = 'Keyword' ):
79
83
Token .__init__ (self , name , 'pound_' + kind , serialization_code ,
80
84
unprefixed_kind = kind , text = text ,
81
- classification = classification , is_keyword = True )
85
+ classification = classification , is_keyword = True ,
86
+ requires_trailing_space = True )
82
87
83
88
def macro_name (self ):
84
89
return "POUND_KEYWORD"
@@ -215,24 +220,31 @@ def macro_name(self):
215
220
serialization_code = 92 ),
216
221
Punctuator ('RightSquareBracket' , 'r_square' , text = ']' ,
217
222
serialization_code = 93 ),
218
- Punctuator ('LeftAngle' , 'l_angle' , text = '<' , serialization_code = 94 ),
219
- Punctuator ('RightAngle' , 'r_angle' , text = '>' , serialization_code = 95 ),
223
+ Punctuator ('LeftAngle' , 'l_angle' , text = '<' , requires_leading_space = True ,
224
+ requires_trailing_space = True , serialization_code = 94 ),
225
+ Punctuator ('RightAngle' , 'r_angle' , text = '>' , requires_leading_space = True ,
226
+ requires_trailing_space = True , serialization_code = 95 ),
220
227
221
228
Punctuator ('Period' , 'period' , text = '.' , serialization_code = 85 ),
222
229
Punctuator ('PrefixPeriod' , 'period_prefix' , text = '.' ,
223
230
serialization_code = 87 ),
224
- Punctuator ('Comma' , 'comma' , text = ',' , serialization_code = 84 ),
231
+ Punctuator ('Comma' , 'comma' , text = ',' , requires_trailing_space = True ,
232
+ serialization_code = 84 ),
225
233
Punctuator ('Ellipsis' , 'ellipsis' , text = '...' , serialization_code = 118 ),
226
- Punctuator ('Colon' , 'colon' , text = ':' , serialization_code = 82 ),
234
+ Punctuator ('Colon' , 'colon' , text = ':' , requires_trailing_space = True ,
235
+ serialization_code = 82 ),
227
236
Punctuator ('Semicolon' , 'semi' , text = ';' , serialization_code = 83 ),
228
- Punctuator ('Equal' , 'equal' , text = '=' , serialization_code = 86 ),
237
+ Punctuator ('Equal' , 'equal' , text = '=' , requires_leading_space = True ,
238
+ requires_trailing_space = True , serialization_code = 86 ),
229
239
Punctuator ('AtSign' , 'at_sign' , text = '@' , classification = 'Attribute' ,
230
240
serialization_code = 80 ),
231
241
Punctuator ('Pound' , 'pound' , text = '#' , serialization_code = 81 ),
232
242
233
243
Punctuator ('PrefixAmpersand' , 'amp_prefix' , text = '&' ,
244
+ requires_leading_space = True , requires_trailing_space = True ,
234
245
serialization_code = 96 ),
235
- Punctuator ('Arrow' , 'arrow' , text = '->' , serialization_code = 78 ),
246
+ Punctuator ('Arrow' , 'arrow' , text = '->' , requires_trailing_space = True ,
247
+ serialization_code = 78 ),
236
248
237
249
238
250
Punctuator ('Backtick' , 'backtick' , text = '`' , serialization_code = 79 ),
0 commit comments