checkExtraRules method

void checkExtraRules(
  1. Node syntaxTree
)

Implementation

void checkExtraRules(Node syntaxTree) {
  final children = syntaxTree.children;
  switch (syntaxTree.type) {
    case ST.pluralParts:
      // Must have an "other" case.
      if (children.every((Node node) => node.children[0].type != ST.other)) {
        throw L10nParserException(
            'ICU Syntax Error: Plural expressions must have an "other" case.',
            filename,
            messageId,
            messageString,
            syntaxTree.positionInMessage);
      }
      // Identifier must be one of "zero", "one", "two", "few", "many".
      for (final node in children) {
        final pluralPartFirstToken = node.children[0];
        const validIdentifiers = <String>[
          'zero',
          'one',
          'two',
          'few',
          'many'
        ];
        if (pluralPartFirstToken.type == ST.identifier &&
            !validIdentifiers.contains(pluralPartFirstToken.value)) {
          throw L10nParserException(
            'ICU Syntax Error: Plural expressions case must be one of "zero", "one", "two", "few", "many", or "other".',
            filename,
            messageId,
            messageString,
            node.positionInMessage,
          );
        }
      }
      break;
    case ST.selectParts:
      if (children.every((Node node) => node.children[0].type != ST.other)) {
        throw L10nParserException(
          'ICU Syntax Error: Select expressions must have an "other" case.',
          filename,
          messageId,
          messageString,
          syntaxTree.positionInMessage,
        );
      }
      break;
    // ignore: no_default_cases
    default:
      break;
  }
  children.forEach(checkExtraRules);
}