Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 583a812

Browse files
authored
Allow select cases to be numbers (#116625)
1 parent ad7322d commit 583a812

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/flutter_tools/lib/src/localizations/message_parser.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Map<ST, List<List<ST>>> grammar = <ST, List<List<ST>>>{
7070
],
7171
ST.selectPart: <List<ST>>[
7272
<ST>[ST.identifier, ST.openBrace, ST.message, ST.closeBrace],
73+
<ST>[ST.number, ST.openBrace, ST.message, ST.closeBrace],
7374
<ST>[ST.other, ST.openBrace, ST.message, ST.closeBrace],
7475
],
7576
};
@@ -408,6 +409,7 @@ class Parser {
408409
case ST.selectParts:
409410
if (tokens.isNotEmpty && (
410411
tokens[0].type == ST.identifier ||
412+
tokens[0].type == ST.number ||
411413
tokens[0].type == ST.other
412414
)) {
413415
parseAndConstructNode(ST.selectParts, 0);
@@ -418,8 +420,10 @@ class Parser {
418420
case ST.selectPart:
419421
if (tokens.isNotEmpty && tokens[0].type == ST.identifier) {
420422
parseAndConstructNode(ST.selectPart, 0);
421-
} else if (tokens.isNotEmpty && tokens[0].type == ST.other) {
423+
} else if (tokens.isNotEmpty && tokens[0].type == ST.number) {
422424
parseAndConstructNode(ST.selectPart, 1);
425+
} else if (tokens.isNotEmpty && tokens[0].type == ST.other) {
426+
parseAndConstructNode(ST.selectPart, 2);
423427
} else {
424428
throw L10nParserException(
425429
'ICU Syntax Error: Select parts must be of the form "identifier { message }"',
@@ -581,6 +585,10 @@ class Parser {
581585
checkExtraRules(syntaxTree);
582586
return syntaxTree;
583587
} on L10nParserException catch (error) {
588+
// For debugging purposes.
589+
if (logger == null) {
590+
rethrow;
591+
}
584592
logger?.printError(error.toString());
585593
return Node(ST.empty, 0, value: '');
586594
}

packages/flutter_tools/test/general.shard/message_parser_test.dart

+11
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,15 @@ void main() {
503503
contains(expectedError3),
504504
)));
505505
});
506+
507+
testWithoutContext('parser allows select cases with numbers', () {
508+
final Node node = Parser('numberSelect', 'app_en.arb', '{ count, select, 0{none} 100{perfect} other{required!} }').parse();
509+
final Node selectExpr = node.children[0];
510+
final Node selectParts = selectExpr.children[5];
511+
final Node selectPart = selectParts.children[0];
512+
expect(selectPart.children[0].value, equals('0'));
513+
expect(selectPart.children[1].value, equals('{'));
514+
expect(selectPart.children[2].type, equals(ST.message));
515+
expect(selectPart.children[3].value, equals('}'));
516+
});
506517
}

0 commit comments

Comments
 (0)