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

Comparing COMP/SCRAM/src/ActiveDoc/Switcher.pm (file contents):
Revision 1.8 by williamc, Wed Nov 17 17:57:33 1999 UTC vs.
Revision 1.16 by williamc, Tue Nov 14 15:20:55 2000 UTC

# Line 13 | Line 13
13   # usegroupchecker(groupchecker)    : Set a groupchecker
14   # parse()                          : Parse the file                            
15   # line()                    : return the current line number of the parse
16 + # tagstartline()            : return the line number on which the current
17 + #                             tag was opened
18   # stream(filehandle)        : stream output to the filehandle if not handled
19   #                               in any other way
20   package ActiveDoc::Switcher;
# Line 103 | Line 105 | sub parse {
105           } # end char while
106          } # End String while loop
107          undef $filehandle;
108 <        $self->_printstream();
108 >        # make sure we close the last buffer
109 >        $self->_calltag($self->{textcontext}, $self->{textcontext},
110 >                                                        $self->_getstore());
111 >        #$self->_printstream();
112   }
113  
114   #
# Line 113 | Line 118 | sub line {
118          my $self=shift;
119          return $self->{linecount};
120   }
121 +
122 + # return the line the current tag was opened
123 + sub tagstartline {
124 +        my $self=shift;
125 +        $self->{tagstart};
126 + }
127   # --------------- Utility routines ----------------------------
128  
129   #
# Line 138 | Line 149 | sub _checkchar {
149  
150          # ---- In a tag
151          if ( $self->{tagcontext}=~/tag/ ) {
152 +           $self->{tagbuff}=$self->{tagbuff}.$char;
153             if ( ! $self->_quotetest($char) ) {
154              if ( ! $self->_labeltest($char) ) {
155               if ( $char eq ">") { $self->_closetag(); }
# Line 160 | Line 172 | sub _nextchar() {
172          my $self=shift;
173          my $char;
174          $char=substr($self->{currentline},$self->{stringpos}++,1);
175 < #       print "Debug : Fetching character $char\n";
175 >        #print "Debug : Fetching character $char\n";
176  
177          # Keep a record for any stream processes
178          $self->{streamstore}=$self->{streamstore}.$char;
# Line 172 | Line 184 | sub _opentag {
184          my $self=shift;
185          my $char;
186  
187 +        # Keep a record of where the tag started
188 +        $self->{tagstart}=$self->line();
189 +
190          # Close the last text segment
191          $self->{streamtmp}=$self->_popstream();
192          $self->_calltag($self->{textcontext}, $self->{textcontext},
# Line 181 | Line 196 | sub _opentag {
196  
197          # Do we have an opening or closing tag?
198          if ( ($char=$self->_nextchar()) eq "/" ) { #we have a closing tag
199 +          $self->{tagbuff}="<".$char;
200            $self->{tagcontext}="endtag";
201          }
202          else { # an opening tag
203 +          $self->{tagbuff}="<";
204            $self->{tagcontext}="starttag";
205            $self->_checkchar($char);
206          }
# Line 201 | Line 218 | sub _closetag {
218          $self->_closelabel();
219          
220          # -- Call the associated tag function if appropriate
221 <        $tagroutine=$self->{tagname}."_".$self->{tagcontext};
222 <        $self->_calltag($tagroutine, $self->{tagname},
221 >        if ( defined $self->{tagname} ) {
222 >         $tagroutine=$self->{tagname}."_".$self->{tagcontext};
223 >         $self->_calltag($tagroutine, $self->{tagname},
224                                                          $self->{tagvar});
225 <        #print "\nDebug : Closing Tag $tagroutine\n";
225 >         #print "\nDebug : Closing Tag $tagroutine\n";
226  
227 <        # -- Now make sure the text context is set for calling routines to
228 <        # -- deal with text portions outside of tags
229 <        if ( $self->{tagcontext} eq "starttag" ) {
230 <          push @{$self->{textstack}} , $self->{textcontext};
231 <          $self->{textcontext}=$self->{tagname};
232 <        }
233 <        else {
227 >         # -- Now make sure the text context is set for calling routines to
228 >         # -- deal with text portions outside of tags
229 >         if ( ($self->{tagcontext} eq "starttag") ) {
230 >           if ( $self->{tagcontainer}->definescontext($self->{tagname}) ) {
231 >              push @{$self->{textstack}} , $self->{textcontext};
232 >              $self->{textcontext}=$self->{tagname};
233 >           }
234 >         }
235 >         else {
236            if ( $#{$self->{textstack}} > -1 ) {
237 <            if ( $self->{textcontext} eq $self->{tagname} ) {  
238 <               $self->{textcontext}=pop @{$self->{textstack}};
239 <            }
237 >           if ( $self->{textcontext} eq $self->{tagname} ) {    
238 >            if ( $self->{tagcontainer}->definescontext($self->{tagname}) ) {
239 >              # -- watch out for valid tags we ignore in this parse
240 >              $self->{textcontext}=pop @{$self->{textstack}};
241 >            }
242 >           }
243              else { #The tag we are closing is not the last one so
244                     # we keep our current context.
245                 $self->_removefromstack($self->{tagname},$self->{textstack});
# Line 224 | Line 247 | sub _closetag {
247  
248            }
249            else { # more close tags than open ones
250 +            if ( $self->{tagcontainer}->definescontext($self->{tagname}) ) {
251               print "Warning : Unmatched </...> tag on line ".
252                                          $self->line()."\n";    
253 +            }
254            }
255 +         }
256          }
257          # Reset context back to text
258          $self->{tagcontext}="text";
# Line 354 | Line 380 | sub _labeltest {
380   sub _resetlabels {
381          my $self=shift;
382          undef $self->{tagvar};
383 +        undef $self->{tagname};
384   }
385  
386   sub _closelabel {
# Line 361 | Line 388 | sub _closelabel {
388  
389          # Do we have a label name?
390          if ( $self->{lastlabel} ne "" ) {
391 <         $self->{tagvar}{$self->{lastlabel}}=$self->_getstore();
391 >         (my $label=$self->{lastlabel})=~tr[A-Z][a-z];
392 >         $self->{tagvar}{$label}=$self->_getstore();
393           $self->{lastlabel}="";
394          }
395          elsif ( $self->_getstore() ne "") {
396 <         #Then it must be the tag name
397 <         ($self->{tagname}=$self->_getstore())=~tr/A-Z/a-z/;
396 >         # Then it must be the tag name
397 >         if ( ! defined $self->{tagname} ) {
398 >            ($self->{tagname}=$self->_getstore())=~tr/A-Z/a-z/;
399 >         }
400 >         else {
401 >            # do not die anymore - breaks non tag documents
402 >            #die ">Tag syntax error in $self->{tagname} on line ".
403 >            #   $self->line()." of file \n$self->{filename}";
404 >            # -- assume that this is plain text
405 >            $self->{tagcontext}="text";
406 >            $self->_resetstore();
407 >            $self->_unshiftstore($self->{tagbuff});
408 >            $self->{tagbuff}="";
409 >            return;
410 >         }
411          }
412          $self->_resetstore();
413   }
# Line 381 | Line 422 | sub _putstore() {
422          $self->{stringbuff}=$self->{stringbuff}.$char;
423   }
424  
425 + sub _unshiftstore() {
426 +        my $self=shift;
427 +        my $char=shift;
428 +
429 +        $self->{stringbuff}=$char.$self->{stringbuff};
430 + }
431 +
432   sub _getstore() {
433          my $self=shift;
434  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines