|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Guacamole::Dumper;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $AUTHORITY = 'cpan:XSAWYERX';  | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # ABSTRACT: Dump Guacamole ASTs  | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $Guacamole::Dumper::VERSION = '0.007';  | 
| 
5
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
290
 | 
 use strict;  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
87
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1431
 | 
    | 
| 
6
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
209
 | 
 use warnings;  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
82
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1596
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
218
 | 
 use List::Util qw/any sum/;  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
76
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5400
 | 
    | 
| 
9
 | 
35
 | 
 
 | 
 
 | 
  
35
  
 | 
 
 | 
272
 | 
 use Exporter "import";  | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
100
 | 
    | 
| 
 
 | 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16686
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our @EXPORT_OK = qw/dump_tree/;  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub dump_tree {  | 
| 
14
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
0
  
 | 
6
 | 
     my ($tree, $offset) = @_;  | 
| 
15
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
     return join "", map "$_\n", _dump_tree_inner($tree, "", $offset);  | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _dump_tree_inner {  | 
| 
19
 | 
30
 | 
 
 | 
 
 | 
  
30
  
 | 
 
 | 
58
 | 
     my ($tree, $indent, $offset) = @_;  | 
| 
20
 | 
30
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
56
 | 
     $indent //= "";  | 
| 
21
 | 
30
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
58
 | 
     $offset //= "  ";  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
30
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
61
 | 
     ref $tree eq 'HASH'  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         or die "Bad token object: $tree";  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my $head = $tree->{  | 
| 
27
 | 
30
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
74
 | 
         $tree->{'type'} eq 'lexeme'  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         ? 'value'  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         : 'name'  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     };  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     my @tail = $tree->{'type'} eq 'lexeme'  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
              ? ()  | 
| 
34
 | 
30
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
59
 | 
              : @{ $tree->{'children'} };  | 
| 
 
 | 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
43
 | 
    | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
36
 | 
30
 | 
  
100
  
 | 
 
 | 
  
20
  
 | 
 
 | 
111
 | 
     if ( any { ref $_ } @tail ) {  | 
| 
 
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
44
 | 
    | 
| 
37
 | 
20
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
30
 | 
         my @rest = map { ref $_ ? _dump_tree_inner($_, "$indent$offset", $offset) : "$indent$offset'$_'" } @tail;  | 
| 
 
 | 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
106
 | 
    | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
39
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
37
 | 
         my @clean = map { s/^\s+//r } @rest;  | 
| 
 
 | 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
251
 | 
    | 
| 
40
 | 
20
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
83
 | 
         if (sum(map length, @clean) < 40) {  | 
| 
41
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
             my @items = ($head, @clean);  | 
| 
42
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
24
 | 
             return ("$indent(@items)");  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
45
 | 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
33
 | 
         $rest[-1] .= ")";  | 
| 
46
 | 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
113
 | 
         return ("$indent($head", @rest);  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } else {  | 
| 
48
 | 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
         my @tailq = map "'$_'", @tail;  | 
| 
49
 | 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
20
 | 
         my @items = ($head, @tailq);  | 
| 
50
 | 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
57
 | 
         return ("$indent(@items)");  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |