@@ -101,10 +101,12 @@ def get_entry(self, ps):
101
101
ps .expect_char ('\n ' if ps .current () else None )
102
102
103
103
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
108
110
109
111
if ps .is_entry_id_start () \
110
112
and (comment is None or isinstance (comment , ast .Comment )):
@@ -182,7 +184,8 @@ def get_comment(self, ps):
182
184
elif level == 2 :
183
185
return ast .ResourceComment (content )
184
186
185
- def skip_section (self , ps ):
187
+ @with_span
188
+ def get_group_comment_from_section (self , ps , comment ):
186
189
ps .expect_char ('[' )
187
190
ps .expect_char ('[' )
188
191
@@ -195,8 +198,12 @@ def skip_section(self, ps):
195
198
ps .expect_char (']' )
196
199
ps .expect_char (']' )
197
200
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 ('' )
200
207
201
208
@with_span
202
209
def get_message (self , ps , comment ):
@@ -231,7 +238,6 @@ def get_message(self, ps, comment):
231
238
232
239
@with_span
233
240
def get_attribute (self , ps ):
234
- ps .expect_indent ()
235
241
ps .expect_char ('.' )
236
242
237
243
key = self .get_identifier (ps )
@@ -250,6 +256,7 @@ def get_attributes(self, ps):
250
256
attrs = []
251
257
252
258
while True :
259
+ ps .expect_indent ()
253
260
attr = self .get_attribute (ps )
254
261
attrs .append (attr )
255
262
@@ -287,8 +294,6 @@ def get_variant_key(self, ps):
287
294
288
295
@with_span
289
296
def get_variant (self , ps , has_default ):
290
- ps .expect_indent ()
291
-
292
297
default_index = False
293
298
294
299
if ps .current_is ('*' ):
@@ -315,6 +320,7 @@ def get_variants(self, ps):
315
320
has_default = False
316
321
317
322
while True :
323
+ ps .expect_indent ()
318
324
variant = self .get_variant (ps , has_default )
319
325
320
326
if variant .default :
0 commit comments