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

Commit

Permalink
Allow select cases to be numbers (#116625)
Browse files Browse the repository at this point in the history
  • Loading branch information
thkim1011 committed Jan 10, 2023
1 parent ad7322d commit 583a812
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -70,6 +70,7 @@ Map<ST, List<List<ST>>> grammar = <ST, List<List<ST>>>{
],
ST.selectPart: <List<ST>>[
<ST>[ST.identifier, ST.openBrace, ST.message, ST.closeBrace],
<ST>[ST.number, ST.openBrace, ST.message, ST.closeBrace],
<ST>[ST.other, ST.openBrace, ST.message, ST.closeBrace],
],
};
Expand Down Expand Up @@ -408,6 +409,7 @@ class Parser {
case ST.selectParts:
if (tokens.isNotEmpty && (
tokens[0].type == ST.identifier ||
tokens[0].type == ST.number ||
tokens[0].type == ST.other
)) {
parseAndConstructNode(ST.selectParts, 0);
Expand All @@ -418,8 +420,10 @@ class Parser {
case ST.selectPart:
if (tokens.isNotEmpty && tokens[0].type == ST.identifier) {
parseAndConstructNode(ST.selectPart, 0);
} else if (tokens.isNotEmpty && tokens[0].type == ST.other) {
} else if (tokens.isNotEmpty && tokens[0].type == ST.number) {
parseAndConstructNode(ST.selectPart, 1);
} else if (tokens.isNotEmpty && tokens[0].type == ST.other) {
parseAndConstructNode(ST.selectPart, 2);
} else {
throw L10nParserException(
'ICU Syntax Error: Select parts must be of the form "identifier { message }"',
Expand Down Expand Up @@ -581,6 +585,10 @@ class Parser {
checkExtraRules(syntaxTree);
return syntaxTree;
} on L10nParserException catch (error) {
// For debugging purposes.
if (logger == null) {
rethrow;
}
logger?.printError(error.toString());
return Node(ST.empty, 0, value: '');
}
Expand Down
11 changes: 11 additions & 0 deletions packages/flutter_tools/test/general.shard/message_parser_test.dart
Expand Up @@ -503,4 +503,15 @@ void main() {
contains(expectedError3),
)));
});

testWithoutContext('parser allows select cases with numbers', () {
final Node node = Parser('numberSelect', 'app_en.arb', '{ count, select, 0{none} 100{perfect} other{required!} }').parse();
final Node selectExpr = node.children[0];
final Node selectParts = selectExpr.children[5];
final Node selectPart = selectParts.children[0];
expect(selectPart.children[0].value, equals('0'));
expect(selectPart.children[1].value, equals('{'));
expect(selectPart.children[2].type, equals(ST.message));
expect(selectPart.children[3].value, equals('}'));
});
}

0 comments on commit 583a812

Please sign in to comment.