fromBlockSandwich static method

Danger<ForBlockSandwich, ForBlockSandwichException> fromBlockSandwich(
  1. BlockSandwich blockSandwich
)
override

Implementation

static Danger<ForBlockSandwich, ForBlockSandwichException> fromBlockSandwich(BlockSandwich blockSandwich) {

    final log = Log(classLocation: ForBlockSandwich, functionLocation: 'fromDerivationCitrusSyntaxList');

    final blockTypeKeyword = blockSandwich.first.second.second;

    if (blockTypeKeyword is! For) return Failure(ForBlockSandwichExceptionA(), log.monitor({
        'invalid block type': blockTypeKeyword,
    }));

    final startBlockArgumentable = blockSandwich.first.fourth;

    switch (startBlockArgumentable) {
    case InExpression():

        final first = startBlockArgumentable.first.text;

        final temporaryPropertyNameResult = PropertyName.result(first);
        log.add(temporaryPropertyNameResult);

        final fifth = startBlockArgumentable.fifth.text;

        final listPropertyNameResult = PropertyName.result(fifth);
        log.add(listPropertyNameResult);

        final derivationCitrusSyntaxList = blockSandwich.second;
        final matureCitrusSemanticListResult = CitrusSemanticList.fromDerivationCitrusSyntaxList(derivationCitrusSyntaxList);
        log.add(matureCitrusSemanticListResult);

        final sourceResult = CitrusSemanticSource.result(blockSandwich.text);
        log.add(sourceResult);

        final result = ForBlockSandwich(sourceResult.wrapped, temporaryPropertyNameResult.wrapped, listPropertyNameResult.wrapped, matureCitrusSemanticListResult.wrapped);

        return Success(result, log);

    case _:

        return Failure(ForBlockSandwichExceptionE(), log.monitor({
            'invalid start block argumentable': startBlockArgumentable.runtimeType,
            'text': startBlockArgumentable.text,
        }));

    }

}