From 7685305e1f82212323ec32a321b1f5c623751b6c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 11:55:51 +0200 Subject: Adding upstream version 3.6.12. Signed-off-by: Daniel Baumann --- src/syntactic-sugar/macros | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/syntactic-sugar/macros (limited to 'src/syntactic-sugar/macros') diff --git a/src/syntactic-sugar/macros b/src/syntactic-sugar/macros new file mode 100644 index 0000000..a3493a4 --- /dev/null +++ b/src/syntactic-sugar/macros @@ -0,0 +1,82 @@ +# vim: syn=perl: + +# "sugar script" (syntactic sugar helper) for gitolite3 + +# simple line-wise macro processor +# ---------------------------------------------------------------------- +# see documentation at the end of this script + +my %macro; + +sub sugar_script { + my $lines = shift; + my @out = (); + + my $l = join( "\n", @$lines ); + while ( $l =~ s/^macro (\w+)\b(.*?)\nend//ms ) { + $macro{$1} = $2; + } + + $l =~ s/^((\w+)\b.*)/$macro{$2} ? expand($1) : $1/gem; + + $lines = [ split "\n", $l ]; + return $lines; +} + +sub expand { + my $l = shift; + my ( $word, @arg ); + + eval "require Text::ParseWords"; + if ($@) { + ( $word, @arg ) = split ' ', $l; + } else { + ( $word, @arg ) = Text::ParseWords::shellwords($l); + } + my $v = $macro{$word}; + $v =~ s/%(\d+)/$arg[$1-1] or die "macro '$word' needs $1 arguments at '$l'\n"/gem; + return $v; +} + +__END__ + +Documentation is mostly by example. + +Setup: + + * uncomment the line + 'macros', + in the ENABLE list in ~/.gitolite.rc + +Notes on macro definition: + + * the keywords 'macro' and 'end' should start on a new line + * the first word after 'macro' is the name of the macro, and the rest, until + the 'end', is the body + +Notes on macro use: + + * the macro name should be the first word on a line + * the rest of the line is used as arguments to the macro + +Example: + + if your conf contains: + + macro foo repo aa-%1 + RW = u1 %2 + R = u2 + end + + foo 1 alice + foo 2 bob + + this will effectively turn into + + repo aa-1 + RW = u1 alice + R = u2 + + repo aa-2 + RW = u1 bob + R = u2 -- cgit v1.2.3