ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/Parse.pm
Revision: 1.8
Committed: Mon Sep 11 14:50:21 2006 UTC (18 years, 8 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V1_0_3-p4, V1_0_3-p3, V1_0_3-p2, before110xmlBRmerge, V1_0_3-p1, V1_0_3
Branch point for: v103_with_xml
Changes since 1.7: +1 -31 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 williamc 1.1 #
2     # Parse.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # maintain parse configurations
9     #
10     # Interface
11     # ---------
12 sashby 1.6 # new() : A new Parse object
13 williamc 1.1 # addtag(name,start,text,end,$object) : Add a new tag
14 sashby 1.6 # addgrouptags() : add <Group> tag functionality
15     # addignoretags() : add <ignore> tag functionality
16 williamc 1.1 # parse(filename,[streamhandle], [streamexcludetag]) :
17     # parse the given file - turn on the stream
18     # function of the switcher if a filehandle
19     # supplied as a second argument
20 sashby 1.6 # line() : return the current linenumber in the file
21 williamc 1.1 # tagstartline() : return the linenumber of the last tag opening
22 sashby 1.6 # includeparse(Parse) : include the settings from another parse object
23 williamc 1.2 # tags() : return list of defined tags
24 williamc 1.3 # cleartags() : clear of all tags
25 sashby 1.6 # opencontext(name) : open a parse context
26 williamc 1.4 # closecontext(name) : close a parse context
27     # includecontext(name) : Process when in a given context
28     # excludecontext(name) : No Processing when given context
29     # contexttag(tagname) : Register the tagname as one able to change context
30     # if not registerd - the close tag will be ignored
31     # too if outside of the specified context!
32 williamc 1.1
33    
34     package ActiveDoc::Parse;
35     require 5.004;
36     use ActiveDoc::Switcher;
37     use ActiveDoc::TagContainer;
38     use ActiveDoc::GroupChecker;
39    
40 sashby 1.6 sub new
41     {
42     my $class=shift;
43     $self={};
44     bless $self, $class;
45     $self->init();
46     return $self;
47     }
48    
49     sub init
50     {
51     my $self=shift;
52     $self->{gc}=GroupChecker->new();
53     $self->{gc}->include("all");
54     $self->{tags}=ActiveDoc::TagContainer->new();
55     }
56    
57     sub parse
58     {
59     my $self=shift;
60     my $file=shift;
61    
62     # basic setup of switcher
63     $self->{switch}=ActiveDoc::Switcher->new($file);
64     $self->{switch}->usegroupchecker($self->{gc});
65     $self->{switch}->usetags($self->{tags});
66    
67     # do we need to switch on the streamer?
68     if ( @_ )
69     {
70     $fh=shift;
71     $self->{switch}->stream($fh);
72     foreach $tag ( @_ )
73     {
74     $self->{switch}->streamexclude($tag);
75     }
76     }
77    
78     # -- parse
79     $self->{switch}->parse();
80     undef $self->{switch};
81     }
82    
83 sashby 1.7 sub parsefilelist()
84     {
85     my $self=shift;
86     my ($files)=@_;
87     # basic setup of switcher
88     $self->{switch}=ActiveDoc::Switcher->new($files);
89     $self->{switch}->usegroupchecker($self->{gc});
90     $self->{switch}->usetags($self->{tags});
91    
92     # -- parse
93     $self->{switch}->parsefilelist();
94     undef $self->{switch};
95     }
96    
97 sashby 1.6 sub line
98     {
99     my $self=shift;
100    
101     if ( defined $self->{switch} )
102     {
103     return $self->{switch}->line();
104     }
105     return undef;
106     }
107    
108     sub tagstartline
109     {
110     my $self=shift;
111    
112     if ( defined $self->{switch} )
113     {
114     return $self->{switch}->tagstartline();
115     }
116     return undef;
117     }
118    
119     sub includeparse
120     {
121     my $self=shift;
122     my $obj=shift;
123     my $tag;
124    
125     # copy the tags from the remote parse object
126     foreach $tag ( $obj->tags() )
127     {
128     $self->addtag($tag,$obj->{tags}->tagsettings($tag));
129     }
130     # now the group settings
131     }
132    
133     sub addtag
134     {
135     my $self=shift;
136     $self->{tags}->addtag(@_);
137     }
138    
139     sub addgrouptags
140     {
141     my $self=shift;
142     $self->{tags}->addtag("Group", \&Group_Start,$self,
143     "", $self, \&Group_End, $self);
144     $self->{tags}->setgrouptag("Group");
145     }
146    
147     sub addignoretags
148     {
149     my $self=shift;
150     $self->{gc}->exclude("ignore");
151     $self->{tags}->addtag("Ignore", \&Ignore_Start, $self,
152     "",$self, \&Ignore_End,$self);
153     $self->{tags}->setgrouptag("Ignore");
154     }
155    
156     sub contexttag
157     {
158     my $self=shift;
159     my $name=shift;
160     $self->{tags}->setgrouptag($name);
161     }
162    
163     sub opencontext
164     {
165     my $self=shift;
166     my $name=shift;
167     $self->{gc}->opencontext($name);
168     }
169    
170     sub closecontext
171     {
172     my $self=shift;
173     my $name=shift;
174     $self->{gc}->closecontext($name);
175     }
176    
177     sub includecontext
178     {
179     my $self=shift;
180     my $name=shift;
181     $self->{gc}->unexclude($name);
182     $self->{gc}->include($name);
183     }
184    
185     sub excludecontext
186     {
187     my $self=shift;
188     my $name=shift;
189     $self->{gc}->exclude($name);
190     $self->{gc}->uninclude($name);
191     }
192    
193     sub cleartags
194     {
195     my $self=shift;
196     $self->{tags}->cleartags();
197     }
198 williamc 1.3
199     sub tags {
200     my $self=shift;
201     return $self->{tags}->tags();
202     }
203    
204 williamc 1.1 # --------- Basic Group Related Tags ---------------------------------
205    
206 sashby 1.6 sub Group_Start
207     {
208     my $self=shift;
209     my $name=shift;
210     my $vars=shift;
211     my $lastgp;
212     $lastgp="group::".$$vars{name};
213     $self->{switch}->checkparam($name, 'name');
214 sashby 1.8 $self->{gc}->opencontext("group::".$$vars{name});
215 sashby 1.6 }
216    
217     sub Group_End
218     {
219     my $self=shift;
220     my $name=shift;
221     $self->{gc}->closelastcontext("group");
222     }
223    
224     sub Ignore_Start
225     {
226     my $self=shift;
227     my $name=shift;
228     $self->{gc}->opencontext("ignore");
229     }
230    
231     sub Ignore_End
232     {
233     my $self=shift;
234     $self->{gc}->closecontext("ignore");
235     }
236 williamc 1.1