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 |
sashby |
1.6 |
# new() : A new Parse object
|
13 |
williamc |
1.1 |
# addtag(name,start,text,end,$object) : Add a new tag
|
14 |
sashby |
1.6 |
# addgrouptags() : add <Group> tag functionality
|
15 |
|
|
# addignoretags() : add <ignore> tag functionality
|
16 |
williamc |
1.1 |
# 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 |
sashby |
1.6 |
# line() : return the current linenumber in the file
|
21 |
williamc |
1.1 |
# tagstartline() : return the linenumber of the last tag opening
|
22 |
sashby |
1.6 |
# includeparse(Parse) : include the settings from another parse object
|
23 |
williamc |
1.2 |
# tags() : return list of defined tags
|
24 |
williamc |
1.3 |
# cleartags() : clear of all tags
|
25 |
sashby |
1.6 |
# opencontext(name) : open a parse context
|
26 |
williamc |
1.4 |
# closecontext(name) : close a parse context
|
27 |
|
|
# includecontext(name) : Process when in a given context
|
28 |
|
|
# excludecontext(name) : No Processing when given context
|
29 |
|
|
# contexttag(tagname) : Register the tagname as one able to change context
|
30 |
|
|
# if not registerd - the close tag will be ignored
|
31 |
|
|
# too if outside of the specified context!
|
32 |
williamc |
1.1 |
|
33 |
|
|
|
34 |
|
|
package ActiveDoc::Parse;
|
35 |
|
|
require 5.004;
|
36 |
|
|
use ActiveDoc::Switcher;
|
37 |
|
|
use ActiveDoc::TagContainer;
|
38 |
|
|
use ActiveDoc::GroupChecker;
|
39 |
sashby |
1.6 |
use Utilities::Verbose;
|
40 |
williamc |
1.1 |
|
41 |
sashby |
1.6 |
@ISA=qw(Utilities::Verbose);
|
42 |
williamc |
1.1 |
|
43 |
sashby |
1.6 |
sub new
|
44 |
|
|
{
|
45 |
|
|
my $class=shift;
|
46 |
|
|
$self={};
|
47 |
|
|
bless $self, $class;
|
48 |
|
|
$self->init();
|
49 |
|
|
return $self;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
sub init
|
53 |
|
|
{
|
54 |
|
|
my $self=shift;
|
55 |
|
|
$self->{gc}=GroupChecker->new();
|
56 |
|
|
$self->{gc}->include("all");
|
57 |
|
|
$self->{tags}=ActiveDoc::TagContainer->new();
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
sub parse
|
61 |
|
|
{
|
62 |
|
|
my $self=shift;
|
63 |
|
|
my $file=shift;
|
64 |
|
|
|
65 |
|
|
# basic setup of switcher
|
66 |
|
|
$self->{switch}=ActiveDoc::Switcher->new($file);
|
67 |
|
|
$self->{switch}->usegroupchecker($self->{gc});
|
68 |
|
|
$self->{switch}->usetags($self->{tags});
|
69 |
|
|
|
70 |
|
|
# do we need to switch on the streamer?
|
71 |
|
|
if ( @_ )
|
72 |
|
|
{
|
73 |
|
|
$fh=shift;
|
74 |
|
|
$self->{switch}->stream($fh);
|
75 |
|
|
foreach $tag ( @_ )
|
76 |
|
|
{
|
77 |
|
|
$self->{switch}->streamexclude($tag);
|
78 |
|
|
}
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
# -- parse
|
82 |
|
|
$self->{switch}->parse();
|
83 |
|
|
undef $self->{switch};
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
sub line
|
87 |
|
|
{
|
88 |
|
|
my $self=shift;
|
89 |
|
|
|
90 |
|
|
if ( defined $self->{switch} )
|
91 |
|
|
{
|
92 |
|
|
return $self->{switch}->line();
|
93 |
|
|
}
|
94 |
|
|
return undef;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
sub tagstartline
|
98 |
|
|
{
|
99 |
|
|
my $self=shift;
|
100 |
|
|
|
101 |
|
|
if ( defined $self->{switch} )
|
102 |
|
|
{
|
103 |
|
|
return $self->{switch}->tagstartline();
|
104 |
|
|
}
|
105 |
|
|
return undef;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
sub includeparse
|
109 |
|
|
{
|
110 |
|
|
my $self=shift;
|
111 |
|
|
my $obj=shift;
|
112 |
|
|
my $tag;
|
113 |
|
|
|
114 |
|
|
# copy the tags from the remote parse object
|
115 |
|
|
foreach $tag ( $obj->tags() )
|
116 |
|
|
{
|
117 |
|
|
$self->addtag($tag,$obj->{tags}->tagsettings($tag));
|
118 |
|
|
}
|
119 |
|
|
# now the group settings
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
sub addtag
|
123 |
|
|
{
|
124 |
|
|
my $self=shift;
|
125 |
|
|
|
126 |
|
|
$self->{tags}->addtag(@_);
|
127 |
|
|
$self->verbose(">> Adding tag ".@_." ");
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
sub addgrouptags
|
131 |
|
|
{
|
132 |
|
|
my $self=shift;
|
133 |
|
|
|
134 |
|
|
$self->verbose(">> Adding a group tag");
|
135 |
|
|
$self->{tags}->addtag("Group", \&Group_Start,$self,
|
136 |
|
|
"", $self, \&Group_End, $self);
|
137 |
|
|
$self->{tags}->setgrouptag("Group");
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
sub addignoretags
|
141 |
|
|
{
|
142 |
|
|
my $self=shift;
|
143 |
|
|
|
144 |
|
|
$self->verbose(">> Adding an IGNORE tag");
|
145 |
|
|
$self->{gc}->exclude("ignore");
|
146 |
|
|
$self->{tags}->addtag("Ignore", \&Ignore_Start, $self,
|
147 |
|
|
"",$self, \&Ignore_End,$self);
|
148 |
|
|
$self->{tags}->setgrouptag("Ignore");
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
sub contexttag
|
152 |
|
|
{
|
153 |
|
|
my $self=shift;
|
154 |
|
|
my $name=shift;
|
155 |
|
|
|
156 |
|
|
$self->verbose("-- contexttag: ".$name." ");
|
157 |
|
|
$self->{tags}->setgrouptag($name);
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
sub opencontext
|
161 |
|
|
{
|
162 |
|
|
my $self=shift;
|
163 |
|
|
my $name=shift;
|
164 |
|
|
|
165 |
|
|
$self->verbose("-- opencontext: ".$name." ");
|
166 |
|
|
$self->{gc}->opencontext($name);
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
sub closecontext
|
170 |
|
|
{
|
171 |
|
|
my $self=shift;
|
172 |
|
|
my $name=shift;
|
173 |
|
|
|
174 |
|
|
$self->verbose("-- closecontext: ".$name." ");
|
175 |
|
|
$self->{gc}->closecontext($name);
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
sub includecontext
|
179 |
|
|
{
|
180 |
|
|
my $self=shift;
|
181 |
|
|
my $name=shift;
|
182 |
|
|
|
183 |
|
|
$self->verbose("-- includecontext : ".$name." ");
|
184 |
|
|
$self->{gc}->unexclude($name);
|
185 |
|
|
$self->{gc}->include($name);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
sub excludecontext
|
189 |
|
|
{
|
190 |
|
|
my $self=shift;
|
191 |
|
|
my $name=shift;
|
192 |
|
|
$self->verbose("-- excludecontext: ".$name." ");
|
193 |
|
|
$self->{gc}->exclude($name);
|
194 |
|
|
$self->{gc}->uninclude($name);
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
sub cleartags
|
198 |
|
|
{
|
199 |
|
|
my $self=shift;
|
200 |
|
|
$self->verbose(">> Clearing TAGS");
|
201 |
|
|
$self->{tags}->cleartags();
|
202 |
|
|
}
|
203 |
williamc |
1.3 |
|
204 |
|
|
sub tags {
|
205 |
|
|
my $self=shift;
|
206 |
sashby |
1.6 |
$self->verbose("-- tags");
|
207 |
williamc |
1.3 |
return $self->{tags}->tags();
|
208 |
|
|
}
|
209 |
|
|
|
210 |
williamc |
1.1 |
# --------- Basic Group Related Tags ---------------------------------
|
211 |
|
|
|
212 |
sashby |
1.6 |
sub Group_Start
|
213 |
|
|
{
|
214 |
|
|
my $self=shift;
|
215 |
|
|
my $name=shift;
|
216 |
|
|
my $vars=shift;
|
217 |
|
|
my $lastgp;
|
218 |
|
|
|
219 |
|
|
$self->verbose(">> Group_Start: ".$name." ");
|
220 |
|
|
$lastgp="group::".$$vars{name};
|
221 |
|
|
$self->{switch}->checkparam($name, 'name');
|
222 |
|
|
$self->{gc}->opencontext("group::".$$vars{name});
|
223 |
|
|
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
sub Group_End
|
227 |
|
|
{
|
228 |
|
|
my $self=shift;
|
229 |
|
|
my $name=shift;
|
230 |
|
|
my $lastgp;
|
231 |
|
|
|
232 |
|
|
$self->verbose(">> Group_End: ".$name." ");
|
233 |
|
|
$self->{gc}->closelastcontext("group");
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
sub Ignore_Start
|
237 |
|
|
{
|
238 |
|
|
my $self=shift;
|
239 |
|
|
my $name=shift;
|
240 |
|
|
|
241 |
|
|
$self->verbose(">> Ignore_Start: ".$name." ");
|
242 |
|
|
$self->{gc}->opencontext("ignore");
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
sub Ignore_End
|
246 |
|
|
{
|
247 |
|
|
my $self=shift;
|
248 |
|
|
|
249 |
|
|
$self->verbose(">> Ignore_End: ".$name." ");
|
250 |
|
|
$self->{gc}->closecontext("ignore");
|
251 |
|
|
}
|
252 |
williamc |
1.1 |
|