fromProtectSource static method

Safety<RootCitrusSyntax> fromProtectSource(
  1. String fileSource
)

protect など 既存の file 側を読み取るよう.

Implementation

static Safety<RootCitrusSyntax> fromProtectSource(String fileSource) {

    final log = Log(classLocation: RootCitrusSyntax, functionLocation: 'fromProtectSource');

    // 1.
    final scanner = StringScanner<DerivationCitrusSyntax>.fromString(fileSource);

    final stringScannerCompileResult = scanner.compile(LeafCitrusSyntax.result);
    log.add(stringScannerCompileResult);
    // 1. より LeafCitrusSyntaxExceptionA は起こりえないので throw out.
    if (stringScannerCompileResult is! Success<SyntaxScanner<DerivationCitrusSyntax, DerivationCitrusSyntax>, LeafCitrusSyntaxExceptionA>) Result.panic(CitrusSyntaxErrorA(), log);

    final compileUnits = [
        CompileUnit([
            ListSyntaxVerify(ListOfIdentifierable.fromIterable),
            ListSyntaxVerify(SpaceCollection.fromIterable),
        ]),
        CompileUnit([
            OneLengthSyntaxVerify(Identifier.result),
        ]),
        CompileUnit([
            TwoLengthSyntaxVerify(BlockType.new),
            ListSyntaxVerify(AccesserableCollection.fromIterable),
        ]),
        CompileUnit([
            ThreeLengthSyntaxVerify(EndBlock.new),
        ]),
        CompileUnit([
            FiveLengthSyntaxVerify(StartBlock.new),
        ]),
        CompileUnit([
            TrunkSyntaxVerify(BlockSandwich.fromIterable),
        ]),
    ];

    final syntaxCompileResult = stringScannerCompileResult.wrapped.compile(compileUnits);
    log.add(syntaxCompileResult);

    final derivationSyntaxListResult = CitrusSyntaxList(syntaxCompileResult.wrapped);

    final result = RootCitrusSyntax(derivationSyntaxListResult);

    return Safety(result, log);

}