[t/spec] Unfudge tests, add needed sort.
[pugs.git] / misc / pixie / extract_actions
blobd4284763a1c07a5feef7baede67646bfc93c9be4
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use File::Slurp qw(slurp);
5 use Term::ANSIColor qw(:constants);
7 my $without = slurp(shift);
8 my $with = slurp(shift);
9 my @chunks = split(/\{\*\}/,$without);
11 my @last_token;
12 for (@chunks) {
13 /^.* (?:regex|rule|token) \s+ ([:\w]+?(?:sym<.*?>)?)\s/sx;
14 my $name = $1;
15 $name =~ s/sym:<(.*)>/$1/g;
16 push (@last_token,$name);
19 my $first = shift @chunks;
20 $with =~ /^\Q$first\E/gc or die "can't match first chunk\n";
21 for my $chunk (@chunks) {
22 die "can't match next chunk:$chunk at",substr($with,pos($with),20),"\n" unless $with =~ /\G\{(.*?)\}\Q$chunk\E/sgc;
23 my $action = $1;
24 my $name = shift @last_token;
25 if ($action) {
26 # print RED,'{',$action,'}',RESET,$chunk;
27 # print '{',$action,'}',$chunk;
28 if ($action ne '*') {
29 my ($tag,) = $chunk =~ /#= (.*)/;
30 $tag //= '';
31 print "### $name $tag\n$action\n";
33 } else {
34 die "no action! chunk:$chunk";
35 # print GREEN,$chunk,RESET;