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.5 by sashby, Fri Dec 10 13:41:36 2004 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
17 < # addtag(parselabel,tagname,start,obj,text,obj,end,obj) :
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!
# Line 31 | Line 32
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
37 + # filenameref(string)   : A string to refer to the file in parse error messages
38 + #                         etc. Default is filetoparse
39   # --------------- Error handling routines ---------------
40   # verbose(string)       : Print string in verbosity mode
41   # verbosity(0|1)        : verbosity off|on
# Line 48 | Line 53 | sub new {
53          my $class=shift;
54          $self={};
55          bless $self, $class;
56 <        $self->verbose("New SimpleDoc (".ref($self).") Created");
52 <        $self->init(@_);
56 >        $self->_initdoc("doc",@_);
57          return $self;
58   }
59  
60 < sub init {
61 <        # dummy to be overridden by inheriting class
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 > }
78 >
79 > sub _initdoc {
80 >        my $self=shift;
81 >        my $parsename=shift;
82 >
83 >        $self->{doctag}="DOC";
84 >        if ( @_ ) {
85 >          $self->{doctag}=shift;
86 >        }
87 >        $self->newparse($parsename);
88 >        $self->addtag($parsename,$self->{doctag},\&Doc_Start, $self);
89   }
90  
91   sub verbosity {
# Line 75 | Line 106 | sub verbose {
106   sub parse {
107          my $self=shift;
108          $parselabel=shift;
78
109          my $file=$self->filetoparse();
110 <        if ( $file ) {
110 >        
111 >        if ( -f $file ) {
112            if ( exists $self->{parsers}{$parselabel} ) {
113              $self->verbose("Parsing $parselabel in file $file");
114              $self->{currentparsename}=$parselabel;
# Line 89 | Line 120 | sub parse {
120            }
121          }
122          else {
123 <          $self->error("Cannot parse $parselabel - file not known");
123 >          $self->error("Cannot parse \"$parselabel\" - file $file not known");
124          }
125   }
126  
127 + sub parsefilelist
128 +   {
129 +   my $self=shift;
130 +   my $parselabel=shift;
131 +   my ($filenames)=@_;
132 +
133 +   if ( exists $self->{parsers}{$parselabel} )
134 +      {
135 +      $self->verbose("ParsingFileList: Label = $parselabel (files = ".join(",",@$filenames)." ");
136 +      $self->{currentparsename}=$parselabel;
137 +      $self->{currentparser}=$self->{parsers}{$parselabel};
138 +      $self->{parsers}{$parselabel}->parsefilelist($filenames);
139 +      delete $self->{currentparser};
140 +      $self->{currentparsename}="";
141 +      $self->verbose("ParseFileList $parselabel Complete");
142 +      }
143 +   else
144 +      {
145 +      $self->error("Cannot parse \"$parselabel\" - Unknown parser!!");
146 +      }
147 +   }
148 +
149   sub currentparsename {
150          my $self=shift;
151          @_?$self->{currentparsename}=shift
# Line 110 | Line 163 | sub newparse {
163          my $parselabel=shift;
164  
165          $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
113 #       $self->{parsers}{$parselabel}->addgrouptags();
166   }
167  
168   sub addignoretags {
# Line 149 | Line 201 | sub includeparse {
201   sub addtag {
202          my $self=shift;
203          my $parselabel=shift;
204 <        if ( $#_ != 6 ) {
204 >        if ( ( $#_ != 6 ) && ( $#_ != 2) ) {
205                  $self->error("Incorrect addtags specification\n".
206                                  "called with :\n@_ \n");
207          }
# Line 229 | Line 281 | sub parseerror {
281          my $string=shift;
282  
283          if ( $self->currentparsename() eq "" ) {
284 <                $self->error($string);
284 >                $self->error("Error In file ".$self->filenameref."\n".$string);
285          }
286          else {
287           $line=$self->line();
288 <         print "Parse Error in ".$self->filetoparse().", line ".
288 >         print "Parse Error in ".$self->filenameref().", line ".
289                                          $line."\n";
290           print $string."\n";
291           exit;
# Line 261 | Line 313 | sub tagstartline {
313          return $self->{currentparser}->tagstartline();
314   }
315  
316 + # -- tag routines
317 + sub Doc_Start {
318 +        my $self=shift;
319 +        my $name=shift;
320 +        my $hashref=shift;
321 +
322 +        $self->checktag($name, $hashref, "type");
323 +        $self->checktag($name, $hashref, "version");
324 +
325 +        $self->{doctype}=$$hashref{'type'};
326 +        $self->{docversion}=$$hashref{'version'};
327 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines