Unverified Commit 583a8122 authored by Tae Hyung Kim's avatar Tae Hyung Kim Committed by GitHub

Allow select cases to be numbers (#116625)

parent ad7322dd
......@@ -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],
],
};
......@@ -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);
......@@ -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 }"',
......@@ -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: '');
}
......
......@@ -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('}'));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment