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 |
|
|
|
36 |
sashby |
1.9 |
sub new()
|
37 |
sashby |
1.6 |
{
|
38 |
|
|
my $class=shift;
|
39 |
|
|
$self={};
|
40 |
|
|
bless $self, $class;
|
41 |
muzaffar |
1.11.4.1 |
my ($dataclass, $parse_style,$keep_running_onerr)=@_;
|
42 |
|
|
require SCRAM::Plugins::DocParser;
|
43 |
|
|
$self->{xmlparser} = new SCRAM::Plugins::DocParser($dataclass,$parse_style,$keep_running_onerr);
|
44 |
sashby |
1.6 |
return $self;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
sashby |
1.9 |
sub parsefilelist()
|
48 |
sashby |
1.6 |
{
|
49 |
|
|
my $self=shift;
|
50 |
sashby |
1.9 |
my ($files)=@_;
|
51 |
muzaffar |
1.11 |
print __PACKAGE__."::parsefilelist(): Not used?\n";
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
sub filehead ()
|
55 |
|
|
{
|
56 |
|
|
my $self=shift;
|
57 |
|
|
my $data=@_;
|
58 |
|
|
if (@_)
|
59 |
|
|
{
|
60 |
|
|
$self->{filehead}=shift;
|
61 |
|
|
return;
|
62 |
|
|
}
|
63 |
|
|
return $self->{filehead} || "";
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
sub filetail ()
|
67 |
|
|
{
|
68 |
|
|
my $self=shift;
|
69 |
|
|
if (@_)
|
70 |
|
|
{
|
71 |
|
|
$self->{filetail}=shift;
|
72 |
|
|
return;
|
73 |
|
|
}
|
74 |
|
|
return $self->{filetail} || "";
|
75 |
sashby |
1.6 |
}
|
76 |
|
|
|
77 |
sashby |
1.9 |
sub parse()
|
78 |
sashby |
1.6 |
{
|
79 |
|
|
my $self=shift;
|
80 |
sashby |
1.9 |
my ($file)=@_;
|
81 |
muzaffar |
1.11.4.1 |
if (!$self->{xmlparser}->parse($file,$self->getfilestring_($file)))
|
82 |
muzaffar |
1.11 |
{
|
83 |
muzaffar |
1.11.4.1 |
print STDERR "**** ERROR: Failed parsing file: $file.\n";
|
84 |
muzaffar |
1.11 |
}
|
85 |
sashby |
1.9 |
return $self;
|
86 |
sashby |
1.6 |
}
|
87 |
|
|
|
88 |
sashby |
1.9 |
sub getfilestring_()
|
89 |
sashby |
1.7 |
{
|
90 |
|
|
my $self=shift;
|
91 |
sashby |
1.9 |
my ($file)=@_;
|
92 |
muzaffar |
1.11 |
my $filestring="";
|
93 |
|
|
my $read=0;
|
94 |
|
|
if (($file!~/\.xml$/) && ($file!~/\/\.SCRAM\/InstalledTools\/[^\/]+$/))
|
95 |
|
|
{
|
96 |
muzaffar |
1.11.4.1 |
eval("use SCRAM::Plugins::Doc2XML");
|
97 |
muzaffar |
1.11 |
if (!$@)
|
98 |
|
|
{
|
99 |
muzaffar |
1.11.4.1 |
my $xmlconvertor = SCRAM::Plugins::Doc2XML->new();
|
100 |
muzaffar |
1.11 |
my $xml=$xmlconvertor->convert($file);
|
101 |
|
|
$filestring = join("",@$xml);
|
102 |
|
|
$xmlconvertor->clean();
|
103 |
|
|
$read=1;
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
if (!$read)
|
107 |
|
|
{
|
108 |
|
|
open (IN, "< $file") or die __PACKAGE__.": Cannot read file $file: $!\n";
|
109 |
|
|
$filestring = join("", <IN>);
|
110 |
|
|
close (IN) or die __PACKAGE__.": Cannot read file $file: $!\n";
|
111 |
|
|
}
|
112 |
|
|
$filestring = $self->filehead().$filestring.$self->filetail();
|
113 |
sashby |
1.9 |
# Strip spaces at the beginning and end of the line:
|
114 |
|
|
$filestring =~ s/^\s+//g;
|
115 |
|
|
$filestring =~ s/\s+$//g;
|
116 |
|
|
$self->{filestring}=$filestring;
|
117 |
|
|
return $filestring;
|
118 |
sashby |
1.7 |
}
|
119 |
|
|
|
120 |
sashby |
1.9 |
sub data()
|
121 |
sashby |
1.6 |
{
|
122 |
|
|
my $self=shift;
|
123 |
muzaffar |
1.11.4.1 |
return $self->{xmlparser}->getOutput();
|
124 |
sashby |
1.6 |
}
|
125 |
|
|
|
126 |
|
|
sub includeparse
|
127 |
|
|
{
|
128 |
|
|
my $self=shift;
|
129 |
|
|
my $obj=shift;
|
130 |
|
|
my $tag;
|
131 |
|
|
|
132 |
|
|
# copy the tags from the remote parse object
|
133 |
|
|
foreach $tag ( $obj->tags() )
|
134 |
|
|
{
|
135 |
|
|
$self->addtag($tag,$obj->{tags}->tagsettings($tag));
|
136 |
|
|
}
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
sub addtag
|
140 |
|
|
{
|
141 |
|
|
my $self=shift;
|
142 |
|
|
$self->{tags}->addtag(@_);
|
143 |
|
|
}
|
144 |
|
|
|
145 |
sashby |
1.9 |
1;
|