ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleDoc.pm
Revision: 1.1.2.3.2.2
Committed: Thu Aug 10 14:40:10 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
CVS Tags: V0_14_0
Changes since 1.1.2.3.2.1: +0 -3 lines
Log Message:
do not die if no dock type

File Contents

# Content
1 #
2 # SimpleDoc.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # -----------
8 # Simple multi parsing functionality and group manipulation
9 #
10 # Interface
11 # ---------
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]) :
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
24 # one object to another
25 # currentparser() : return the current parser object
26 # currentparsename([name]) : get/set current parse name
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 # --------------- Error handling routines ---------------
38 # verbose(string) : Print string in verbosity mode
39 # verbosity(0|1) : verbosity off|on
40 # line() : return the current line number in the current parse
41 # tagstartline() : return the line number where the current tag was
42 # opened
43 # parseerror(string) : print error and associate with line number etc.
44 # error(string) : handle an error
45
46 package ActiveDoc::SimpleDoc;
47 require 5.004;
48 use ActiveDoc::Parse;
49
50 sub new {
51 my $class=shift;
52 $self={};
53 bless $self, $class;
54 $self->_initdoc("doc",@_);
55 return $self;
56 }
57
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 return ($self->{doctype},$self->{docversion});
66 }
67
68 sub _initdoc {
69 my $self=shift;
70 my $parsename=shift;
71
72 $self->{doctag}="DOC";
73 if ( @_ ) {
74 $self->{doctag}=shift;
75 }
76 $self->newparse($parsename);
77 $self->addtag($parsename,$self->{doctag},\&Doc_Start, $self);
78 }
79
80 sub verbosity {
81 my $self=shift;
82 $self->{verbose}=shift;
83 }
84
85 sub verbose {
86 my $self=shift;
87 my $string=shift;
88
89 if ( $self->{verbose} ) {
90 print ">".ref($self)."($self) : \n->".$string."\n";
91 }
92 }
93
94 # ----- parse related routines --------------
95 sub parse {
96 my $self=shift;
97 $parselabel=shift;
98
99 my $file=$self->filetoparse();
100 if ( -f $file ) {
101 if ( exists $self->{parsers}{$parselabel} ) {
102 $self->verbose("Parsing $parselabel in file $file");
103 $self->{currentparsename}=$parselabel;
104 $self->{currentparser}=$self->{parsers}{$parselabel};
105 $self->{parsers}{$parselabel}->parse($file,@_);
106 delete $self->{currentparser};
107 $self->{currentparsename}="";
108 $self->verbose("Parse $parselabel Complete");
109 }
110 }
111 else {
112 $self->error("Cannot parse \"$parselabel\" - file $file not known");
113 }
114 }
115
116 sub currentparsename {
117 my $self=shift;
118 @_?$self->{currentparsename}=shift
119 :(defined $self->{currentparsename}?$self->{currentparsename}:"");
120 }
121
122 sub currentparser {
123 my $self=shift;
124 return $self->{currentparser};
125 }
126
127
128 sub newparse {
129 my $self=shift;
130 my $parselabel=shift;
131
132 $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
133 # $self->{parsers}{$parselabel}->addgrouptags();
134 }
135
136 sub addignoretags {
137 my $self=shift;
138 my $parselabel=shift;
139 $self->{parsers}{$parselabel}->addignoretags();
140 }
141
142 sub cleartags {
143 my $self=shift;
144 my $parselabel=shift;
145
146 $self->{parsers}{$parselabel}->cleartags();
147 }
148
149
150 sub includeparse {
151 my $self=shift;
152 my $parselabel=shift;
153 my $remoteparselabel=shift;
154 my $activedoc=shift;
155
156 # Some error trapping
157 if ( ! exists $self->{parsers}{$parselabel} ) {
158 $self->error("Unknown local parse name specified");
159 }
160 if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
161 $self->error("Unknown parse name specified in remote obj $activedoc");
162 }
163
164 #
165 my $rp=$activedoc->{parsers}{$remoteparselabel};
166 $self->{parsers}{$parselabel}->includeparse($rp);
167 }
168
169 sub addtag {
170 my $self=shift;
171 my $parselabel=shift;
172 if ( ( $#_ != 6 ) && ( $#_ != 2) ) {
173 $self->error("Incorrect addtags specification\n".
174 "called with :\n@_ \n");
175 }
176 $self->{parsers}{$parselabel}->addtag(@_);
177 }
178
179 sub filetoparse {
180 my $self=shift;
181
182 if ( @_ ) {
183 $self->{filename}=shift;
184 }
185 return $self->{filename};
186 }
187 # --------- Group services
188 sub grouptag {
189 my $self=shift;
190 my $name=shift;
191 my $parselabel=shift;
192
193 $self->{parsers}{$parselabel}->contexttag($name);
194 }
195
196 sub opengroup {
197 my $self=shift;
198 my $name=shift;
199
200 if ( defined $self->currentparser ) {
201 $self->currentparser()->opencontext($name);
202 }
203 else {
204 $self->error("Cannot Call opengroup outside of a parse (".
205 caller().")");
206 }
207 }
208
209 sub closegroup {
210 my $self=shift;
211 my $name=shift;
212
213 if ( defined $self->currentparser ) {
214 $self->currentparser()->closecontext($name);
215 }
216 else {
217 $self->error("Cannot Call closegroup outside of a parse (".
218 caller().")");
219 }
220 }
221
222 sub allowgroup {
223 my $self=shift;
224 my $name=shift;
225 my $parselabel=shift;
226
227 $self->{parsers}{$parselabel}->includecontext($name);
228 }
229
230 sub disallowgroup {
231 my $self=shift;
232 my $name=shift;
233 my $parselabel=shift;
234
235 $self->{parsers}{$parselabel}->excludecontext($name);
236 }
237
238 # -------- Error Handling and Error services --------------
239
240 sub error {
241 my $self=shift;
242 my $string=shift;
243
244 die $string."\n";
245 }
246
247 sub parseerror {
248 my $self=shift;
249 my $string=shift;
250
251 if ( $self->currentparsename() eq "" ) {
252 $self->error("Error In file ".$self->filetoparse."\n".$string);
253 }
254 else {
255 $line=$self->line();
256 print "Parse Error in ".$self->filetoparse().", line ".
257 $line."\n";
258 print $string."\n";
259 exit;
260 }
261 }
262
263 sub checktag {
264 my $self=shift;
265 my $tagname=shift;
266 my $hashref=shift;
267 my $param=shift;
268
269 if ( ! exists $$hashref{$param} ) {
270 $self->parseerror("Incomplete Tag <$tagname> : $param required");
271 }
272 }
273
274 sub line {
275 my $self=shift;
276 return $self->{currentparser}->line();
277 }
278
279 sub tagstartline {
280 my $self=shift;
281 return $self->{currentparser}->tagstartline();
282 }
283
284 # -- tag routines
285 sub Doc_Start {
286 my $self=shift;
287 my $name=shift;
288 my $hashref=shift;
289
290 $self->checktag($name, $hashref, "type");
291 $self->checktag($name, $hashref, "version");
292
293 $self->{doctype}=$$hashref{'type'};
294 $self->{docversion}=$$hashref{'version'};
295 }