mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Allow select cases to be numbers (#116625)
This commit is contained in:
parent
ad7322ddbf
commit
583a8122bc
@ -70,6 +70,7 @@ Map<ST, List<List<ST>>> grammar = <ST, List<List<ST>>>{
|
|||||||
],
|
],
|
||||||
ST.selectPart: <List<ST>>[
|
ST.selectPart: <List<ST>>[
|
||||||
<ST>[ST.identifier, ST.openBrace, ST.message, ST.closeBrace],
|
<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],
|
<ST>[ST.other, ST.openBrace, ST.message, ST.closeBrace],
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@ -408,6 +409,7 @@ class Parser {
|
|||||||
case ST.selectParts:
|
case ST.selectParts:
|
||||||
if (tokens.isNotEmpty && (
|
if (tokens.isNotEmpty && (
|
||||||
tokens[0].type == ST.identifier ||
|
tokens[0].type == ST.identifier ||
|
||||||
|
tokens[0].type == ST.number ||
|
||||||
tokens[0].type == ST.other
|
tokens[0].type == ST.other
|
||||||
)) {
|
)) {
|
||||||
parseAndConstructNode(ST.selectParts, 0);
|
parseAndConstructNode(ST.selectParts, 0);
|
||||||
@ -418,8 +420,10 @@ class Parser {
|
|||||||
case ST.selectPart:
|
case ST.selectPart:
|
||||||
if (tokens.isNotEmpty && tokens[0].type == ST.identifier) {
|
if (tokens.isNotEmpty && tokens[0].type == ST.identifier) {
|
||||||
parseAndConstructNode(ST.selectPart, 0);
|
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);
|
parseAndConstructNode(ST.selectPart, 1);
|
||||||
|
} else if (tokens.isNotEmpty && tokens[0].type == ST.other) {
|
||||||
|
parseAndConstructNode(ST.selectPart, 2);
|
||||||
} else {
|
} else {
|
||||||
throw L10nParserException(
|
throw L10nParserException(
|
||||||
'ICU Syntax Error: Select parts must be of the form "identifier { message }"',
|
'ICU Syntax Error: Select parts must be of the form "identifier { message }"',
|
||||||
@ -581,6 +585,10 @@ class Parser {
|
|||||||
checkExtraRules(syntaxTree);
|
checkExtraRules(syntaxTree);
|
||||||
return syntaxTree;
|
return syntaxTree;
|
||||||
} on L10nParserException catch (error) {
|
} on L10nParserException catch (error) {
|
||||||
|
// For debugging purposes.
|
||||||
|
if (logger == null) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
logger?.printError(error.toString());
|
logger?.printError(error.toString());
|
||||||
return Node(ST.empty, 0, value: '');
|
return Node(ST.empty, 0, value: '');
|
||||||
}
|
}
|
||||||
|
@ -503,4 +503,15 @@ void main() {
|
|||||||
contains(expectedError3),
|
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('}'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user