@@ -227,7 +227,7 @@ export default class FluentParser {
227
227
ps . skipBlankInline ( ) ;
228
228
ps . expectChar ( "=" ) ;
229
229
230
- const value = this . maybeGetValue ( ps , { allowVariantList : false } ) ;
230
+ const value = this . maybeGetPattern ( ps ) ;
231
231
const attrs = this . getAttributes ( ps ) ;
232
232
233
233
if ( value === null && attrs . length === 0 ) {
@@ -244,11 +244,9 @@ export default class FluentParser {
244
244
ps . skipBlankInline ( ) ;
245
245
ps . expectChar ( "=" ) ;
246
246
247
- // XXX Once https://github.com/projectfluent/fluent/pull/220 lands,
248
- // getTerm will be the only place where VariantLists are still legal. Move
249
- // the code from getPatternOrVariantList up to here then, and remove the
250
- // allowVariantList switch.
251
- const value = this . maybeGetValue ( ps , { allowVariantList : true } ) ;
247
+ // Syntax 0.8 compat: VariantLists are supported but deprecated. They can
248
+ // only be found as values of Terms. Nested VariantLists are not allowed.
249
+ const value = this . maybeGetVariantList ( ps ) || this . maybeGetPattern ( ps ) ;
252
250
if ( value === null ) {
253
251
throw new ParseError ( "E0006" , id . name ) ;
254
252
}
@@ -265,7 +263,7 @@ export default class FluentParser {
265
263
ps . skipBlankInline ( ) ;
266
264
ps . expectChar ( "=" ) ;
267
265
268
- const value = this . maybeGetValue ( ps , { allowVariantList : false } ) ;
266
+ const value = this . maybeGetPattern ( ps ) ;
269
267
if ( value === null ) {
270
268
throw new ParseError ( "E0012" ) ;
271
269
}
@@ -312,7 +310,7 @@ export default class FluentParser {
312
310
return this . getIdentifier ( ps ) ;
313
311
}
314
312
315
- getVariant ( ps , { hasDefault, allowVariantList } ) {
313
+ getVariant ( ps , { hasDefault} ) {
316
314
let defaultIndex = false ;
317
315
318
316
if ( ps . currentChar === "*" ) {
@@ -333,23 +331,21 @@ export default class FluentParser {
333
331
ps . skipBlank ( ) ;
334
332
ps . expectChar ( "]" ) ;
335
333
336
- // XXX We need to pass allowVariantList all the way down to here because
337
- // nested VariantLists in Terms are legal for now.
338
- const value = this . maybeGetValue ( ps , { allowVariantList} ) ;
334
+ const value = this . maybeGetPattern ( ps ) ;
339
335
if ( value === null ) {
340
336
throw new ParseError ( "E0012" ) ;
341
337
}
342
338
343
339
return new AST . Variant ( key , value , defaultIndex ) ;
344
340
}
345
341
346
- getVariants ( ps , { allowVariantList } ) {
342
+ getVariants ( ps ) {
347
343
const variants = [ ] ;
348
344
let hasDefault = false ;
349
345
350
346
ps . skipBlank ( ) ;
351
347
while ( ps . isVariantStart ( ) ) {
352
- const variant = this . getVariant ( ps , { allowVariantList , hasDefault} ) ;
348
+ const variant = this . getVariant ( ps , { hasDefault} ) ;
353
349
354
350
if ( variant . default ) {
355
351
hasDefault = true ;
@@ -405,34 +401,34 @@ export default class FluentParser {
405
401
return new AST . NumberLiteral ( num ) ;
406
402
}
407
403
408
- // maybeGetValue distinguishes between patterns which start on the same line
404
+ // maybeGetPattern distinguishes between patterns which start on the same line
409
405
// as the identifier (a.k.a. inline signleline patterns and inline multiline
410
406
// patterns) and patterns which start on a new line (a.k.a. block multiline
411
407
// patterns). The distinction is important for the dedentation logic: the
412
408
// indent of the first line of a block pattern must be taken into account when
413
409
// calculating the maximum common indent.
414
- maybeGetValue ( ps , { allowVariantList } ) {
410
+ maybeGetPattern ( ps ) {
415
411
ps . peekBlankInline ( ) ;
416
412
if ( ps . isValueStart ( ) ) {
417
413
ps . skipToPeek ( ) ;
418
- return this . getPatternOrVariantList (
419
- ps , { isBlock : false , allowVariantList} ) ;
414
+ return this . getPattern ( ps , { isBlock : false } ) ;
420
415
}
421
416
422
417
ps . peekBlankBlock ( ) ;
423
418
if ( ps . isValueContinuation ( ) ) {
424
419
ps . skipToPeek ( ) ;
425
- return this . getPatternOrVariantList (
426
- ps , { isBlock : true , allowVariantList} ) ;
420
+ return this . getPattern ( ps , { isBlock : true } ) ;
427
421
}
428
422
429
423
return null ;
430
424
}
431
425
432
- // Parse a VariantList (if allowed) or a Pattern.
433
- getPatternOrVariantList ( ps , { isBlock, allowVariantList} ) {
434
- ps . peekBlankInline ( ) ;
435
- if ( allowVariantList && ps . currentPeek === "{" ) {
426
+ // Deprecated in Syntax 0.8. VariantLists are only allowed as values of Terms.
427
+ // Values of Messages, Attributes and Variants must be Patterns. This method
428
+ // is only used in getTerm.
429
+ maybeGetVariantList ( ps ) {
430
+ ps . peekBlank ( ) ;
431
+ if ( ps . currentPeek === "{" ) {
436
432
const start = ps . peekOffset ;
437
433
ps . peek ( ) ;
438
434
ps . peekBlankInline ( ) ;
@@ -441,19 +437,18 @@ export default class FluentParser {
441
437
if ( ps . isVariantStart ( ) ) {
442
438
ps . resetPeek ( start ) ;
443
439
ps . skipToPeek ( ) ;
444
- return this . getVariantList ( ps , { allowVariantList } ) ;
440
+ return this . getVariantList ( ps ) ;
445
441
}
446
442
}
447
443
}
448
444
449
445
ps . resetPeek ( ) ;
450
- const pattern = this . getPattern ( ps , { isBlock} ) ;
451
- return pattern ;
446
+ return null ;
452
447
}
453
448
454
449
getVariantList ( ps ) {
455
450
ps . expectChar ( "{" ) ;
456
- var variants = this . getVariants ( ps , { allowVariantList : true } ) ;
451
+ var variants = this . getVariants ( ps ) ;
457
452
ps . expectChar ( "}" ) ;
458
453
return new AST . VariantList ( variants ) ;
459
454
}
@@ -679,7 +674,7 @@ export default class FluentParser {
679
674
ps . skipBlankInline ( ) ;
680
675
ps . expectLineEnd ( ) ;
681
676
682
- const variants = this . getVariants ( ps , { allowVariantList : false } ) ;
677
+ const variants = this . getVariants ( ps ) ;
683
678
return new AST . SelectExpression ( selector , variants ) ;
684
679
}
685
680
0 commit comments