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

Comparing COMP/SCRAM/src/ActiveDoc/Parse.pm (file contents):
Revision 1.6 by sashby, Wed Mar 27 17:35:48 2002 UTC vs.
Revision 1.9 by sashby, Tue Feb 27 11:59:42 2007 UTC

# Line 30 | Line 30
30   #                         if not registerd - the close tag will be ignored
31   #                         too if outside of the specified context!
32  
33
33   package ActiveDoc::Parse;
34   require 5.004;
35 < use ActiveDoc::Switcher;
37 < use ActiveDoc::TagContainer;
38 < use ActiveDoc::GroupChecker;
39 < use Utilities::Verbose;
40 <
41 < @ISA=qw(Utilities::Verbose);
35 > use XML::Parser;
36  
37 < sub new
37 > sub new()
38     {
39     my $class=shift;
40     $self={};
41     bless $self, $class;
42 <   $self->init();
42 >   my ($dataclass, $parse_style)=@_;
43 >
44 >   $self->{xmlparser} = new XML::Parser (
45 >                                         Style => $parse_style,
46 >                                         ParseParamEnt => 1,
47 >                                         ErrorContext => 3,
48 >                                         Pkg   => $dataclass);  
49     return $self;
50     }
51  
52 < sub init
52 > sub parsefilelist()
53     {
54     my $self=shift;
55 <   $self->{gc}=GroupChecker->new();
56 <   $self->{gc}->include("all");
57 <   $self->{tags}=ActiveDoc::TagContainer->new();
55 >   my ($files)=@_;
56 >   print __PACKAGE__."::parsefilelist(): Not used?\n";
57     }
58  
59 < sub parse
59 > sub parse()
60     {
61     my $self=shift;
62 <   my $file=shift;
63 <  
64 <   # basic setup of switcher
66 <   $self->{switch}=ActiveDoc::Switcher->new($file);
67 <   $self->{switch}->usegroupchecker($self->{gc});
68 <   $self->{switch}->usetags($self->{tags});
69 <
70 <   # do we need to switch on the streamer?
71 <   if ( @_ )
72 <      {
73 <      $fh=shift;
74 <      $self->{switch}->stream($fh);
75 <      foreach $tag ( @_ )
76 <         {
77 <         $self->{switch}->streamexclude($tag);
78 <         }
79 <      }
80 <
81 <   # -- parse
82 <   $self->{switch}->parse();
83 <   undef $self->{switch};
62 >   my ($file)=@_;
63 >   $self->{data} = $self->{xmlparser}->parse($self->getfilestring_($file));
64 >   return $self;
65     }
66  
67 < sub line
67 > sub getfilestring_()
68     {
69     my $self=shift;
70 <  
71 <   if ( defined $self->{switch} )
72 <      {
73 <      return $self->{switch}->line();
74 <      }
75 <   return undef;
70 >   my ($file)=@_;
71 >   open (IN, "< $file") or die __PACKAGE__.": Cannot read file $file: $!\n";
72 >   my $filestring = join("", <IN>);
73 >   close (IN) or die __PACKAGE__.": Cannot read file $file: $!\n";
74 >   # Strip spaces at the beginning and end of the line:
75 >   $filestring =~ s/^\s+//g;
76 >   $filestring =~ s/\s+$//g;
77 >   # Finally strip the newlines:
78 >   $filestring =~ s/\n//g;
79 >   # Strip out spaces in between tags:
80 >   $filestring =~ s/>\s+</></g;
81 >   $self->{filestring}=$filestring;
82 >   return $filestring;
83     }
84  
85 < sub tagstartline
85 > sub data()
86     {
87     my $self=shift;
88 <
101 <   if ( defined $self->{switch} )
102 <      {
103 <      return $self->{switch}->tagstartline();
104 <      }
105 <   return undef;
88 >   return $self->{data}->[0];
89     }
90  
91   sub includeparse
# Line 116 | Line 99 | sub includeparse
99        {
100        $self->addtag($tag,$obj->{tags}->tagsettings($tag));
101        }
119   # now the group settings
102     }
103  
104   sub addtag
105     {
106     my $self=shift;
125
107     $self->{tags}->addtag(@_);
127   $self->verbose(">> Adding tag ".@_." ");
128   }
129
130 sub addgrouptags
131   {
132   my $self=shift;
133  
134   $self->verbose(">> Adding a group tag");
135   $self->{tags}->addtag("Group", \&Group_Start,$self,
136                         "", $self, \&Group_End, $self);
137   $self->{tags}->setgrouptag("Group");
138   }
139
140 sub addignoretags
141   {
142   my $self=shift;
143
144   $self->verbose(">> Adding an IGNORE tag");
145   $self->{gc}->exclude("ignore");
146   $self->{tags}->addtag("Ignore", \&Ignore_Start, $self,
147                         "",$self, \&Ignore_End,$self);
148   $self->{tags}->setgrouptag("Ignore");
149   }
150
151 sub contexttag
152   {
153   my $self=shift;
154   my $name=shift;
155  
156   $self->verbose("-- contexttag: ".$name." ");
157   $self->{tags}->setgrouptag($name);
158   }
159
160 sub opencontext
161   {
162   my $self=shift;
163   my $name=shift;
164
165   $self->verbose("-- opencontext: ".$name." ");
166   $self->{gc}->opencontext($name);
167   }
168
169 sub closecontext
170   {
171   my $self=shift;
172   my $name=shift;
173
174   $self->verbose("-- closecontext: ".$name." ");
175   $self->{gc}->closecontext($name);
176   }
177
178 sub includecontext
179   {
180   my $self=shift;
181   my $name=shift;
182
183   $self->verbose("-- includecontext : ".$name." ");
184   $self->{gc}->unexclude($name);
185   $self->{gc}->include($name);
186   }
187
188 sub excludecontext
189   {
190   my $self=shift;
191   my $name=shift;
192   $self->verbose("-- excludecontext: ".$name." ");
193   $self->{gc}->exclude($name);
194   $self->{gc}->uninclude($name);
195   }
196
197 sub cleartags
198   {
199   my $self=shift;
200   $self->verbose(">> Clearing TAGS");
201   $self->{tags}->cleartags();
202   }
203
204 sub tags {
205         my $self=shift;
206         $self->verbose("-- tags");
207         return $self->{tags}->tags();
208 }
209
210 # ---------  Basic Group Related Tags ---------------------------------
211
212 sub Group_Start
213   {
214   my $self=shift;
215   my $name=shift;
216   my $vars=shift;
217   my $lastgp;
218
219   $self->verbose(">> Group_Start: ".$name." ");
220   $lastgp="group::".$$vars{name};
221   $self->{switch}->checkparam($name, 'name');
222   $self->{gc}->opencontext("group::".$$vars{name});
223  
224   }
225
226 sub Group_End
227   {
228   my $self=shift;
229   my $name=shift;
230   my $lastgp;
231  
232   $self->verbose(">> Group_End: ".$name." ");
233   $self->{gc}->closelastcontext("group");
234   }
235
236 sub Ignore_Start
237   {
238   my $self=shift;
239   my $name=shift;
240  
241   $self->verbose(">> Ignore_Start: ".$name." ");
242   $self->{gc}->opencontext("ignore");
243   }
244
245 sub Ignore_End
246   {
247   my $self=shift;
248
249   $self->verbose(">> Ignore_End: ".$name." ");
250   $self->{gc}->closecontext("ignore");
108     }
109  
110 + 1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines