
package Text::Wigwam::Engine::Fusion::Token::Terminator::Expression;

    use strict;
    use warnings;
    our $VERSION = '0.01';

    use base q/Text::Wigwam::Cast/;

    use Text::Wigwam::Const qw( TERM OPTIONAL );
    use Text::Wigwam::Engine::Fusion::Const(
      qw/
        TEXT_BLOCK
        ROOT_BLOCK
        CODE_BLOCK
      /
    );

    sub new { return bless { DRAW => $_[1] } }
    sub exec {
        my( $tokn, $want, $Arg, $Api, $core ) = @_;

         # If we're pulling a list, process the next token.
        return $core->next_token->exec( $want, $Arg, $Api, $core ) if $want & TERM;

        $Api->exception( 'A required argument is missing!' ) unless $want & OPTIONAL;

         # If the calling directive is not pulling a list, then fake
         # the data via null_data.
        return $Arg->null_data($want);
    }
    sub skip {
        my( $tokn, $list, $Arg, $Api, $core ) = @_;
        return $core->next_token->skip( $list, $Arg, $Api, $core ) if $list;
        $Api->exception( 'A required argument is missing!' ) unless $Arg->want & OPTIONAL;
        return;
    }
    sub paint {
        my( $tokn, $Arg, $Api, $core ) = @_;

        my $flag = $tokn->{FLAG};
        $tokn->{FLAG} = 1;
        return(
            Text::Wigwam::Engine::Fusion::Paint::Group->new(
                [
                    Text::Wigwam::Engine::Fusion::Paint::Token->new(
                        ($flag ? '' : $tokn->{DRAW}[0]),
                        $core->curr_addr,
                        'directive'
                    ),
                ]
            ),
            0,
        ) unless $Arg->want & TERM;

        $tokn->{FLAG} = 0;
        return $core->next_token->paint( $Arg, $Api, $core );# if $flag;

        my( $text, $end ) = $core->next_token->paint(
            $Arg,
            $Api,
            $core
        );
        return(
            Text::Wigwam::Engine::Fusion::Paint::Group->new(
              [
                Text::Wigwam::Engine::Fusion::Paint::Token->new(
                    @{$tokn->{DRAW}},
                    $core->curr_addr,
                'directive'
                ),
                @$text
              ]
            ),
            $end,
        );
    }

1;
