ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleDoc.pm
Revision: 1.6
Committed: Tue Feb 27 11:59:42 2007 UTC (18 years, 2 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V1_1_0, v110p1, V110p6, V110p5, V110p4, V110p3
Branch point for: v200branch
Changes since 1.5: +139 -255 lines
Log Message:
Merged from XML branch to HEAD. Start release prep.

File Contents

# User Rev Content
1 williamc 1.1 #
2     # SimpleDoc.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8 williamc 1.2 # Simple multi parsing functionality and group manipulation
9 williamc 1.1 #
10     # Interface
11     # ---------
12 williamc 1.3 # new([DocVersionTag]) : A new ActiveDoc object. You can also
13     # specify an alternative doc version tag
14 williamc 1.1 # 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     # checktag(tagname, hashref, param) : check for existence of param in
18     # hashref from a tag call
19     # currentparser() : return the current parser object
20     # currentparsename([name]) : get/set current parse name
21     #
22 williamc 1.3 # filenameref(string) : A string to refer to the file in parse error messages
23     # etc. Default is filetoparse
24 williamc 1.1 # --------------- Error handling routines ---------------
25     # verbose(string) : Print string in verbosity mode
26     # verbosity(0|1) : verbosity off|on
27     # parseerror(string) : print error and associate with line number etc.
28     # error(string) : handle an error
29    
30     package ActiveDoc::SimpleDoc;
31     require 5.004;
32     use ActiveDoc::Parse;
33    
34 sashby 1.6 sub new()
35     {
36     my $class=shift;
37     $self={};
38     bless $self, $class;
39     return $self;
40     }
41 williamc 1.1
42 sashby 1.6 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 williamc 1.3
52 sashby 1.6 sub verbosity()
53     {
54     my $self=shift;
55     $self->{verbose}=shift;
56     }
57 williamc 1.3
58 sashby 1.6 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 williamc 1.1
69 sashby 1.6 # ----- parse related routines --------------
70     sub parse()
71     {
72     my $self=shift;
73     $parselabel=shift;
74     my $file=$self->filetoparse();
75 williamc 1.1
76 sashby 1.6 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 williamc 1.1
96 sashby 1.6 sub parsefilelist()
97 sashby 1.5 {
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 sashby 1.6 sub currentparsename()
119     {
120     my $self=shift;
121     @_?$self->{currentparsename}=shift
122     :(defined $self->{currentparsename}?$self->{currentparsename}:"");
123     }
124 williamc 1.1
125 sashby 1.6 sub currentparser()
126     {
127     my $self=shift;
128     return $self->{currentparser};
129     }
130 williamc 1.1
131 sashby 1.6 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 williamc 1.1
142 sashby 1.6 sub filetoparse()
143     {
144     my $self=shift;
145    
146     if ( @_ )
147     {
148     $self->{filename}=shift;
149     }
150     return $self->{filename};
151 williamc 1.1 }
152    
153 sashby 1.6 sub content()
154     {
155     my $self=shift;
156     return $self->{content};
157     }
158 williamc 1.1
159     # -------- Error Handling and Error services --------------
160 sashby 1.6 sub error()
161     {
162     my $self=shift;
163     my $string=shift;
164    
165     die $string."\n";
166     }
167 williamc 1.1
168 sashby 1.6 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 williamc 1.1
187 sashby 1.6 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 williamc 1.1
200 sashby 1.6 # -- dummy tag routines
201     sub doc()
202     {
203     my $self=shift;
204     }
205 williamc 1.1
206 sashby 1.6 sub doc_()
207     {
208     my $self=shift;
209     }
210 williamc 1.1
211 sashby 1.6 1;