line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
17
|
use strict; use warnings; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
|
|
87
|
|
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
98
|
|
2
|
|
|
|
|
|
|
package Kwim::Tree; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use base 'Pegex::Tree'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2013
|
|
5
|
|
|
|
|
|
|
# use XXX -with => 'YAML::XS'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub got_block_blank { |
8
|
20
|
|
|
20
|
0
|
43
|
my ($self, $text) = @_; |
9
|
20
|
|
|
|
|
72
|
$self->add('blank'); |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub got_block_comment { |
13
|
4
|
|
|
4
|
0
|
12
|
my ($self, $text) = @_; |
14
|
4
|
|
|
|
|
46
|
$self->add(comment => $text); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub got_line_comment { |
18
|
8
|
|
|
8
|
0
|
16
|
my ($self, $text) = @_; |
19
|
8
|
|
|
|
|
34
|
$self->add(comment => $text); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub got_block_rule { |
23
|
1
|
|
|
1
|
0
|
3
|
my ($self, $text) = @_; |
24
|
1
|
|
|
|
|
4
|
$self->add(rule => ''); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub got_block_head { |
28
|
15
|
|
|
15
|
0
|
38
|
my ($self, $got) = @_; |
29
|
15
|
|
|
|
|
46
|
my $marker = shift @$got; |
30
|
15
|
|
|
|
|
67
|
my ($text) = grep defined, @$got; |
31
|
15
|
|
|
|
|
48
|
chomp $text; |
32
|
15
|
|
|
|
|
34
|
my $level = length $marker; |
33
|
15
|
|
|
|
|
138
|
$self->add("head$level" => $text); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub got_block_pref { |
37
|
10
|
|
|
10
|
0
|
26
|
my ($self, $text) = @_; |
38
|
10
|
|
|
|
|
33
|
chomp $text; |
39
|
10
|
|
|
|
|
80
|
$text =~ s/^ //gm; |
40
|
10
|
|
|
|
|
48
|
$self->add("pref" => $text); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub got_block_list_bullet { |
44
|
10
|
|
|
10
|
0
|
251
|
my ($self, $text) = @_; |
45
|
10
|
|
|
|
|
85
|
my @items = map {s/^ //gm; $_} split /^\*\ /m, $text; |
|
35
|
|
|
|
|
92
|
|
|
35
|
|
|
|
|
92
|
|
46
|
10
|
|
|
|
|
29
|
shift @items; |
47
|
25
|
|
|
|
|
118
|
my $items = [ |
48
|
|
|
|
|
|
|
map { |
49
|
10
|
|
|
|
|
30
|
my $item = $self->add_parse(item => $_, 'block-list-item'); |
50
|
25
|
50
|
|
|
|
199
|
if ($item->{item}[0]{para}) { |
51
|
25
|
|
|
|
|
79
|
$item->{item}[0] = $item->{item}[0]{para}; |
52
|
|
|
|
|
|
|
} |
53
|
25
|
|
|
|
|
101
|
$item; |
54
|
|
|
|
|
|
|
} @items |
55
|
|
|
|
|
|
|
]; |
56
|
10
|
|
|
|
|
131
|
+{ list => $items }; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub got_block_list_data { |
60
|
4
|
|
|
4
|
0
|
11
|
my ($self, $text) = @_; |
61
|
4
|
|
|
|
|
35
|
my @items = map {s/^ //gm; $_} split /^\-\ /m, $text; |
|
11
|
|
|
|
|
46
|
|
|
11
|
|
|
|
|
30
|
|
62
|
4
|
|
|
|
|
14
|
shift @items; |
63
|
7
|
|
|
|
|
16
|
my $items = [ |
64
|
|
|
|
|
|
|
map { |
65
|
4
|
|
|
|
|
11
|
my ($term, $def, $rest); |
66
|
7
|
100
|
|
|
|
42
|
if (s/(.*?) :: +(\S.*)\n//) { |
67
|
2
|
|
|
|
|
12
|
($term, $def, $rest) = ($1, $2, $_); |
68
|
2
|
|
|
|
|
10
|
$def = $self->collapse($self->parse($def)); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
5
|
|
|
|
|
29
|
s/(.*)\n//; |
72
|
5
|
|
|
|
|
28
|
($term, $def, $rest) = ($1, '', $_); |
73
|
|
|
|
|
|
|
} |
74
|
7
|
|
|
|
|
35
|
$term = $self->collapse($self->parse($term)); |
75
|
7
|
|
|
|
|
26
|
my $result = [$term, $def]; |
76
|
7
|
100
|
|
|
|
27
|
if (length $rest) { |
77
|
6
|
|
|
|
|
25
|
push @$result, $self->parse($rest, 'block-list-item'); |
78
|
|
|
|
|
|
|
} |
79
|
7
|
|
|
|
|
157
|
$result; |
80
|
|
|
|
|
|
|
} @items |
81
|
|
|
|
|
|
|
]; |
82
|
4
|
|
|
|
|
48
|
+{ data => $items }; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub got_block_title { |
86
|
7
|
|
|
7
|
0
|
17
|
my ($self, $pair) = @_; |
87
|
7
|
|
|
|
|
23
|
my ($name, $abstract) = @$pair; |
88
|
7
|
100
|
|
|
|
32
|
if (defined $abstract) { |
89
|
4
|
|
|
|
|
23
|
$name = $self->collapse($self->parse($name)); |
90
|
4
|
|
|
|
|
20
|
$abstract = $self->collapse($self->parse($abstract)); |
91
|
4
|
|
|
|
|
47
|
+{title => [ $name, $abstract ]}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
3
|
|
|
|
|
18
|
$self->add_parse(title => $name); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub got_block_verse { |
99
|
0
|
|
|
0
|
0
|
0
|
my ($self, $text) = @_; |
100
|
0
|
|
|
|
|
0
|
$self->add_parse(verse => $text); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub got_block_para { |
104
|
131
|
|
|
131
|
0
|
314
|
my ($self, $text) = @_; |
105
|
131
|
|
|
|
|
620
|
$self->add_parse(para => $text); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub got_phrase_func { |
109
|
17
|
|
|
17
|
0
|
50
|
my ($self, $content) = @_; |
110
|
17
|
|
|
|
|
219
|
+{func => $content}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub got_phrase_code { |
114
|
8
|
|
|
8
|
0
|
30
|
my ($self, $content) = @_; |
115
|
8
|
|
|
|
|
54
|
$self->add(code => $content); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub got_phrase_bold { |
119
|
13
|
|
|
13
|
0
|
39
|
my ($self, $content) = @_; |
120
|
13
|
|
|
|
|
71
|
$self->add(bold => $content); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub got_phrase_emph { |
124
|
9
|
|
|
9
|
0
|
18
|
my ($self, $content) = @_; |
125
|
9
|
|
|
|
|
35
|
$self->add(emph => $content); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub got_phrase_del { |
129
|
7
|
|
|
7
|
0
|
21
|
my ($self, $content) = @_; |
130
|
7
|
|
|
|
|
37
|
$self->add(del => $content); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub got_phrase_hyper_named { |
134
|
4
|
|
|
4
|
0
|
12
|
my ($self, $content) = @_; |
135
|
4
|
|
|
|
|
13
|
my ($text, $link) = @$content; |
136
|
4
|
|
|
|
|
63
|
{ hyper => { link => $link, text => $text } }; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub got_phrase_hyper_explicit { |
140
|
4
|
|
|
4
|
0
|
12
|
my ($self, $content) = @_; |
141
|
4
|
|
|
|
|
38
|
{ hyper => { link => $content, text => '' } }; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub got_phrase_hyper_implicit { |
145
|
4
|
|
|
4
|
0
|
10
|
my ($self, $content) = @_; |
146
|
4
|
|
|
|
|
43
|
{ hyper => { link => $content, text => '' } }; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub got_phrase_link_named { |
150
|
0
|
|
|
0
|
0
|
0
|
my ($self, $content) = @_; |
151
|
0
|
|
|
|
|
0
|
my ($text, $link) = @$content; |
152
|
0
|
|
|
|
|
0
|
{ link => { link => $link, text => $text } }; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub got_phrase_link_plain { |
156
|
1
|
|
|
1
|
0
|
3
|
my ($self, $content) = @_; |
157
|
1
|
|
|
|
|
9
|
{ link => { link => $content, text => '' } }; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
161
|
|
|
|
|
|
|
sub add { |
162
|
95
|
|
|
95
|
0
|
256
|
my ($self, $tag, $content) = @_; |
163
|
95
|
100
|
|
|
|
261
|
if (ref $content) { |
164
|
29
|
|
|
|
|
61
|
$content = $content->[0]; |
165
|
29
|
100
|
|
|
|
81
|
if (@$content == 1) { |
|
|
50
|
|
|
|
|
|
166
|
27
|
|
|
|
|
313
|
$content = $content->[0] |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
elsif (@$content > 1) { |
169
|
2
|
|
|
|
|
10
|
$content = $self->collapse($content); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
95
|
|
|
|
|
740
|
+{ $tag => $content } |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub add_parse { |
176
|
159
|
|
|
159
|
0
|
427
|
my ($self, $tag, $text, $start) = @_; |
177
|
159
|
|
|
|
|
2353
|
+{ $tag => $self->collapse($self->parse($text, $start)) }; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub parse { |
181
|
182
|
|
|
182
|
0
|
506
|
my ($self, $text, $start) = @_; |
182
|
182
|
100
|
|
|
|
453
|
if (not $start) { |
183
|
151
|
|
|
|
|
253
|
$start = 'text-markup'; |
184
|
151
|
|
|
|
|
592
|
chomp $text; |
185
|
|
|
|
|
|
|
} |
186
|
182
|
|
50
|
|
|
996
|
my $debug = $self->{parser}{debug} || undef; |
187
|
182
|
|
|
|
|
1245
|
my $parser = Pegex::Parser->new( |
188
|
|
|
|
|
|
|
grammar => 'Kwim::Grammar'->new(start => $start), |
189
|
|
|
|
|
|
|
receiver => 'Kwim::Tree'->new, |
190
|
|
|
|
|
|
|
debug => $debug, |
191
|
|
|
|
|
|
|
); |
192
|
182
|
|
|
|
|
3196
|
$parser->parse($text, $start); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub collapse { |
196
|
178
|
|
|
178
|
0
|
398
|
my ($self, $content) = @_; |
197
|
178
|
|
|
|
|
748
|
for (my $i = 0; $i < @$content; $i++) { |
198
|
264
|
100
|
|
|
|
853
|
next if ref $content->[$i]; |
199
|
170
|
|
100
|
|
|
1151
|
while ($i + 1 < @$content and not ref $content->[$i + 1]) { |
200
|
24
|
|
|
|
|
142
|
$content->[$i] .= splice(@$content, $i + 1, 1); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
178
|
|
|
|
|
1711
|
$content; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
1; |