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.1.2.3 by williamc, Fri May 12 10:29:43 2000 UTC vs.
Revision 1.8 by muzaffar, Fri Jan 14 17:36:42 2011 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 ( -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 ( @_ ) {
158 <           $self->{filename}=shift;
159 <        }
160 <        return $self->{filename};
161 < }
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 $fhead=shift || "";
75 >   my $ftail=shift || "";
76 >   my $file=$self->filetoparse();
77 >
78 >   if ( -f $file )
79 >      {
80 >      if ( exists $self->{parsers}{$parselabel} )
81 >         {
82 >         $self->verbose("Parsing $parselabel in file $file");
83 >         $self->{currentparsename}=$parselabel;
84 >         $self->{currentparser}=$self->{parsers}{$parselabel};
85 >         # Parse and store the returned data in content (only for Streams style):
86 >         $self->{parsers}{$parselabel}->filehead($fhead);
87 >         $self->{parsers}{$parselabel}->filetail($ftail);
88 >         $self->{content} = $self->{parsers}{$parselabel}->parse($file,@_)->data();
89 >         delete $self->{currentparser};
90 >         $self->{currentparsename}="";
91 >         $self->verbose("Parse $parselabel Complete");
92 >         }
93 >      }
94 >   else
95 >      {
96 >      $self->error("Cannot parse \"$parselabel\" - file $file not known");
97 >      }
98 >   }
99 >
100 > sub parsefilelist()
101 >   {
102 >   my $self=shift;
103 >   my $parselabel=shift;
104 >   my ($filenames)=@_;
105 >
106 >   if ( exists $self->{parsers}{$parselabel} )
107 >      {
108 >      $self->verbose("ParsingFileList: Label = $parselabel (files = ".join(",",@$filenames)." ");
109 >      $self->{currentparsename}=$parselabel;
110 >      $self->{currentparser}=$self->{parsers}{$parselabel};
111 >      $self->{parsers}{$parselabel}->parsefilelist($filenames);
112 >      delete $self->{currentparser};
113 >      $self->{currentparsename}="";
114 >      $self->verbose("ParseFileList $parselabel Complete");
115 >      }
116 >   else
117 >      {
118 >      $self->error("Cannot parse \"$parselabel\" - Unknown parser!!");
119 >      }
120 >   }
121 >
122 > sub currentparsename()
123 >   {
124 >   my $self=shift;
125 >   @_?$self->{currentparsename}=shift
126 >      :(defined $self->{currentparsename}?$self->{currentparsename}:"");
127 >   }
128 >
129 > sub currentparser()
130 >   {
131 >   my $self=shift;
132 >   return $self->{currentparser};
133 >   }
134 >
135 > sub newparse()
136 >   {
137 >   my $self=shift;
138 >   my $parselabel=shift;
139 >   my $dataclass=shift;
140 >   my $parse_style=shift;
141 >   $dataclass ||= "ParsedDoc";
142 >   $parse_style ||= 'Objects';
143 >   $self->{parsers}{$parselabel}=ActiveDoc::Parse->new($dataclass,$parse_style,shift,shift);
144 >   }
145 >
146 > sub filetoparse()
147 >   {
148 >   my $self=shift;
149 >  
150 >   if ( @_ )
151 >      {
152 >      $self->{filename}=shift;
153 >      }
154 >   return $self->{filename};
155 > }
156 >
157 > sub content()
158 >   {
159 >   my $self=shift;
160 >   return $self->{content};
161 >   }
162  
163   # -------- Error Handling and Error services --------------
164 + sub error()
165 +   {
166 +   my $self=shift;
167 +   my $string=shift;
168 +  
169 +   die $string."\n";
170 +   }
171 +
172 + sub parseerror
173 +   {
174 +   my $self=shift;
175 +   my $string=shift;
176 +  
177 +   if ( $self->currentparsename() eq "" )
178 +      {
179 +      $self->error("Error In file ".$self->filenameref."\n".$string);
180 +      }
181 +   else
182 +      {
183 +      $line=$self->line();
184 +      print "Parse Error in ".$self->filenameref().", line ".
185 +         $line."\n";
186 +      print $string."\n";
187 +      exit;
188 +      }
189 +   }
190 +
191 + sub checktag()
192 +   {
193 +   my $self=shift;
194 +   my $tagname=shift;
195 +   my $hashref=shift;
196 +   my $param=shift;
197 +  
198 +   if ( ! exists $$hashref{$param} )
199 +      {
200 +      $self->parseerror("Incomplete Tag <$tagname> : $param required");
201 +      }
202 +   }
203 +
204 + # -- dummy tag routines
205 + sub doc()
206 +   {
207 +   my $self=shift;
208 +   }
209 +
210 + sub doc_()
211 +   {
212 +   my $self=shift;
213 +   }
214  
215 < 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 <
215 > 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines