ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleDoc.pm
(Generate patch)

Comparing COMP/SCRAM/src/ActiveDoc/SimpleDoc.pm (file contents):
Revision 1.3 by williamc, Mon Aug 28 07:43:21 2000 UTC vs.
Revision 1.6 by sashby, Tue Feb 27 11:59:42 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines