@@ -9,7 +9,8 @@ class Token(object):
99 """
1010
1111 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 ):
1314 self .name = name
1415 self .kind = kind
1516 if unprefixed_kind is None :
@@ -20,6 +21,8 @@ def __init__(self, name, kind, serialization_code, unprefixed_kind=None,
2021 self .text = text or ""
2122 self .classification = classification_by_name (classification )
2223 self .is_keyword = is_keyword
24+ self .requires_leading_space = requires_leading_space
25+ self .requires_trailing_space = requires_trailing_space
2326
2427 def swift_kind (self ):
2528 name = lowercase_first_word (self .name )
@@ -37,7 +40,8 @@ def __init__(self, name, text, serialization_code,
3740 classification = 'Keyword' ):
3841 Token .__init__ (self , name , 'kw_' + text , serialization_code ,
3942 unprefixed_kind = text , text = text ,
40- classification = classification , is_keyword = True )
43+ classification = classification , is_keyword = True ,
44+ requires_trailing_space = True )
4145
4246 def macro_name (self ):
4347 return "KEYWORD"
@@ -78,7 +82,8 @@ def __init__(self, name, kind, text, serialization_code,
7882 classification = 'Keyword' ):
7983 Token .__init__ (self , name , 'pound_' + kind , serialization_code ,
8084 unprefixed_kind = kind , text = text ,
81- classification = classification , is_keyword = True )
85+ classification = classification , is_keyword = True ,
86+ requires_trailing_space = True )
8287
8388 def macro_name (self ):
8489 return "POUND_KEYWORD"
@@ -215,24 +220,31 @@ def macro_name(self):
215220 serialization_code = 92 ),
216221 Punctuator ('RightSquareBracket' , 'r_square' , text = ']' ,
217222 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 ),
220227
221228 Punctuator ('Period' , 'period' , text = '.' , serialization_code = 85 ),
222229 Punctuator ('PrefixPeriod' , 'period_prefix' , text = '.' ,
223230 serialization_code = 87 ),
224- Punctuator ('Comma' , 'comma' , text = ',' , serialization_code = 84 ),
231+ Punctuator ('Comma' , 'comma' , text = ',' , requires_trailing_space = True ,
232+ serialization_code = 84 ),
225233 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 ),
227236 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 ),
229239 Punctuator ('AtSign' , 'at_sign' , text = '@' , classification = 'Attribute' ,
230240 serialization_code = 80 ),
231241 Punctuator ('Pound' , 'pound' , text = '#' , serialization_code = 81 ),
232242
233243 Punctuator ('PrefixAmpersand' , 'amp_prefix' , text = '&' ,
244+ requires_leading_space = True , requires_trailing_space = True ,
234245 serialization_code = 96 ),
235- Punctuator ('Arrow' , 'arrow' , text = '->' , serialization_code = 78 ),
246+ Punctuator ('Arrow' , 'arrow' , text = '->' , requires_trailing_space = True ,
247+ serialization_code = 78 ),
236248
237249
238250 Punctuator ('Backtick' , 'backtick' , text = '`' , serialization_code = 79 ),
0 commit comments