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.2 by williamc, Fri Apr 7 13:40:10 2000 UTC vs.
Revision 1.6 by sashby, Tue Feb 27 11:59:42 2007 UTC

# Line 9 | Line 9
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
16 # addtag(parselabel,tagname,start,obj,text,obj,end,obj) :
17 #                                Add tags to the parse given by label
18 # grouptag(tagname, parselabel) : Allow a tag to switch context
19 #                                 - 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
22 # includeparse(local_parsename, objparsename, activedoc) : copy the parse from
23 #                                                       one object to another
19   # currentparser() : return the current parser object
20   # currentparsename([name]) : get/set current parse name
21   #
22 < # addignoretags(parsename) : add <ignore> </igonore> tags funtionality to the
23 < #                               specified parse
29 < # opengroup(name) : declare a group to be open
30 < # closegroup(name) : declare a group to be closed
31 < # allowgroup(name,parse) : allow a group so named
32 < # disallowgroup(name,parse) : disallow the named group
33 < # restoregroup(name,parse) : restore group access setting (that before last change)
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
37 # line()                : return the current line number in the current parse
38 # tagstartline()        : return the line number where the current tag was
39 #                         opened
27   # parseerror(string)   :  print error and associate with line number etc.
28   # error(string) : handle an error
29  
# Line 44 | 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->verbose("New SimpleDoc (".ref($self).") Created");
39 <        $self->init(@_);
40 <        return $self;
41 < }
42 <
43 < sub init {
44 <        # dummy to be overridden by inheriting class
45 < }
46 <
47 < sub verbosity {
48 <        my $self=shift;
49 <        $self->{verbose}=shift;
50 < }
51 <
52 < sub verbose {
53 <        my $self=shift;
54 <        my $string=shift;
55 <
56 <        if ( $self->{verbose} ) {
57 <          print ">".ref($self)."($self) : \n->".$string."\n";
58 <        }
59 < }
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 ( $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 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 ) {
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 ( @_ ) {
163 <           $self->{filename}=shift;
164 <        }
165 <        return $self->{filename};
166 < }
167 < # --------- Group services
168 < sub grouptag {
169 <        my $self=shift;
170 <        my $name=shift;
171 <        my $parselabel=shift;
172 <
173 <        $self->{parsers}{$parselabel}->contexttag($name);
174 < }
175 <
176 < sub opengroup {
177 <        my $self=shift;
178 <        my $name=shift;
179 <
180 <        if ( defined $self->currentparser ) {
181 <           $self->currentparser()->opencontext($name);
182 <        }
183 <        else {
184 <           $self->error("Cannot Call opengroup outside of a parse (".
185 <                        caller().")");
186 <        }
187 < }
188 <
189 < sub closegroup {
190 <        my $self=shift;
191 <        my $name=shift;
192 <
193 <        if ( defined $self->currentparser ) {
194 <           $self->currentparser()->closecontext($name);
195 <        }
196 <        else {
197 <           $self->error("Cannot Call closegroup outside of a parse (".
198 <                        caller().")");
199 <        }
200 < }
201 <
202 < sub allowgroup {
203 <        my $self=shift;
204 <        my $name=shift;
205 <        my $parselabel=shift;
206 <
207 <        $self->{parsers}{$parselabel}->includecontext($name);
208 < }
209 <
210 < sub disallowgroup {
211 <        my $self=shift;
212 <        my $name=shift;
213 <        my $parselabel=shift;
214 <
215 <        $self->{parsers}{$parselabel}->excludecontext($name);
216 < }
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 {
221 <        my $self=shift;
222 <        my $string=shift;
223 <
224 <        die $string."\n";
225 < }
226 <
227 < sub parseerror {
228 <        my $self=shift;
229 <        my $string=shift;
230 <
231 <        if ( $self->currentparsename() eq "" ) {
232 <                $self->error($string);
233 <        }
234 <        else {
235 <         $line=$self->line();
236 <         print "Parse Error in ".$self->filetoparse().", line ".
237 <                                        $line."\n";
238 <         print $string."\n";
239 <         exit;
240 <        }
241 < }
242 <
243 < sub checktag {
244 <        my $self=shift;
245 <        my $tagname=shift;
246 <        my $hashref=shift;
247 <        my $param=shift;
248 <
249 <        if ( ! exists $$hashref{$param} ) {
250 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
251 <        }
252 < }
253 <
254 < sub line {
255 <        my $self=shift;
256 <        return $self->{currentparser}->line();
257 < }
258 <
259 < sub tagstartline {
260 <        my $self=shift;
261 <        return $self->{currentparser}->tagstartline();
262 < }
263 <
211 > 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines