1 |
williamc |
1.1 |
#
|
2 |
|
|
# Parse.pm
|
3 |
|
|
#
|
4 |
|
|
# Originally Written by Christopher Williams
|
5 |
|
|
#
|
6 |
|
|
# Description
|
7 |
|
|
# -----------
|
8 |
|
|
# maintain parse configurations
|
9 |
|
|
#
|
10 |
|
|
# Interface
|
11 |
|
|
# ---------
|
12 |
|
|
# new() : A new Parse object
|
13 |
|
|
# addtag(name,start,text,end,$object) : Add a new tag
|
14 |
|
|
# addgrouptags() : add <Group> tag functionality
|
15 |
|
|
# addignoretags() : add <ignore> tag functionality
|
16 |
|
|
# parse(filename,[streamhandle], [streamexcludetag]) :
|
17 |
|
|
# parse the given file - turn on the stream
|
18 |
|
|
# function of the switcher if a filehandle
|
19 |
|
|
# supplied as a second argument
|
20 |
|
|
# line() : return the current linenumber in the file
|
21 |
|
|
# tagstartline() : return the linenumber of the last tag opening
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
package ActiveDoc::Parse;
|
25 |
|
|
require 5.004;
|
26 |
|
|
use ActiveDoc::Switcher;
|
27 |
|
|
use ActiveDoc::TagContainer;
|
28 |
|
|
use ActiveDoc::GroupChecker;
|
29 |
|
|
|
30 |
|
|
sub new {
|
31 |
|
|
my $class=shift;
|
32 |
|
|
$self={};
|
33 |
|
|
bless $self, $class;
|
34 |
|
|
$self->init();
|
35 |
|
|
return $self;
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
sub init {
|
39 |
|
|
my $self=shift;
|
40 |
|
|
$self->{gc}=GroupChecker->new();
|
41 |
|
|
$self->{gc}->include("all");
|
42 |
|
|
$self->{tags}=ActiveDoc::TagContainer->new();
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
sub parse {
|
46 |
|
|
my $self=shift;
|
47 |
|
|
my $file=shift;
|
48 |
|
|
|
49 |
|
|
# basic setup of switcher
|
50 |
|
|
$self->{switch}=ActiveDoc::Switcher->new($file);
|
51 |
|
|
$self->{switch}->usegroupchecker($self->{gc});
|
52 |
|
|
$self->{switch}->usetags($self->{tags});
|
53 |
|
|
|
54 |
|
|
# do we need to switch on the streamer?
|
55 |
|
|
if ( @_ ) {
|
56 |
|
|
$fh=shift;
|
57 |
|
|
$self->{switch}->stream($fh);
|
58 |
|
|
foreach $tag ( @_ ) {
|
59 |
|
|
$self->{switch}->streamexclude($tag);
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
# parse
|
64 |
|
|
$self->{switch}->parse();
|
65 |
|
|
undef $self->{switch};
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
sub line {
|
69 |
|
|
my $self=shift;
|
70 |
|
|
if ( defined $self->{switch} ) {
|
71 |
|
|
return $self->{switch}->line();
|
72 |
|
|
}
|
73 |
|
|
return undef;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
sub tagstartline {
|
77 |
|
|
my $self=shift;
|
78 |
|
|
if ( defined $self->{switch} ) {
|
79 |
|
|
return $self->{switch}->tagstartline();
|
80 |
|
|
}
|
81 |
|
|
return undef;
|
82 |
|
|
}
|
83 |
|
|
sub addtag {
|
84 |
|
|
my $self=shift;
|
85 |
|
|
$self->{tags}->addtag(@_);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
sub addgrouptags {
|
89 |
|
|
my $self=shift;
|
90 |
|
|
$self->{tags}->addtag("Group", \&Group_Start,$self,
|
91 |
|
|
"", $self, \&Group_End, $self);
|
92 |
|
|
$self->{tags}->setgrouptag("Group");
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
sub addignoretags {
|
96 |
|
|
my $self=shift;
|
97 |
|
|
$self->{gc}->exclude("ignore");
|
98 |
|
|
$self->{tags}->addtag("Ignore", \&Ignore_Start, $self,
|
99 |
|
|
"",$self, \&Ignore_End,$self);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
# --------- Basic Group Related Tags ---------------------------------
|
103 |
|
|
|
104 |
|
|
sub Group_Start {
|
105 |
|
|
my $self=shift;
|
106 |
|
|
my $name=shift;
|
107 |
|
|
my $vars=shift;
|
108 |
|
|
my $lastgp;
|
109 |
|
|
|
110 |
|
|
$lastgp="group::".$$vars{name};
|
111 |
|
|
$self->{switch}->checkparam($name, 'name');
|
112 |
|
|
$self->{gc}->opencontext("group::".$$vars{name});
|
113 |
|
|
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
sub Group_End {
|
117 |
|
|
my $self=shift;
|
118 |
|
|
my $name=shift;
|
119 |
|
|
my $lastgp;
|
120 |
|
|
|
121 |
|
|
$self->{gc}->closelastcontext("group");
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
sub Ignore_Start {
|
125 |
|
|
my $self=shift;
|
126 |
|
|
my $name=shift;
|
127 |
|
|
|
128 |
|
|
$self->{gc}->opencontext("ignore");
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
sub Ignore_End {
|
132 |
|
|
my $self=shift;
|
133 |
|
|
$self->{gc}->closecontext("ignore");
|
134 |
|
|
}
|
135 |
|
|
|