ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/Parse.pm
Revision: 1.10
Committed: Tue Feb 27 13:33:04 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.9: +0 -1 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     package ActiveDoc::Parse;
34     require 5.004;
35 sashby 1.9 use XML::Parser;
36 williamc 1.1
37 sashby 1.9 sub new()
38 sashby 1.6 {
39     my $class=shift;
40     $self={};
41     bless $self, $class;
42 sashby 1.9 my ($dataclass, $parse_style)=@_;
43    
44     $self->{xmlparser} = new XML::Parser (
45     Style => $parse_style,
46     ParseParamEnt => 1,
47     ErrorContext => 3,
48     Pkg => $dataclass);
49 sashby 1.6 return $self;
50     }
51    
52 sashby 1.9 sub parsefilelist()
53 sashby 1.6 {
54     my $self=shift;
55 sashby 1.9 my ($files)=@_;
56 sashby 1.6 }
57    
58 sashby 1.9 sub parse()
59 sashby 1.6 {
60     my $self=shift;
61 sashby 1.9 my ($file)=@_;
62     $self->{data} = $self->{xmlparser}->parse($self->getfilestring_($file));
63     return $self;
64 sashby 1.6 }
65    
66 sashby 1.9 sub getfilestring_()
67 sashby 1.7 {
68     my $self=shift;
69 sashby 1.9 my ($file)=@_;
70     open (IN, "< $file") or die __PACKAGE__.": Cannot read file $file: $!\n";
71     my $filestring = join("", <IN>);
72     close (IN) or die __PACKAGE__.": Cannot read file $file: $!\n";
73     # Strip spaces at the beginning and end of the line:
74     $filestring =~ s/^\s+//g;
75     $filestring =~ s/\s+$//g;
76     # Finally strip the newlines:
77     $filestring =~ s/\n//g;
78     # Strip out spaces in between tags:
79     $filestring =~ s/>\s+</></g;
80     $self->{filestring}=$filestring;
81     return $filestring;
82 sashby 1.7 }
83    
84 sashby 1.9 sub data()
85 sashby 1.6 {
86     my $self=shift;
87 sashby 1.9 return $self->{data}->[0];
88 sashby 1.6 }
89    
90     sub includeparse
91     {
92     my $self=shift;
93     my $obj=shift;
94     my $tag;
95    
96     # copy the tags from the remote parse object
97     foreach $tag ( $obj->tags() )
98     {
99     $self->addtag($tag,$obj->{tags}->tagsettings($tag));
100     }
101     }
102    
103     sub addtag
104     {
105     my $self=shift;
106     $self->{tags}->addtag(@_);
107     }
108    
109 sashby 1.9 1;