fromBlockSandwich static method

Danger<Define, CitrusSemanticException> fromBlockSandwich(
  1. BlockSandwich blockSandwich
)

Implementation

static Danger<Define, CitrusSemanticException> fromBlockSandwich(BlockSandwich blockSandwich) {

    final log = Log(classLocation: Define, functionLocation: 'fromBlockSandwich');

    final blockTypeKeyword = blockSandwich.first.second.second;

    if (blockTypeKeyword is! DefineKeyword) return Failure(DefineExceptionC(), log.monitor({
        'invalid block type keyword': blockTypeKeyword.runtimeType,
    }));

    final startBlockArgumentable = blockSandwich.first.fourth;

    switch (startBlockArgumentable) {
    case AccesserableCollection():

        final identifiers = startBlockArgumentable.identifiers;
        final length = identifiers.length;

        if (length != 1) return Failure(DefineExceptionE(), log.monitor({
            'identifiers length': length,
            'identifiers': identifiers,
        }));

        // 必ず return
        final result = Define(blockSandwich.source, blockTypeKeyword, identifiers.first, blockSandwich.second.source);

        return Success(result, log);

    case _:

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

    }
}