ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/Parse.pm
Revision: 1.5
Committed: Fri Apr 7 13:40:09 2000 UTC (25 years, 1 month ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V0_19_3, V0_19_2, V0_19_1, V0_19_0, V0_18_5, V0_18_4, V_18_3_TEST, VO_18_3, V0_18_2, V0_18_1, ProtoEnd
Changes since 1.4: +1 -1 lines
Log Message:
updates

File Contents

# Content
1 #
2 # Parse.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # -----------
8 # maintain parse configurations
9 #
10 # Interface
11 # ---------
12 # new() : A new Parse object
13 # addtag(name,start,text,end,$object) : Add a new tag
14 # addgrouptags() : add <Group> tag functionality
15 # addignoretags() : add <ignore> tag functionality
16 # 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 # line() : return the current linenumber in the file
21 # tagstartline() : return the linenumber of the last tag opening
22 # includeparse(Parse) : include the settings from another parse object
23 # tags() : return list of defined tags
24 # cleartags() : clear of all tags
25 # opencontext(name) : open a parse context
26 # 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
33
34 package ActiveDoc::Parse;
35 require 5.004;
36 use ActiveDoc::Switcher;
37 use ActiveDoc::TagContainer;
38 use ActiveDoc::GroupChecker;
39
40 sub new {
41 my $class=shift;
42 $self={};
43 bless $self, $class;
44 $self->init();
45 return $self;
46 }
47
48 sub init {
49 my $self=shift;
50 $self->{gc}=GroupChecker->new();
51 $self->{gc}->include("all");
52 $self->{tags}=ActiveDoc::TagContainer->new();
53 }
54
55 sub parse {
56 my $self=shift;
57 my $file=shift;
58
59 # basic setup of switcher
60 $self->{switch}=ActiveDoc::Switcher->new($file);
61 $self->{switch}->usegroupchecker($self->{gc});
62 $self->{switch}->usetags($self->{tags});
63
64 # do we need to switch on the streamer?
65 if ( @_ ) {
66 $fh=shift;
67 $self->{switch}->stream($fh);
68 foreach $tag ( @_ ) {
69 $self->{switch}->streamexclude($tag);
70 }
71 }
72
73 # -- parse
74 $self->{switch}->parse();
75 undef $self->{switch};
76 }
77
78 sub line {
79 my $self=shift;
80 if ( defined $self->{switch} ) {
81 return $self->{switch}->line();
82 }
83 return undef;
84 }
85
86 sub tagstartline {
87 my $self=shift;
88 if ( defined $self->{switch} ) {
89 return $self->{switch}->tagstartline();
90 }
91 return undef;
92 }
93
94 sub includeparse {
95 my $self=shift;
96 my $obj=shift;
97
98 my $tag;
99 # copy the tags from the remote parse object
100 foreach $tag ( $obj->tags() ) {
101 $self->addtag($tag,$obj->{tags}->tagsettings($tag));
102 }
103 # now the group settings
104 }
105
106 sub addtag {
107 my $self=shift;
108 $self->{tags}->addtag(@_);
109 }
110
111 sub addgrouptags {
112 my $self=shift;
113 $self->{tags}->addtag("Group", \&Group_Start,$self,
114 "", $self, \&Group_End, $self);
115 $self->{tags}->setgrouptag("Group");
116 }
117
118 sub addignoretags {
119 my $self=shift;
120 $self->{gc}->exclude("ignore");
121 $self->{tags}->addtag("Ignore", \&Ignore_Start, $self,
122 "",$self, \&Ignore_End,$self);
123 $self->{tags}->setgrouptag("Ignore");
124 }
125
126 sub contexttag {
127 my $self=shift;
128 $self->{tags}->setgrouptag(shift);
129 }
130
131 sub opencontext {
132 my $self=shift;
133 $self->{gc}->opencontext(shift);
134 }
135
136 sub closecontext {
137 my $self=shift;
138 $self->{gc}->closecontext(shift);
139 }
140
141 sub includecontext {
142 my $self=shift;
143 my $name=shift;
144
145 $self->{gc}->unexclude($name);
146 $self->{gc}->include($name);
147 }
148
149 sub excludecontext {
150 my $self=shift;
151 my $name=shift;
152 $self->{gc}->exclude($name);
153 $self->{gc}->uninclude($name);
154 }
155
156 sub cleartags {
157 my $self=shift;
158 $self->{tags}->cleartags();
159 }
160
161 sub tags {
162 my $self=shift;
163 return $self->{tags}->tags();
164 }
165
166 # --------- Basic Group Related Tags ---------------------------------
167
168 sub Group_Start {
169 my $self=shift;
170 my $name=shift;
171 my $vars=shift;
172 my $lastgp;
173
174 $lastgp="group::".$$vars{name};
175 $self->{switch}->checkparam($name, 'name');
176 $self->{gc}->opencontext("group::".$$vars{name});
177
178 }
179
180 sub Group_End {
181 my $self=shift;
182 my $name=shift;
183 my $lastgp;
184
185 $self->{gc}->closelastcontext("group");
186 }
187
188 sub Ignore_Start {
189 my $self=shift;
190 my $name=shift;
191
192 $self->{gc}->opencontext("ignore");
193 }
194
195 sub Ignore_End {
196 my $self=shift;
197 $self->{gc}->closecontext("ignore");
198 }
199