ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/Parse.pm
Revision: 1.2
Committed: Fri Jan 14 15:55:16 2000 UTC (25 years, 3 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.1: +19 -0 lines
Log Message:
extend interface for tags and includeparse

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     # 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 williamc 1.2 # includeparse(Parse) : include the settings from another parse object
23     # tags() : return list of defined tags
24 williamc 1.1
25    
26     package ActiveDoc::Parse;
27     require 5.004;
28     use ActiveDoc::Switcher;
29     use ActiveDoc::TagContainer;
30     use ActiveDoc::GroupChecker;
31    
32     sub new {
33     my $class=shift;
34     $self={};
35     bless $self, $class;
36     $self->init();
37     return $self;
38     }
39    
40     sub init {
41     my $self=shift;
42     $self->{gc}=GroupChecker->new();
43     $self->{gc}->include("all");
44     $self->{tags}=ActiveDoc::TagContainer->new();
45     }
46    
47     sub parse {
48     my $self=shift;
49     my $file=shift;
50    
51     # basic setup of switcher
52     $self->{switch}=ActiveDoc::Switcher->new($file);
53     $self->{switch}->usegroupchecker($self->{gc});
54     $self->{switch}->usetags($self->{tags});
55    
56     # do we need to switch on the streamer?
57     if ( @_ ) {
58     $fh=shift;
59     $self->{switch}->stream($fh);
60     foreach $tag ( @_ ) {
61     $self->{switch}->streamexclude($tag);
62     }
63     }
64    
65     # parse
66     $self->{switch}->parse();
67     undef $self->{switch};
68     }
69    
70     sub line {
71     my $self=shift;
72     if ( defined $self->{switch} ) {
73     return $self->{switch}->line();
74     }
75     return undef;
76     }
77    
78     sub tagstartline {
79     my $self=shift;
80     if ( defined $self->{switch} ) {
81     return $self->{switch}->tagstartline();
82     }
83     return undef;
84     }
85 williamc 1.2
86     sub includeparse {
87     my $self=shift;
88     my $obj=shift;
89    
90     my $tag;
91     # copy the tags from the remote parse object
92     foreach $tag ( $obj->tags() ) {
93     $self->addtag($tag,$obj->{tags}->tagsettings($tag));
94     }
95     # now the group settings
96     }
97    
98 williamc 1.1 sub addtag {
99     my $self=shift;
100     $self->{tags}->addtag(@_);
101     }
102    
103     sub addgrouptags {
104     my $self=shift;
105     $self->{tags}->addtag("Group", \&Group_Start,$self,
106     "", $self, \&Group_End, $self);
107     $self->{tags}->setgrouptag("Group");
108     }
109    
110     sub addignoretags {
111     my $self=shift;
112     $self->{gc}->exclude("ignore");
113     $self->{tags}->addtag("Ignore", \&Ignore_Start, $self,
114     "",$self, \&Ignore_End,$self);
115     }
116    
117     # --------- Basic Group Related Tags ---------------------------------
118    
119     sub Group_Start {
120     my $self=shift;
121     my $name=shift;
122     my $vars=shift;
123     my $lastgp;
124    
125     $lastgp="group::".$$vars{name};
126     $self->{switch}->checkparam($name, 'name');
127     $self->{gc}->opencontext("group::".$$vars{name});
128    
129     }
130    
131     sub Group_End {
132     my $self=shift;
133     my $name=shift;
134     my $lastgp;
135    
136     $self->{gc}->closelastcontext("group");
137     }
138    
139     sub Ignore_Start {
140     my $self=shift;
141     my $name=shift;
142    
143     $self->{gc}->opencontext("ignore");
144     }
145    
146 williamc 1.2 sub tags {
147     my $self=shift;
148     return $self->{tags}->tags();
149     }
150 williamc 1.1 sub Ignore_End {
151     my $self=shift;
152     $self->{gc}->closecontext("ignore");
153     }
154