Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 77 lines (61 sloc) 1.668 kB
784582b * Change /usr/local/bin/perl to the perl in PATH.
audreyt authored
1 #!/usr/bin/env perl
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
2
c5e9a77 * Add the same inplace-STD.pmc guard to the main executables.
audreyt authored
3 use FindBin;
4 BEGIN { unshift @INC, $FindBin::Bin if -s "$FindBin::Bin/STD.pmc"; }
5
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
6 use strict;
7 use warnings;
8
9 use STD;
10 use utf8;
11 use feature 'say';
12
d942ebd [redspans] nice 19;
azawawi authored
13 #let us play nice with others
14 use POSIX qw(nice); nice 19;
15
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
16 my @loc;
17
18 sub MAIN {
19 my $output = 'ast';
20 my $file = shift;
21
d730f17 [redspans] add in current character for documentation
lwall authored
22 my $txt = Encode::decode('utf8', `cat $file`);
23 $loc[length($txt) - 1] = [];
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
24
77c77f9 [redspans] pass actions as option to parsefile, as specced
lwall authored
25 STD->parsefile($file, actions => 'Actions');
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
26
99e5dc6 [redspans] Improved output to be more user-friendly, TimToady++
azawawi authored
27 my ($last_tree,$buffer) = ("","");
d730f17 [redspans] add in current character for documentation
lwall authored
28 for my $i (0 .. @loc-1) {
99e5dc6 [redspans] Improved output to be more user-friendly, TimToady++
azawawi authored
29 say("Undefined $i"),next unless defined $loc[$i];
30 my $c = substr($txt,$i,1);
c8d8459 [redspans] trees are now stored as action refs thus consuming far les…
azawawi authored
31 my $tree = "";
32 for my $action_ref (@{$loc[$i]}) {
33 $tree .= ${$action_ref} . " ";
34 }
99e5dc6 [redspans] Improved output to be more user-friendly, TimToady++
azawawi authored
35 if($tree ne $last_tree) {
bc9c6d2 [redspans] empty buffers are never printed
azawawi authored
36 say "\n'$buffer'\n$last_tree" if $buffer ne '';
99e5dc6 [redspans] Improved output to be more user-friendly, TimToady++
azawawi authored
37 $buffer = $c;
38 } else {
39 $buffer .= $c;
40 }
41 $last_tree = $tree;
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
42 }
43 }
44
45 ###################################################################
46
47 { package Actions;
48
49 our $AUTOLOAD;
c8d8459 [redspans] trees are now stored as action refs thus consuming far les…
azawawi authored
50 my %actions = ();
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
51 sub AUTOLOAD {
c8d8459 [redspans] trees are now stored as action refs thus consuming far les…
azawawi authored
52 my $self = shift;
53 my $C = shift;
54 my $F = $C->{_from};
55 my $P = $C->{_pos};
56 $AUTOLOAD =~ s/^Actions:://;
57 $loc[$P] = [] if $loc[$P]; # in case we backtracked to here
58 my $action = $AUTOLOAD;
59 my $action_ref = $actions{$action};
60 if(!$action_ref) {
61 $actions{$action} = $action_ref = \$action;
62 }
63 for ($F..$P-1) {
64 unshift @{$loc[$_]}, $action_ref;
65 }
34dee70 [redspans] program to calculate reduction spans for syntax highlighti…
lwall authored
66 }
67
68 sub stdstopper { }
69 sub terminator { }
70 sub unitstopper { }
71 sub comp_unit { }
72 }
73
74 MAIN(@ARGV);
bcb314d [redspans] vim modeline that corresponds to the current indetation le…
moritz authored
75
76 # vim: ts=8 sw=4
Something went wrong with that request. Please try again.