Quick actions

cmd+k|ctrl+k

Navigation

Languages

Talk language extensions

Snippet info

Language

Raku

Visibility

public

Author

theangryepicbanana

Created

2018-07-21T16:31:01Z

Updated

2018-07-29T00:01:01Z

my $file = slurp 'data.sm';

my @Extensions = [];

sub Parse-Extension(\file, $ext is copy) {
    my $out = "";
    
    my $replace = ($ext ~~ m:g/^^Replace': '(\N+)/)[0][0].Str;
    my $structure = ($ext ~~ m:g/^^Captures': '(\N+)/)[0][0].Int;
    my @l;
    
    for $ext.lines {
        given .trim-leading() {
            when /^'$'(\d)': '(\N+)$/ {
                my @m = $/.list;
                push @l, @m>>.Str;
            }
        }
    }
    
    for (file ~~ m:g/(<$(@l[0][1])>)(<$(@l[1][1])>)(<$(@l[2][1])>)/).list {
        my @match = $_>>.Str;
        my $rep = $replace.subst(/'$'0/, @match[0]).subst(/'$'1/, @match[1]).subst(/'$'2/, @match[2]);
        file ~~ s:g/$(@match.join.Str)/$rep/;
    }
}

for $file.lines -> $line {
    given $line {
        when /^'#:'Extend\swith\s(\N+?)$/ {
            push @Extensions, slurp "$0"
        }
    }
}

for @Extensions -> $ext {
    Parse-Extension $file, $ext;
}

say $file;
INFO