@@ -56,8 +56,6 @@ def parse(self, source):
5656 entries .append (entry )
5757
5858 ps .last_comment_zero_four_syntax = False
59-
60- ps .skip_inline_ws ()
6159 ps .skip_blank_lines ()
6260
6361 res = ast .Resource (entries )
@@ -209,12 +207,13 @@ def get_message(self, ps, comment):
209207 pattern = None
210208 attrs = None
211209
210+ # XXX Syntax 0.4 compat
212211 if ps .current_is ('=' ):
213212 ps .next ()
214- ps .skip_inline_ws ()
215- ps .skip_blank_lines ()
216213
217- pattern = self .get_pattern (ps )
214+ if ps .is_peek_pattern_start ():
215+ ps .skip_indent ()
216+ pattern = self .get_pattern (ps )
218217
219218 if ps .is_peek_next_line_attribute_start ():
220219 attrs = self .get_attributes (ps )
@@ -226,27 +225,25 @@ def get_message(self, ps, comment):
226225
227226 @with_span
228227 def get_attribute (self , ps ):
228+ ps .expect_indent ()
229229 ps .expect_char ('.' )
230230
231231 key = self .get_public_identifier (ps )
232232
233233 ps .skip_inline_ws ()
234234 ps .expect_char ('=' )
235- ps .skip_inline_ws ()
236235
237- value = self .get_pattern (ps )
236+ if ps .is_peek_pattern_start ():
237+ ps .skip_indent ()
238+ value = self .get_pattern (ps )
239+ return ast .Attribute (key , value )
238240
239- if value is None :
240- raise ParseError ('E0006' , 'value' )
241-
242- return ast .Attribute (key , value )
241+ raise ParseError ('E0006' , 'value' )
243242
244243 def get_attributes (self , ps ):
245244 attrs = []
246245
247246 while True :
248- ps .expect_indent ()
249-
250247 attr = self .get_attribute (ps )
251248 attrs .append (attr )
252249
@@ -288,6 +285,8 @@ def get_variant_key(self, ps):
288285
289286 @with_span
290287 def get_variant (self , ps , has_default ):
288+ ps .expect_indent ()
289+
291290 default_index = False
292291
293292 if ps .current_is ('*' ):
@@ -302,22 +301,18 @@ def get_variant(self, ps, has_default):
302301
303302 ps .expect_char (']' )
304303
305- ps .skip_inline_ws ()
306-
307- value = self .get_pattern (ps )
308-
309- if value is None :
310- raise ParseError ('E0006' , 'value' )
304+ if ps .is_peek_pattern_start ():
305+ ps .skip_indent ()
306+ value = self .get_pattern (ps )
307+ return ast .Variant (key , value , default_index )
311308
312- return ast . Variant ( key , value , default_index )
309+ raise ParseError ( 'E0006' , ' value' )
313310
314311 def get_variants (self , ps ):
315312 variants = []
316313 has_default = False
317314
318315 while True :
319- ps .expect_indent ()
320-
321316 variant = self .get_variant (ps , has_default )
322317
323318 if variant .default :
@@ -383,17 +378,12 @@ def get_pattern(self, ps):
383378 elements = []
384379 ps .skip_inline_ws ()
385380
386- # Special-case: trim leading whitespace and newlines.
387- if ps .is_peek_next_non_blank_line_pattern ():
388- ps .skip_blank_lines ()
389- ps .skip_inline_ws ()
390-
391381 while ps .current ():
392382 ch = ps .current ()
393383
394384 # The end condition for get_pattern's while loop is a newline
395385 # which is not followed by a valid pattern continuation.
396- if ch == '\n ' and not ps .is_peek_next_non_blank_line_pattern ():
386+ if ch == '\n ' and not ps .is_peek_next_line_pattern_start ():
397387 break
398388
399389 if ch == '{' :
@@ -416,7 +406,7 @@ def get_text_element(self, ps):
416406 return ast .TextElement (buf )
417407
418408 if ch == '\n ' :
419- if not ps .is_peek_next_non_blank_line_pattern ():
409+ if not ps .is_peek_next_line_pattern_start ():
420410 return ast .TextElement (buf )
421411
422412 ps .next ()
0 commit comments