parse method Null safety

  1. @override
ParsingResult<YamlNode, YamlLocalizationToken> parse(
  1. {required YamlNode input,
  2. required String name}
)
override

Implementation

@override
ParsingResult<YamlNode, YamlLocalizationToken> parse({
  required YamlNode input,
  required String name,
}) {
  if (!(input is YamlMap)) {
    throw ParsingException<YamlLocalizationToken>(
      message: '[input] should be a YamlMap',
      token: YamlLocalizationToken.unknown(input),
    );
  }
  final map = input;
  _tokens = <YamlLocalizationToken>[];

  // Parsing language coedes
  final languages = <Localizations>[];

  for (var languageEntry in map.nodes.entries) {
    _addToken(
      YamlLocalizationTokenType.languageKey,
      languageEntry.key,
    );
    if (!(languageEntry.value is YamlMap)) {
      throw ParsingException<YamlLocalizationToken>(
        message: '[${languageEntry.key}] should be a YamlMap',
        token: YamlLocalizationToken.unknown(languageEntry.value),
      );
    }
    final section = _parseSection(
      languageEntry.key.toString(),
      name,
      languageEntry.value as YamlMap,
    );
    languages.add(
      Localizations.fromSection(
        name: name,
        supportedLanguageCodes: [languageEntry.key.toString()],
        section: section,
      ),
    );
  }

  return ParsingResult<YamlNode, YamlLocalizationToken>(
    input: input,
    result: Localizations.merge(name, languages),
    tokens: _tokens,
  );
}