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! |
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 |
|
# --------------- Error handling routines --------------- |
38 |
|
# verbose(string) : Print string in verbosity mode |
39 |
|
# verbosity(0|1) : verbosity off|on |
51 |
|
my $class=shift; |
52 |
|
$self={}; |
53 |
|
bless $self, $class; |
54 |
< |
$self->verbose("New SimpleDoc (".ref($self).") Created"); |
52 |
< |
$self->init(@_); |
54 |
> |
$self->_initdoc("doc",@_); |
55 |
|
return $self; |
56 |
|
} |
57 |
|
|
58 |
< |
sub init { |
59 |
< |
# dummy to be overridden by inheriting class |
58 |
> |
sub doctype { |
59 |
> |
my $self=shift; |
60 |
> |
my $rv=1; |
61 |
> |
|
62 |
> |
undef $self->{docversion}; |
63 |
> |
undef $self->{doctype}; |
64 |
> |
$self->parse("doc"); |
65 |
> |
if ( ! defined $self->{doctype} ) { |
66 |
> |
$self->parseerror("Unable to find <".$self->{doctag}.">"); |
67 |
> |
} |
68 |
> |
return ($self->{doctype},$self->{docversion}); |
69 |
> |
} |
70 |
> |
|
71 |
> |
sub _initdoc { |
72 |
> |
my $self=shift; |
73 |
> |
my $parsename=shift; |
74 |
> |
|
75 |
> |
$self->{doctag}="DOC"; |
76 |
> |
if ( @_ ) { |
77 |
> |
$self->{doctag}=shift; |
78 |
> |
} |
79 |
> |
$self->newparse($parsename); |
80 |
> |
$self->addtag($parsename,$self->{doctag},\&Doc_Start, $self); |
81 |
|
} |
82 |
|
|
83 |
|
sub verbosity { |
100 |
|
$parselabel=shift; |
101 |
|
|
102 |
|
my $file=$self->filetoparse(); |
103 |
< |
if ( $file ) { |
103 |
> |
if ( -f $file ) { |
104 |
|
if ( exists $self->{parsers}{$parselabel} ) { |
105 |
|
$self->verbose("Parsing $parselabel in file $file"); |
106 |
|
$self->{currentparsename}=$parselabel; |
112 |
|
} |
113 |
|
} |
114 |
|
else { |
115 |
< |
$self->error("Cannot parse $parselabel - file not known"); |
115 |
> |
$self->error("Cannot parse \"$parselabel\" - file $file not known"); |
116 |
|
} |
117 |
|
} |
118 |
|
|
172 |
|
sub addtag { |
173 |
|
my $self=shift; |
174 |
|
my $parselabel=shift; |
175 |
< |
if ( $#_ != 6 ) { |
175 |
> |
if ( ( $#_ != 6 ) && ( $#_ != 2) ) { |
176 |
|
$self->error("Incorrect addtags specification\n". |
177 |
|
"called with :\n@_ \n"); |
178 |
|
} |
252 |
|
my $string=shift; |
253 |
|
|
254 |
|
if ( $self->currentparsename() eq "" ) { |
255 |
< |
$self->error($string); |
255 |
> |
$self->error("Error In file ".$self->filetoparse."\n".$string); |
256 |
|
} |
257 |
|
else { |
258 |
|
$line=$self->line(); |
284 |
|
return $self->{currentparser}->tagstartline(); |
285 |
|
} |
286 |
|
|
287 |
+ |
# -- tag routines |
288 |
+ |
sub Doc_Start { |
289 |
+ |
my $self=shift; |
290 |
+ |
my $name=shift; |
291 |
+ |
my $hashref=shift; |
292 |
+ |
|
293 |
+ |
$self->checktag($name, $hashref, "type"); |
294 |
+ |
$self->checktag($name, $hashref, "version"); |
295 |
+ |
|
296 |
+ |
$self->{doctype}=$$hashref{'type'}; |
297 |
+ |
$self->{docversion}=$$hashref{'version'}; |
298 |
+ |
} |