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.4 by sashby, Tue Dec 4 19:24:04 2001 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 < }
109 <
110 < sub addignoretags {
111 <        my $self=shift;
112 <        my $parselabel=shift;
113 <        $self->{parsers}{$parselabel}->addignoretags();
114 < }
115 <
116 < sub cleartags {
117 <        my $self=shift;
118 <        my $parselabel=shift;
119 <
120 <        $self->{parsers}{$parselabel}->cleartags();
121 < }
122 <
123 <
124 < sub includeparse {
125 <        my $self=shift;
126 <        my $parselabel=shift;
127 <        my $remoteparselabel=shift;
128 <        my $activedoc=shift;
129 <
130 <        # Some error trapping
131 <        if ( ! exists $self->{parsers}{$parselabel} ) {
132 <          $self->error("Unknown local parse name specified");
133 <        }
134 <        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
135 <          $self->error("Unknown parse name specified in remote obj $activedoc");
136 <        }
137 <
138 <        #
139 <        my $rp=$activedoc->{parsers}{$remoteparselabel};
140 <        $self->{parsers}{$parselabel}->includeparse($rp);
141 < }
142 <
143 < sub addtag {
144 <        my $self=shift;
145 <        my $parselabel=shift;
146 <        if ( ( $#_ != 6 ) && ( $#_ != 2) ) {
147 <                $self->error("Incorrect addtags specification\n".
148 <                                "called with :\n@_ \n");
149 <        }
150 <        $self->{parsers}{$parselabel}->addtag(@_);
151 < }
152 <
153 < sub filetoparse {
154 <        my $self=shift;
155 <
156 <        if ( @_ ) {
157 <           $self->{filename}=shift;
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 < }
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 {
251 <        my $self=shift;
252 <        my $string=shift;
253 <
254 <        die $string."\n";
255 < }
256 <
257 < sub parseerror {
258 <        my $self=shift;
259 <        my $string=shift;
260 <
261 <        if ( $self->currentparsename() eq "" ) {
262 <                $self->error("Error In file ".$self->filenameref."\n".$string);
263 <        }
264 <        else {
265 <         $line=$self->line();
266 <         print "Parse Error in ".$self->filenameref().", line ".
267 <                                        $line."\n";
268 <         print $string."\n";
269 <         exit;
270 <        }
271 < }
272 <
273 < sub checktag {
274 <        my $self=shift;
275 <        my $tagname=shift;
276 <        my $hashref=shift;
277 <        my $param=shift;
278 <
279 <        if ( ! exists $$hashref{$param} ) {
280 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
281 <        }
282 < }
283 <
284 < sub line {
285 <        my $self=shift;
286 <        return $self->{currentparser}->line();
287 < }
288 <
289 < sub tagstartline {
290 <        my $self=shift;
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 < }
211 > 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines