5 |
|
# |
6 |
|
# Description |
7 |
|
# ----------- |
8 |
< |
# Simple multi parsing functionality |
8 |
> |
# Simple multi parsing functionality and group manipulation |
9 |
|
# |
10 |
|
# Interface |
11 |
|
# --------- |
12 |
< |
# new() : A new ActiveDoc object |
12 |
> |
# new([DocVersionTag]) : A new ActiveDoc object. You can also |
13 |
> |
# specify an alternative doc version tag |
14 |
|
# filetoparse([filename]) : Set/Return the filename of document |
15 |
|
# newparse(parselabel) : Create a new parse type |
16 |
|
# parse(parselabel) : Parse the document file for the given parse level |
17 |
< |
# addtag(parselabel,tagname,start,obj,text,obj,end,obj) : |
17 |
> |
# addtag(parselabel,tagname,start,obj,[text,obj,end,obj]) : |
18 |
|
# Add tags to the parse given by label |
19 |
+ |
# grouptag(tagname, parselabel) : Allow a tag to switch context |
20 |
+ |
# - if not you can never turn a context off! |
21 |
|
# checktag(tagname, hashref, param) : check for existence of param in |
22 |
|
# hashref from a tag call |
23 |
|
# includeparse(local_parsename, objparsename, activedoc) : copy the parse from |
27 |
|
# |
28 |
|
# addignoretags(parsename) : add <ignore> </igonore> tags funtionality to the |
29 |
|
# specified parse |
30 |
+ |
# opengroup(name) : declare a group to be open |
31 |
+ |
# closegroup(name) : declare a group to be closed |
32 |
+ |
# allowgroup(name,parse) : allow a group so named |
33 |
+ |
# disallowgroup(name,parse) : disallow the named group |
34 |
+ |
# restoregroup(name,parse) : restore group access setting (that before last change) |
35 |
+ |
# doctype() : return the (type,version) of the document |
36 |
+ |
# as specified by the DocVersionTag |
37 |
+ |
# filenameref(string) : A string to refer to the file in parse error messages |
38 |
+ |
# etc. Default is filetoparse |
39 |
|
# --------------- Error handling routines --------------- |
40 |
|
# verbose(string) : Print string in verbosity mode |
41 |
|
# verbosity(0|1) : verbosity off|on |
53 |
|
my $class=shift; |
54 |
|
$self={}; |
55 |
|
bless $self, $class; |
56 |
< |
$self->verbose("New SimpleDoc (".ref($self).") Created"); |
45 |
< |
$self->init(@_); |
56 |
> |
$self->_initdoc("doc",@_); |
57 |
|
return $self; |
58 |
|
} |
59 |
|
|
60 |
< |
sub init { |
61 |
< |
# dummy to be overridden by inheriting class |
60 |
> |
sub doctype { |
61 |
> |
my $self=shift; |
62 |
> |
my $rv=1; |
63 |
> |
|
64 |
> |
undef $self->{docversion}; |
65 |
> |
undef $self->{doctype}; |
66 |
> |
$self->parse("doc"); |
67 |
> |
return ($self->{doctype},$self->{docversion}); |
68 |
> |
} |
69 |
> |
|
70 |
> |
sub filenameref { |
71 |
> |
my $self=shift; |
72 |
> |
if ( @_ ) { |
73 |
> |
$self->{filenameref}=shift; |
74 |
> |
} |
75 |
> |
return (defined $self->{filenameref})?$self->{filenameref} |
76 |
> |
:$self->filetoparse(); |
77 |
> |
} |
78 |
> |
|
79 |
> |
sub _initdoc { |
80 |
> |
my $self=shift; |
81 |
> |
my $parsename=shift; |
82 |
> |
|
83 |
> |
$self->{doctag}="DOC"; |
84 |
> |
if ( @_ ) { |
85 |
> |
$self->{doctag}=shift; |
86 |
> |
} |
87 |
> |
$self->newparse($parsename); |
88 |
> |
$self->addtag($parsename,$self->{doctag},\&Doc_Start, $self); |
89 |
|
} |
90 |
|
|
91 |
|
sub verbosity { |
108 |
|
$parselabel=shift; |
109 |
|
|
110 |
|
my $file=$self->filetoparse(); |
111 |
< |
if ( $file ) { |
111 |
> |
if ( -f $file ) { |
112 |
|
if ( exists $self->{parsers}{$parselabel} ) { |
113 |
|
$self->verbose("Parsing $parselabel in file $file"); |
114 |
|
$self->{currentparsename}=$parselabel; |
120 |
|
} |
121 |
|
} |
122 |
|
else { |
123 |
< |
$self->error("Cannot parse $parselabel - file not known"); |
123 |
> |
$self->error("Cannot parse \"$parselabel\" - file $file not known"); |
124 |
|
} |
125 |
|
} |
126 |
|
|
141 |
|
my $parselabel=shift; |
142 |
|
|
143 |
|
$self->{parsers}{$parselabel}=ActiveDoc::Parse->new(); |
106 |
– |
# $self->{parsers}{$parselabel}->addgrouptags(); |
144 |
|
} |
145 |
|
|
146 |
|
sub addignoretags { |
179 |
|
sub addtag { |
180 |
|
my $self=shift; |
181 |
|
my $parselabel=shift; |
182 |
< |
if ( $#_ != 6 ) { |
182 |
> |
if ( ( $#_ != 6 ) && ( $#_ != 2) ) { |
183 |
|
$self->error("Incorrect addtags specification\n". |
184 |
|
"called with :\n@_ \n"); |
185 |
|
} |
194 |
|
} |
195 |
|
return $self->{filename}; |
196 |
|
} |
197 |
+ |
# --------- Group services |
198 |
+ |
sub grouptag { |
199 |
+ |
my $self=shift; |
200 |
+ |
my $name=shift; |
201 |
+ |
my $parselabel=shift; |
202 |
+ |
|
203 |
+ |
$self->{parsers}{$parselabel}->contexttag($name); |
204 |
+ |
} |
205 |
+ |
|
206 |
+ |
sub opengroup { |
207 |
+ |
my $self=shift; |
208 |
+ |
my $name=shift; |
209 |
+ |
|
210 |
+ |
if ( defined $self->currentparser ) { |
211 |
+ |
$self->currentparser()->opencontext($name); |
212 |
+ |
} |
213 |
+ |
else { |
214 |
+ |
$self->error("Cannot Call opengroup outside of a parse (". |
215 |
+ |
caller().")"); |
216 |
+ |
} |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
sub closegroup { |
220 |
+ |
my $self=shift; |
221 |
+ |
my $name=shift; |
222 |
+ |
|
223 |
+ |
if ( defined $self->currentparser ) { |
224 |
+ |
$self->currentparser()->closecontext($name); |
225 |
+ |
} |
226 |
+ |
else { |
227 |
+ |
$self->error("Cannot Call closegroup outside of a parse (". |
228 |
+ |
caller().")"); |
229 |
+ |
} |
230 |
+ |
} |
231 |
+ |
|
232 |
+ |
sub allowgroup { |
233 |
+ |
my $self=shift; |
234 |
+ |
my $name=shift; |
235 |
+ |
my $parselabel=shift; |
236 |
+ |
|
237 |
+ |
$self->{parsers}{$parselabel}->includecontext($name); |
238 |
+ |
} |
239 |
+ |
|
240 |
+ |
sub disallowgroup { |
241 |
+ |
my $self=shift; |
242 |
+ |
my $name=shift; |
243 |
+ |
my $parselabel=shift; |
244 |
+ |
|
245 |
+ |
$self->{parsers}{$parselabel}->excludecontext($name); |
246 |
+ |
} |
247 |
|
|
248 |
|
# -------- Error Handling and Error services -------------- |
249 |
|
|
259 |
|
my $string=shift; |
260 |
|
|
261 |
|
if ( $self->currentparsename() eq "" ) { |
262 |
< |
$self->error($string); |
262 |
> |
$self->error("Error In file ".$self->filenameref."\n".$string); |
263 |
|
} |
264 |
|
else { |
265 |
|
$line=$self->line(); |
266 |
< |
print "Parse Error in ".$self->filetoparse().", line ". |
266 |
> |
print "Parse Error in ".$self->filenameref().", line ". |
267 |
|
$line."\n"; |
268 |
|
print $string."\n"; |
269 |
|
exit; |
291 |
|
return $self->{currentparser}->tagstartline(); |
292 |
|
} |
293 |
|
|
294 |
+ |
# -- tag routines |
295 |
+ |
sub Doc_Start { |
296 |
+ |
my $self=shift; |
297 |
+ |
my $name=shift; |
298 |
+ |
my $hashref=shift; |
299 |
+ |
|
300 |
+ |
$self->checktag($name, $hashref, "type"); |
301 |
+ |
$self->checktag($name, $hashref, "version"); |
302 |
+ |
|
303 |
+ |
$self->{doctype}=$$hashref{'type'}; |
304 |
+ |
$self->{docversion}=$$hashref{'version'}; |
305 |
+ |
} |