| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: ITextParser.pm,v 1.19 2008/06/03 17:31:15 cmungall Exp $ |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Copyright (C) 2002 Chris Mungall |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# See also - http://stag.sourceforge.net |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# This module is free software. |
|
8
|
|
|
|
|
|
|
# You may distribute this module under the same terms as perl itself |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Data::Stag::ITextParser; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
ITextParser.pm - parses stag IText format into stag events |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 AUTHOR |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
8
|
|
|
8
|
|
50
|
use Exporter; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
602
|
|
|
28
|
8
|
|
|
8
|
|
47
|
use Carp; |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
505
|
|
|
29
|
8
|
|
|
8
|
|
44
|
use FileHandle; |
|
|
8
|
|
|
|
|
13
|
|
|
|
8
|
|
|
|
|
78
|
|
|
30
|
8
|
|
|
8
|
|
4102
|
use strict; |
|
|
8
|
|
|
|
|
26
|
|
|
|
8
|
|
|
|
|
386
|
|
|
31
|
8
|
|
|
8
|
|
46
|
use base qw(Data::Stag::BaseGenerator Exporter); |
|
|
8
|
|
|
|
|
18
|
|
|
|
8
|
|
|
|
|
6486
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
8
|
|
|
8
|
|
64
|
use vars qw($VERSION); |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
339403
|
|
|
34
|
|
|
|
|
|
|
$VERSION="0.14"; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub fmtstr { |
|
37
|
0
|
|
|
0
|
0
|
0
|
return 'itext'; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub parse_fh { |
|
41
|
10
|
|
|
10
|
0
|
19
|
my $self = shift; |
|
42
|
10
|
|
|
|
|
17
|
my $fh = shift; |
|
43
|
10
|
|
|
|
|
20
|
my @stack = (); |
|
44
|
10
|
|
|
|
|
15
|
my $txt; |
|
45
|
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
170
|
while(<$fh>) { |
|
47
|
370
|
|
|
|
|
583
|
chomp; |
|
48
|
370
|
|
|
|
|
547
|
s/\\\#/MAGIC_WORD_HASH/g; |
|
49
|
370
|
|
|
|
|
418
|
s/\#.*//; |
|
50
|
370
|
|
|
|
|
507
|
s/MAGIC_WORD_HASH/\#/g; |
|
51
|
370
|
50
|
|
|
|
756
|
next unless $_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# remove trailing ws |
|
54
|
370
|
|
|
|
|
2515
|
s/\s*$//; |
|
55
|
|
|
|
|
|
|
|
|
56
|
370
|
|
|
|
|
794
|
my $eofre = '\<\<(\S+)' . "\$"; |
|
57
|
370
|
50
|
|
|
|
1205
|
if (/$eofre/) { |
|
58
|
0
|
|
|
|
|
0
|
my $eof = $1; |
|
59
|
0
|
|
|
|
|
0
|
s/$eofre//; |
|
60
|
0
|
|
|
|
|
0
|
my $sofar = $_; |
|
61
|
0
|
|
|
|
|
0
|
while (<$fh>) { |
|
62
|
0
|
0
|
|
|
|
0
|
last if /^$eof/; |
|
63
|
0
|
|
|
|
|
0
|
$sofar .= $_; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
0
|
|
|
|
|
0
|
$_ = $sofar; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# get indent level |
|
69
|
370
|
|
|
|
|
863
|
/(\s*)(.*)/s; |
|
70
|
|
|
|
|
|
|
|
|
71
|
370
|
|
|
|
|
993
|
my ($indent_txt, $elt) = ($1, $2); |
|
72
|
370
|
|
|
|
|
471
|
my $indent = length($indent_txt); |
|
73
|
370
|
50
|
33
|
|
|
1809
|
if ($elt =~ /^([\w\-\+\?\*]+):\s*(.*)$/s || |
|
74
|
|
|
|
|
|
|
$elt =~ /^([\@\.]):\s*(.*)$/s) { |
|
75
|
370
|
|
|
|
|
707
|
$elt = $1; |
|
76
|
370
|
|
|
|
|
515
|
my $nu_txt = $2; |
|
77
|
|
|
|
|
|
|
|
|
78
|
370
|
|
|
|
|
821
|
$self->pop_to_level($indent, $txt, \@stack); |
|
79
|
370
|
|
|
|
|
473
|
$txt = undef; |
|
80
|
370
|
100
|
66
|
|
|
1138
|
if ($nu_txt || length($nu_txt)) { |
|
81
|
240
|
|
|
|
|
342
|
$txt = $nu_txt; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
370
|
|
|
|
|
1188
|
$self->start_event($elt); |
|
84
|
370
|
|
|
|
|
2085
|
push(@stack, [$indent, $elt]); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
else { |
|
87
|
|
|
|
|
|
|
# body |
|
88
|
0
|
0
|
|
|
|
0
|
$txt .= $elt if $elt; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
10
|
|
|
|
|
86
|
$fh->close; |
|
92
|
10
|
|
|
|
|
234
|
$self->pop_to_level(0, $txt, \@stack); |
|
93
|
10
|
|
|
|
|
29
|
return; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub pop_to_level { |
|
97
|
380
|
|
|
380
|
0
|
436
|
my $self = shift; |
|
98
|
380
|
|
|
|
|
425
|
my $indent = shift; |
|
99
|
380
|
|
|
|
|
457
|
my $txt = shift; |
|
100
|
380
|
|
|
|
|
399
|
my $stack = shift; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# if buffered pcdata, export it |
|
103
|
380
|
100
|
|
|
|
6189
|
if (defined $txt) { |
|
104
|
|
|
|
|
|
|
# unescape :s |
|
105
|
240
|
|
|
|
|
321
|
$txt =~ s/^\\:/:/g; |
|
106
|
240
|
|
|
|
|
286
|
$txt =~ s/([^\\])\\:/$1:/g; |
|
107
|
240
|
|
|
|
|
673
|
$self->evbody($txt); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
380
|
|
100
|
|
|
1810
|
while (scalar(@$stack) && |
|
110
|
|
|
|
|
|
|
$stack->[-1]->[0] >= $indent) { |
|
111
|
370
|
|
|
|
|
1036
|
$self->end_event($stack->[-1]->[1]); |
|
112
|
370
|
|
|
|
|
2120
|
pop(@$stack); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
380
|
|
|
|
|
567
|
return; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |