~ubuntu-branches/ubuntu/vivid/gitolite3/vivid-proposed

« back to all changes in this revision

Viewing changes to src/syntactic-sugar/macros

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2014-05-25 20:09:36 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140525200936-el6hezd1fym50pxh
Tags: 3.6-1
* New upstream release
* Depend on ssh-server instead of openssh-server (Closes: #735176).

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
# see documentation at the end of this script
8
8
 
9
9
my %macro;
 
10
 
10
11
sub sugar_script {
11
12
    my $lines = shift;
12
 
    my @out  = ();
 
13
    my @out   = ();
13
14
 
14
 
    my $l = join("\n", @$lines);
15
 
    while ($l =~ s/^macro (\w+)\b(.*?)\nend//ms) {
 
15
    my $l = join( "\n", @$lines );
 
16
    while ( $l =~ s/^macro (\w+)\b(.*?)\nend//ms ) {
16
17
        $macro{$1} = $2;
17
18
    }
18
19
 
19
20
    $l =~ s/^((\w+)\b.*)/$macro{$2} ? expand($1) : $1/gem;
20
21
 
21
 
    $lines = [split "\n", $l];
 
22
    $lines = [ split "\n", $l ];
22
23
    return $lines;
23
24
}
24
25
 
25
26
sub expand {
26
27
    my $l = shift;
27
 
    my ($word, @arg) = split ' ', $l;
 
28
    my ( $word, @arg );
 
29
 
 
30
    eval "require Text::ParseWords";
 
31
    if ($@) {
 
32
        ( $word, @arg ) = split ' ', $l;
 
33
    } else {
 
34
        ( $word, @arg ) = Text::ParseWords::shellwords($l);
 
35
    }
28
36
    my $v = $macro{$word};
29
37
    $v =~ s/%(\d+)/$arg[$1-1] or die "macro '$word' needs $1 arguments at '$l'\n"/gem;
30
38
    return $v;