# vim: syn=perl:

# "sugar script" (syntactic sugar helper) for gitolite3
# ----------------------------------------------------------------------
# see src/VREF/refex-expr for instructions and WARNINGS!

my $perm = qr(-|R|RW\+?C?D?M?);

my $seq = 1;

sub sugar_script {
    my $lines = shift;

    # my @out  = ();
    for my $l (@$lines) {
        push @out, $l;

        # quick check
        next unless $l =~ /^($perm) /;
        # more detailed check
        next unless $l =~ /^($perm) (\S.*) = (\S.*)$/;
        my ( $perm, $refexes, $users ) = ( $1, $2, $3 );
        next unless $refexes =~ / (and|not|or|xor|\+|-|==|-lt|-gt|-eq|-le|-ge|-ne) /;

        print STDERR ">>>> $l\n";
        pop @out;    # we need to replace that last line

        push @out, "option refex-expr.sugar$seq = $refexes";
        push @out, "$perm VREF/refex-expr/sugar$seq = $users";

        $seq++;
    }

    return \@out;
}
