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.5 by sashby, Fri Dec 10 13:41:36 2004 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 < }
59 <
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 < }
34 > sub new()
35 >   {
36 >   my $class=shift;
37 >   $self={};
38 >   bless $self, $class;
39 >   return $self;
40 >   }
41  
42 < sub _initdoc {
43 <        my $self=shift;
44 <        my $parsename=shift;
45 <
46 <        $self->{doctag}="DOC";
47 <        if ( @_ ) {
48 <          $self->{doctag}=shift;
49 <        }
50 <        $self->newparse($parsename);
88 <        $self->addtag($parsename,$self->{doctag},\&Doc_Start, $self);
89 < }
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 <        my $self=shift;
54 <        $self->{verbose}=shift;
55 < }
52 > sub verbosity()
53 >   {
54 >   my $self=shift;
55 >   $self->{verbose}=shift;
56 >   }
57  
58 < sub verbose {
59 <        my $self=shift;
60 <        my $string=shift;
61 <
62 <        if ( $self->{verbose} ) {
63 <          print ">".ref($self)."($self) : \n->".$string."\n";
64 <        }
65 < }
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 <        my $file=$self->filetoparse();
74 <        
111 <        if ( -f $file ) {
112 <          if ( exists $self->{parsers}{$parselabel} ) {
113 <            $self->verbose("Parsing $parselabel in file $file");
114 <            $self->{currentparsename}=$parselabel;
115 <            $self->{currentparser}=$self->{parsers}{$parselabel};
116 <            $self->{parsers}{$parselabel}->parse($file,@_);
117 <            delete $self->{currentparser};
118 <            $self->{currentparsename}="";
119 <            $self->verbose("Parse $parselabel Complete");
120 <          }
121 <        }
122 <        else {
123 <          $self->error("Cannot parse \"$parselabel\" - file $file not known");
124 <        }
125 < }
70 > sub parse()
71 >   {
72 >   my $self=shift;
73 >   $parselabel=shift;
74 >   my $file=$self->filetoparse();
75  
76 < sub parsefilelist
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;
# Line 146 | Line 115 | sub parsefilelist
115        }
116     }
117  
118 < sub currentparsename {
119 <        my $self=shift;
120 <        @_?$self->{currentparsename}=shift
121 <          :(defined $self->{currentparsename}?$self->{currentparsename}:"");
122 < }
123 <
155 < sub currentparser {
156 <        my $self=shift;
157 <        return $self->{currentparser};
158 < }
159 <
160 <
161 < sub newparse {
162 <        my $self=shift;
163 <        my $parselabel=shift;
164 <
165 <        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
166 < }
167 <
168 < sub addignoretags {
169 <        my $self=shift;
170 <        my $parselabel=shift;
171 <        $self->{parsers}{$parselabel}->addignoretags();
172 < }
173 <
174 < sub cleartags {
175 <        my $self=shift;
176 <        my $parselabel=shift;
177 <
178 <        $self->{parsers}{$parselabel}->cleartags();
179 < }
180 <
181 <
182 < sub includeparse {
183 <        my $self=shift;
184 <        my $parselabel=shift;
185 <        my $remoteparselabel=shift;
186 <        my $activedoc=shift;
187 <
188 <        # Some error trapping
189 <        if ( ! exists $self->{parsers}{$parselabel} ) {
190 <          $self->error("Unknown local parse name specified");
191 <        }
192 <        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
193 <          $self->error("Unknown parse name specified in remote obj $activedoc");
194 <        }
195 <
196 <        #
197 <        my $rp=$activedoc->{parsers}{$remoteparselabel};
198 <        $self->{parsers}{$parselabel}->includeparse($rp);
199 < }
200 <
201 < sub addtag {
202 <        my $self=shift;
203 <        my $parselabel=shift;
204 <        if ( ( $#_ != 6 ) && ( $#_ != 2) ) {
205 <                $self->error("Incorrect addtags specification\n".
206 <                                "called with :\n@_ \n");
207 <        }
208 <        $self->{parsers}{$parselabel}->addtag(@_);
209 < }
210 <
211 < sub filetoparse {
212 <        my $self=shift;
213 <
214 <        if ( @_ ) {
215 <           $self->{filename}=shift;
216 <        }
217 <        return $self->{filename};
218 < }
219 < # --------- Group services
220 < sub grouptag {
221 <        my $self=shift;
222 <        my $name=shift;
223 <        my $parselabel=shift;
224 <
225 <        $self->{parsers}{$parselabel}->contexttag($name);
226 < }
227 <
228 < sub opengroup {
229 <        my $self=shift;
230 <        my $name=shift;
231 <
232 <        if ( defined $self->currentparser ) {
233 <           $self->currentparser()->opencontext($name);
234 <        }
235 <        else {
236 <           $self->error("Cannot Call opengroup outside of a parse (".
237 <                        caller().")");
238 <        }
239 < }
118 > sub currentparsename()
119 >   {
120 >   my $self=shift;
121 >   @_?$self->{currentparsename}=shift
122 >      :(defined $self->{currentparsename}?$self->{currentparsename}:"");
123 >   }
124  
125 < sub closegroup {
126 <        my $self=shift;
127 <        my $name=shift;
128 <
129 <        if ( defined $self->currentparser ) {
246 <           $self->currentparser()->closecontext($name);
247 <        }
248 <        else {
249 <           $self->error("Cannot Call closegroup outside of a parse (".
250 <                        caller().")");
251 <        }
252 < }
125 > sub currentparser()
126 >   {
127 >   my $self=shift;
128 >   return $self->{currentparser};
129 >   }
130  
131 < sub allowgroup {
132 <        my $self=shift;
133 <        my $name=shift;
134 <        my $parselabel=shift;
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 <        $self->{parsers}{$parselabel}->includecontext($name);
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 disallowgroup {
154 <        my $self=shift;
155 <        my $name=shift;
156 <        my $parselabel=shift;
157 <
267 <        $self->{parsers}{$parselabel}->excludecontext($name);
268 < }
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 error {
169 <        my $self=shift;
170 <        my $string=shift;
171 <
172 <        die $string."\n";
173 < }
174 <
175 < sub parseerror {
176 <        my $self=shift;
177 <        my $string=shift;
178 <
179 <        if ( $self->currentparsename() eq "" ) {
180 <                $self->error("Error In file ".$self->filenameref."\n".$string);
181 <        }
182 <        else {
183 <         $line=$self->line();
184 <         print "Parse Error in ".$self->filenameref().", line ".
185 <                                        $line."\n";
290 <         print $string."\n";
291 <         exit;
292 <        }
293 < }
294 <
295 < sub checktag {
296 <        my $self=shift;
297 <        my $tagname=shift;
298 <        my $hashref=shift;
299 <        my $param=shift;
300 <
301 <        if ( ! exists $$hashref{$param} ) {
302 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
303 <        }
304 < }
305 <
306 < sub line {
307 <        my $self=shift;
308 <        return $self->{currentparser}->line();
309 < }
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 tagstartline {
188 <        my $self=shift;
189 <        return $self->{currentparser}->tagstartline();
190 < }
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 < # -- tag routines
201 < sub Doc_Start {
202 <        my $self=shift;
203 <        my $name=shift;
204 <        my $hashref=shift;
200 > # -- dummy tag routines
201 > sub doc()
202 >   {
203 >   my $self=shift;
204 >   }
205  
206 <        $self->checktag($name, $hashref, "type");
207 <        $self->checktag($name, $hashref, "version");
206 > sub doc_()
207 >   {
208 >   my $self=shift;
209 >   }
210  
211 <        $self->{doctype}=$$hashref{'type'};
326 <        $self->{docversion}=$$hashref{'version'};
327 < }
211 > 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines