@@ -101,10 +101,12 @@ def get_entry(self, ps):
101101 ps .expect_char ('\n ' if ps .current () else None )
102102
103103 if ps .current_is ('[' ):
104- self .skip_section (ps )
105- if comment :
106- return ast .GroupComment (comment .content )
107- return None
104+ group_comment = self .get_group_comment_from_section (ps , comment )
105+ if comment and self .with_spans :
106+ # The Group Comment should start where the section comment
107+ # starts.
108+ group_comment .span .start = comment .span .start
109+ return group_comment
108110
109111 if ps .is_entry_id_start () \
110112 and (comment is None or isinstance (comment , ast .Comment )):
@@ -182,7 +184,8 @@ def get_comment(self, ps):
182184 elif level == 2 :
183185 return ast .ResourceComment (content )
184186
185- def skip_section (self , ps ):
187+ @with_span
188+ def get_group_comment_from_section (self , ps , comment ):
186189 ps .expect_char ('[' )
187190 ps .expect_char ('[' )
188191
@@ -195,8 +198,12 @@ def skip_section(self, ps):
195198 ps .expect_char (']' )
196199 ps .expect_char (']' )
197200
198- ps .skip_inline_ws ()
199- ps .next ()
201+ if comment :
202+ return ast .GroupComment (comment .content )
203+
204+ # A Section without a comment is like an empty Group Comment.
205+ # Semantically it ends the previous group and starts a new one.
206+ return ast .GroupComment ('' )
200207
201208 @with_span
202209 def get_message (self , ps , comment ):
@@ -231,7 +238,6 @@ def get_message(self, ps, comment):
231238
232239 @with_span
233240 def get_attribute (self , ps ):
234- ps .expect_indent ()
235241 ps .expect_char ('.' )
236242
237243 key = self .get_identifier (ps )
@@ -250,6 +256,7 @@ def get_attributes(self, ps):
250256 attrs = []
251257
252258 while True :
259+ ps .expect_indent ()
253260 attr = self .get_attribute (ps )
254261 attrs .append (attr )
255262
@@ -287,8 +294,6 @@ def get_variant_key(self, ps):
287294
288295 @with_span
289296 def get_variant (self , ps , has_default ):
290- ps .expect_indent ()
291-
292297 default_index = False
293298
294299 if ps .current_is ('*' ):
@@ -315,6 +320,7 @@ def get_variants(self, ps):
315320 has_default = False
316321
317322 while True :
323+ ps .expect_indent ()
318324 variant = self .get_variant (ps , has_default )
319325
320326 if variant .default :
0 commit comments