resolve method

  1. @override
Success<String, CitrusSemanticException> resolve(
  1. CitrusSymbolTable symbolTable,
  2. String generateLocation,
  3. Iterable<String> fragments
)
override

Implementation

@override
Success<String, CitrusSemanticException> resolve(CitrusSymbolTable symbolTable, String generateLocation, Iterable<String> fragments) {

    final log = Log(classLocation: runtimeType, functionLocation: 'resolve');

    final path = p.joinAll([generateLocation, ...fragments]);

    final file = io.File(path);
    late final String fileSource;

    // file が存在しないときは 空の source として扱う.
    switch (file.existsSync()) {
    case true: fileSource = io.File(path).readAsStringSync(encoding: utf8);
    case false: fileSource = '';
    }

    final rootSyntaxResult = RootCitrusSyntax.fromProtectSource(fileSource);
    log.add(rootSyntaxResult);

    final blockSandwiches = rootSyntaxResult.wrapped.derivationCitrusSyntaxList.whereType<BlockSandwich>();

    final protectContentRosterResult = ProtectContentRoster.fromBlockSandwich(blockSandwiches);
    log.add(protectContentRosterResult);
    if (protectContentRosterResult is! Success<ProtectContentRoster, ImmatureCitrusSemanticException>) return Success(source, log);

    for (final protectContent in protectContentRosterResult.wrapped) {

        if (protectContent.accesser == accesser) {

            final result = protectContent.resolve(symbolTable);
            log.add(result);

            // 既存の file に指定の id の protect が存在する場合 file 側の protect syntax の記述をそのまま返す.
            return Success(result.wrapped, log);

        }

    }

    // 既存の file に指定の id の protect が無い場合 template 側の protect syntax の記述をそのまま返す.
    return Success(source, log);

}