ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleDoc.pm
Revision: 1.1
Committed: Wed Apr 5 10:12:13 2000 UTC (25 years, 1 month ago) by williamc
Content type: text/plain
Branch: MAIN
Branch point for: V0_9branch
Log Message:
Simplified Parsing Module

File Contents

# User Rev Content
1 williamc 1.1 #
2     # SimpleDoc.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # Simple multi parsing functionality
9     #
10     # Interface
11     # ---------
12     # new() : A new ActiveDoc object
13     # filetoparse([filename]) : Set/Return the filename of document
14     # newparse(parselabel) : Create a new parse type
15     # 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     # checktag(tagname, hashref, param) : check for existence of param in
19     # hashref from a tag call
20     # includeparse(local_parsename, objparsename, activedoc) : copy the parse from
21     # one object to another
22     # currentparser() : return the current parser object
23     # currentparsename([name]) : get/set current parse name
24     #
25     # addignoretags(parsename) : add <ignore> </igonore> tags funtionality to the
26     # specified parse
27     # --------------- Error handling routines ---------------
28     # verbose(string) : Print string in verbosity mode
29     # verbosity(0|1) : verbosity off|on
30     # line() : return the current line number in the current parse
31     # tagstartline() : return the line number where the current tag was
32     # opened
33     # parseerror(string) : print error and associate with line number etc.
34     # error(string) : handle an error
35    
36     package ActiveDoc::SimpleDoc;
37     require 5.004;
38     use ActiveDoc::Parse;
39    
40     sub new {
41     my $class=shift;
42     $self={};
43     bless $self, $class;
44     $self->verbose("New SimpleDoc (".ref($self).") Created");
45     $self->init(@_);
46     return $self;
47     }
48    
49     sub init {
50     # dummy to be overridden by inheriting class
51     }
52    
53     sub verbosity {
54     my $self=shift;
55     $self->{verbose}=shift;
56     }
57    
58     sub verbose {
59     my $self=shift;
60     my $string=shift;
61    
62     if ( $self->{verbose} ) {
63     print ">".ref($self)."($self) : \n->".$string."\n";
64     }
65     }
66    
67     # ----- parse related routines --------------
68     sub parse {
69     my $self=shift;
70     $parselabel=shift;
71    
72     my $file=$self->filetoparse();
73     if ( $file ) {
74     if ( exists $self->{parsers}{$parselabel} ) {
75     $self->verbose("Parsing $parselabel in file $file");
76     $self->{currentparsename}=$parselabel;
77     $self->{currentparser}=$self->{parsers}{$parselabel};
78     $self->{parsers}{$parselabel}->parse($file,@_);
79     delete $self->{currentparser};
80     $self->{currentparsename}="";
81     $self->verbose("Parse $parselabel Complete");
82     }
83     }
84     else {
85     $self->error("Cannot parse $parselabel - file not known");
86     }
87     }
88    
89     sub currentparsename {
90     my $self=shift;
91     @_?$self->{currentparsename}=shift
92     :(defined $self->{currentparsename}?$self->{currentparsename}:"");
93     }
94    
95     sub currentparser {
96     my $self=shift;
97     return $self->{currentparser};
98     }
99    
100    
101     sub newparse {
102     my $self=shift;
103     my $parselabel=shift;
104    
105     $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
106     # $self->{parsers}{$parselabel}->addgrouptags();
107     }
108    
109     sub addignoretags {
110     my $self=shift;
111     my $parselabel=shift;
112     $self->{parsers}{$parselabel}->addignoretags();
113     }
114    
115     sub cleartags {
116     my $self=shift;
117     my $parselabel=shift;
118    
119     $self->{parsers}{$parselabel}->cleartags();
120     }
121    
122    
123     sub includeparse {
124     my $self=shift;
125     my $parselabel=shift;
126     my $remoteparselabel=shift;
127     my $activedoc=shift;
128    
129     # Some error trapping
130     if ( ! exists $self->{parsers}{$parselabel} ) {
131     $self->error("Unknown local parse name specified");
132     }
133     if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
134     $self->error("Unknown parse name specified in remote obj $activedoc");
135     }
136    
137     #
138     my $rp=$activedoc->{parsers}{$remoteparselabel};
139     $self->{parsers}{$parselabel}->includeparse($rp);
140     }
141    
142     sub addtag {
143     my $self=shift;
144     my $parselabel=shift;
145     if ( $#_ != 6 ) {
146     $self->error("Incorrect addtags specification\n".
147     "called with :\n@_ \n");
148     }
149     $self->{parsers}{$parselabel}->addtag(@_);
150     }
151    
152     sub filetoparse {
153     my $self=shift;
154    
155     if ( @_ ) {
156     $self->{filename}=shift;
157     }
158     return $self->{filename};
159     }
160    
161     # -------- Error Handling and Error services --------------
162    
163     sub error {
164     my $self=shift;
165     my $string=shift;
166    
167     die $string."\n";
168     }
169    
170     sub parseerror {
171     my $self=shift;
172     my $string=shift;
173    
174     if ( $self->currentparsename() eq "" ) {
175     $self->error($string);
176     }
177     else {
178     $line=$self->line();
179     print "Parse Error in ".$self->filetoparse().", line ".
180     $line."\n";
181     print $string."\n";
182     exit;
183     }
184     }
185    
186     sub checktag {
187     my $self=shift;
188     my $tagname=shift;
189     my $hashref=shift;
190     my $param=shift;
191    
192     if ( ! exists $$hashref{$param} ) {
193     $self->parseerror("Incomplete Tag <$tagname> : $param required");
194     }
195     }
196    
197     sub line {
198     my $self=shift;
199     return $self->{currentparser}->line();
200     }
201    
202     sub tagstartline {
203     my $self=shift;
204     return $self->{currentparser}->tagstartline();
205     }
206