xamplr-pp 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +504 -0
- data/README.rdoc +94 -0
- data/Rakefile +56 -0
- data/VERSION.yml +4 -0
- data/lib/xampl-pp-dtd.rb +126 -0
- data/lib/xampl-pp-wf.rb +1037 -0
- data/lib/xamplr-pp.rb +991 -0
- data/lib/xamplr-pp/ANNOUNCE.TXT +47 -0
- data/lib/xamplr-pp/LICENSE +504 -0
- data/lib/xamplr-pp/Makefile +122 -0
- data/lib/xamplr-pp/examples/parse-wf.rb +55 -0
- data/lib/xamplr-pp/examples/parse.rb +59 -0
- data/lib/xamplr-pp/license.inc +17 -0
- data/lib/xamplr-pp/saxdemo.rb +214 -0
- data/lib/xamplr-pp/saxish.rb +298 -0
- data/lib/xamplr-pp/saxishHandler.rb +58 -0
- data/lib/xamplr-pp/toys/chew.rb +62 -0
- data/lib/xamplr-pp/toys/chewMultibyte.rb +44 -0
- data/lib/xamplr-pp/toys/dump.rb +58 -0
- data/lib/xamplr-pp/xmlName.defn +67 -0
- data/lib/xamplr-pp/xpp.rb +908 -0
- data/lib/xamplr-pp/xppDeluxe.rb +49 -0
- data/lib/xamplr-pp/xppIter.rb +845 -0
- data/test/test_helper.rb +10 -0
- data/test/xamplr_pp_gem_test.rb +7 -0
- metadata +79 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
DIST_FILES_ROOT=\
|
2
|
+
LICENSE.TXT \
|
3
|
+
README.TXT
|
4
|
+
DIST_FILES_LIB=\
|
5
|
+
saxish.rb \
|
6
|
+
saxishHandler.rb \
|
7
|
+
xampl-pp.rb
|
8
|
+
DIST_FILES_TEST=\
|
9
|
+
TC_EventTypes.rb \
|
10
|
+
TC_Features.rb \
|
11
|
+
TC_Input.rb \
|
12
|
+
TC_Input000.data \
|
13
|
+
TC_Input001.data \
|
14
|
+
TC_Misc.rb \
|
15
|
+
TC_Namespace.rb \
|
16
|
+
TC_Parse.rb \
|
17
|
+
TC_Parse000.data \
|
18
|
+
TS_xpp.rb
|
19
|
+
DIST_FILES_EXAMPLES=\
|
20
|
+
saxdemo.rb
|
21
|
+
|
22
|
+
ut:
|
23
|
+
time ruby TS_xpp.rb 2>&1 | tee e1
|
24
|
+
|
25
|
+
p: pinit pgo
|
26
|
+
|
27
|
+
pinit:
|
28
|
+
cp P_ChewFile.profile.base P_ChewFile.profile
|
29
|
+
|
30
|
+
pgo:
|
31
|
+
ruby -r rbprof P_ChewFile.rb 2>&1 | tee results.prof
|
32
|
+
|
33
|
+
pclean:
|
34
|
+
rm -f P_ChewFile.profile
|
35
|
+
ruby -r rbprof P_ChewFile.rb 2>&1 | tee results.prof
|
36
|
+
|
37
|
+
wclean:
|
38
|
+
rm -f P_ChewFile-wf.profile
|
39
|
+
ruby -r rbprof P_ChewFile-wf.rb 2>&1 | tee results.prof
|
40
|
+
|
41
|
+
base:
|
42
|
+
cp P_ChewFile.profile P_ChewFile.profile.base
|
43
|
+
|
44
|
+
prof:
|
45
|
+
#ruby -r rbprof P_Input.rb 2>&1 | tee results.prof
|
46
|
+
cp P_Input.profile.base P_Input.profile
|
47
|
+
ruby P_Input.rb 2>&1 | tee results.prof
|
48
|
+
|
49
|
+
|
50
|
+
go: goXpp
|
51
|
+
|
52
|
+
goXpp:
|
53
|
+
time ruby xpp.rb
|
54
|
+
|
55
|
+
|
56
|
+
tconf:
|
57
|
+
rm -f results.conformance
|
58
|
+
./chew.rb PASS pass.files >> results.conformance
|
59
|
+
#./chew.rb FAIL not-wf.files >> results.conformance
|
60
|
+
#./chew.rb FAIL fail.files >> results.conformance
|
61
|
+
#./chew.rb FAIL invalid.files >> results.conformance
|
62
|
+
#./chew.rb PASS valid.files >> results.conformance
|
63
|
+
##./chew.rb FAIL japanese.files >> results.conformance
|
64
|
+
|
65
|
+
conf::
|
66
|
+
time ruby conf.rb \
|
67
|
+
xmlconf/xmltest/xmltest.xml \
|
68
|
+
xmlconf/oasis/oasis.xml \
|
69
|
+
xmlconf/ibm/ibm_oasis_invalid.xml \
|
70
|
+
xmlconf/ibm/ibm_oasis_not-wf.xml \
|
71
|
+
xmlconf/ibm/ibm_oasis_valid.xml \
|
72
|
+
xmlconf/japanese/japanese.xml \
|
73
|
+
xmlconf/sun/sun-error.xml \
|
74
|
+
xmlconf/sun/sun-invalid.xml \
|
75
|
+
xmlconf/sun/sun-not-wf.xml \
|
76
|
+
xmlconf/sun/sun-valid.xml \
|
77
|
+
| tee results.conformance
|
78
|
+
##rm -f results.conformance
|
79
|
+
##./chew.rb PASS pass.files >> results.conformance
|
80
|
+
##./chew.rb FAIL not-wf.files >> results.conformance
|
81
|
+
##./chew.rb FAIL fail.files >> results.conformance
|
82
|
+
##./chew.rb FAIL invalid.files >> results.conformance
|
83
|
+
##./chew.rb PASS valid.files >> results.conformance
|
84
|
+
##./chew.rb FAIL japanese.files >> results.conformance
|
85
|
+
|
86
|
+
rconf:
|
87
|
+
rm -f results.conformance
|
88
|
+
./chewRexml.rb PASS pass.files >> results.conformance
|
89
|
+
./chewRexml.rb FAIL not-wf.files >> results.conformance
|
90
|
+
./chewRexml.rb FAIL fail.files >> results.conformance
|
91
|
+
#./chewRexml.rb FAIL invalid.files >> results.conformance
|
92
|
+
#./chewRexml.rb PASS valid.files >> results.conformance
|
93
|
+
##./chewRexml.rb FAIL japanese.files >> results.conformance
|
94
|
+
|
95
|
+
rconfpp:
|
96
|
+
rm -f results.conformance
|
97
|
+
./chewRexmlPP.rb PASS pass.files
|
98
|
+
./chewRexmlPP.rb FAIL not-wf.files
|
99
|
+
./chewRexmlPP.rb FAIL fail.files
|
100
|
+
./chewRexmlPP.rb FAIL invalid.files
|
101
|
+
./chewRexmlPP.rb PASS valid.files
|
102
|
+
#./chewRexmlPP.rb PASS pass.files >> results.conformance
|
103
|
+
#./chewRexmlPP.rb FAIL not-wf.files >> results.conformance
|
104
|
+
#./chewRexmlPP.rb FAIL fail.files >> results.conformance
|
105
|
+
#./chewRexmlPP.rb FAIL invalid.files >> results.conformance
|
106
|
+
#./chewRexmlPP.rb PASS valid.files >> results.conformance
|
107
|
+
##./chewRexmlPP.rb FAIL japanese.files >> results.conformance
|
108
|
+
|
109
|
+
sax:
|
110
|
+
ruby saxdemo.rb testFeeds.xml rexmlDoc.xml test.xml
|
111
|
+
|
112
|
+
saxFail:
|
113
|
+
ruby saxdemo.rb test0.xml
|
114
|
+
|
115
|
+
dist::
|
116
|
+
cp $(DIST_FILES_ROOT) dist
|
117
|
+
cp $(DIST_FILES_LIB) dist/lib
|
118
|
+
cp $(DIST_FILES_TEST) dist/test
|
119
|
+
cp $(DIST_FILES_EXAMPLES) dist/examples
|
120
|
+
|
121
|
+
prex:
|
122
|
+
ruby -r rbprof P_RexmlPP.rb 2>&1 | tee results.prof
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
require "xampl-pp-wf"
|
3
|
+
|
4
|
+
class Listener
|
5
|
+
|
6
|
+
attr :count, false
|
7
|
+
|
8
|
+
def parse(filename)
|
9
|
+
@xpp = Xampl_PP.new
|
10
|
+
@xpp.input = File.new(filename)
|
11
|
+
|
12
|
+
@count = 0
|
13
|
+
|
14
|
+
while not @xpp.endDocument? do
|
15
|
+
event = @xpp.nextEvent
|
16
|
+
case event
|
17
|
+
#case @xpp.nextEvent
|
18
|
+
when Xampl_PP::START_DOCUMENT
|
19
|
+
@count += 1
|
20
|
+
when Xampl_PP::END_DOCUMENT
|
21
|
+
@count += 1
|
22
|
+
when Xampl_PP::START_ELEMENT
|
23
|
+
@count += 1
|
24
|
+
when Xampl_PP::END_ELEMENT
|
25
|
+
@count += 1
|
26
|
+
when Xampl_PP::TEXT
|
27
|
+
@count += 1
|
28
|
+
when Xampl_PP::CDATA_SECTION
|
29
|
+
@count += 1
|
30
|
+
when Xampl_PP::ENTITY_REF
|
31
|
+
@count += 1
|
32
|
+
when Xampl_PP::IGNORABLE_WHITESPACE
|
33
|
+
@count += 1
|
34
|
+
when Xampl_PP::PROCESSING_INSTRUCTION
|
35
|
+
@count += 1
|
36
|
+
when Xampl_PP::COMMENT
|
37
|
+
@count += 1
|
38
|
+
when Xampl_PP::DOCTYPE
|
39
|
+
@count += 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
start = Time.now
|
47
|
+
for filename in ARGV do
|
48
|
+
listener = Listener.new
|
49
|
+
listener.parse(filename)
|
50
|
+
#printf("EVENTS: %d\n", listener.count)
|
51
|
+
end
|
52
|
+
puts "Time: #{Time.now - start}"
|
53
|
+
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
require "xampl-pp"
|
3
|
+
|
4
|
+
class Listener
|
5
|
+
|
6
|
+
attr :count, false
|
7
|
+
|
8
|
+
def parse(filename)
|
9
|
+
@xpp = Xampl_PP.new
|
10
|
+
@xpp.input = File.new(filename)
|
11
|
+
|
12
|
+
@count = 0
|
13
|
+
|
14
|
+
#printf("__________________________________")
|
15
|
+
while not @xpp.endDocument? do
|
16
|
+
event = @xpp.nextEvent
|
17
|
+
if(0 == (@count % 10001)) then
|
18
|
+
printf("count: %d\n", count)
|
19
|
+
end
|
20
|
+
#printf("\nEVENT: %s\n", event)
|
21
|
+
case event
|
22
|
+
#case @xpp.nextEvent
|
23
|
+
when Xampl_PP::START_DOCUMENT
|
24
|
+
@count += 1
|
25
|
+
when Xampl_PP::END_DOCUMENT
|
26
|
+
@count += 1
|
27
|
+
when Xampl_PP::START_ELEMENT
|
28
|
+
@count += 1
|
29
|
+
when Xampl_PP::END_ELEMENT
|
30
|
+
@count += 1
|
31
|
+
when Xampl_PP::TEXT
|
32
|
+
@count += 1
|
33
|
+
when Xampl_PP::CDATA_SECTION
|
34
|
+
@count += 1
|
35
|
+
when Xampl_PP::ENTITY_REF
|
36
|
+
@count += 1
|
37
|
+
when Xampl_PP::IGNORABLE_WHITESPACE
|
38
|
+
@count += 1
|
39
|
+
when Xampl_PP::PROCESSING_INSTRUCTION
|
40
|
+
@count += 1
|
41
|
+
when Xampl_PP::COMMENT
|
42
|
+
@count += 1
|
43
|
+
when Xampl_PP::DOCTYPE
|
44
|
+
@count += 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
for filename in ARGV do
|
52
|
+
listener = Listener.new
|
53
|
+
listener.parse(filename)
|
54
|
+
|
55
|
+
printf("EVENTS: %d\n", listener.count)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# xampl-pp : XML pull parser
|
2
|
+
# Copyright (C) 2002-2009 Bob Hutchison
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# #Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
#
|
@@ -0,0 +1,214 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
#
|
3
|
+
# xampl-pp : XML pull parser
|
4
|
+
# Copyright (C) 2002-2009 Bob Hutchison
|
5
|
+
#
|
6
|
+
# This library is free software; you can redistribute it and/or
|
7
|
+
# modify it under the terms of the GNU Lesser General Public
|
8
|
+
# License as published by the Free Software Foundation; either
|
9
|
+
# version 2.1 of the License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This library is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# #Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public
|
17
|
+
# License along with this library; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
#
|
20
|
+
|
21
|
+
require "xampl-pp"
|
22
|
+
require "saxish"
|
23
|
+
require "saxishHandler"
|
24
|
+
|
25
|
+
#
|
26
|
+
# This module uses the saxish api. The saxish api is meant to demonstrate
|
27
|
+
# the use of Xampl_PP pull parser, while being useful in itself. If you are
|
28
|
+
# meaning to learn about the Xampl_PP parser, you should look at the
|
29
|
+
# saxish.rb file -- this one isn't going to help you a lot.
|
30
|
+
#
|
31
|
+
|
32
|
+
class SAXdemo
|
33
|
+
include SAXishHandler
|
34
|
+
|
35
|
+
attr :verbose, true
|
36
|
+
|
37
|
+
def resolve(name)
|
38
|
+
@resolverCount += 1
|
39
|
+
return "fake it"
|
40
|
+
end
|
41
|
+
|
42
|
+
def startElement(name, namespace, qname, prefix, attributeCount, isEmpty, saxparser)
|
43
|
+
printf("StartElement -- name: '%s'\n", name) if verbose
|
44
|
+
printf(" namespace: '%s'\n", namespace) if verbose
|
45
|
+
printf(" qname: '%s'\n", qname) if verbose
|
46
|
+
printf(" prefix: '%s'\n", prefix) if verbose
|
47
|
+
printf(" attributeCount: %d\n", attributeCount) if verbose
|
48
|
+
printf(" isEmpty: %s\n", isEmpty) if verbose
|
49
|
+
i = 0
|
50
|
+
while i < attributeCount do
|
51
|
+
printf(" attribute[%d] -- name: '%s'\n", i, saxparser.attributeName(i)) if verbose
|
52
|
+
printf(" attribute[%d] -- namespace: '%s'\n", i, saxparser.attributeNamespace(i)) if verbose
|
53
|
+
printf(" attribute[%d] -- qname: '%s'\n", i, saxparser.attributeQName(i)) if verbose
|
54
|
+
printf(" attribute[%d] -- prefix: '%s'\n", i, saxparser.attributePrefix(i)) if verbose
|
55
|
+
printf(" attribute[%d] -- value: '%s'\n", i, saxparser.attributeValue(i)) if verbose
|
56
|
+
i += 1
|
57
|
+
end
|
58
|
+
@startElementEventCount += 1
|
59
|
+
@eventCount += 1
|
60
|
+
if @maxDepth < saxparser.depth then
|
61
|
+
@maxDepth = saxparser.depth
|
62
|
+
@maxDepthLine = saxparser.line
|
63
|
+
@maxDepthColumn = saxparser.column
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def endElement(name, namespace, qname, prefix)
|
68
|
+
printf("EndElement -- name: '%s'\n", name) if verbose
|
69
|
+
printf(" namespace: '%s'\n", namespace) if verbose
|
70
|
+
printf(" qname: '%s'\n", qname) if verbose
|
71
|
+
printf(" prefix: '%s'\n", prefix) if verbose
|
72
|
+
@endElementEventCount += 1
|
73
|
+
@eventCount += 1
|
74
|
+
end
|
75
|
+
|
76
|
+
def entityRef(name, text)
|
77
|
+
printf("EntityRef -- name '%s' text '%s'\n", name, text) if verbose
|
78
|
+
@entityRefCount += 1
|
79
|
+
@eventCount += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
def text(text, isWhitespace)
|
83
|
+
if not isWhitespace then
|
84
|
+
printf("Text -- length: %d\n", text.length) if verbose
|
85
|
+
@textEventCount += 1
|
86
|
+
else
|
87
|
+
printf("Text -- length: %d WHITESPACE\n", text.length) if verbose
|
88
|
+
@whitespaceTextEventCount += 1
|
89
|
+
end
|
90
|
+
@eventCount += 1
|
91
|
+
end
|
92
|
+
|
93
|
+
def cdataSection(text)
|
94
|
+
printf("CDATA -- length: %s\n", text.length) if verbose
|
95
|
+
@cdataEventCount += 1
|
96
|
+
@eventCount += 1
|
97
|
+
end
|
98
|
+
|
99
|
+
def ignoreableWhitespace(text)
|
100
|
+
printf("IgnoreableWhitespace -- length: %s\n", text.length) if verbose
|
101
|
+
@ignorableWhitespaceEventCount += 1
|
102
|
+
@eventCount += 1
|
103
|
+
end
|
104
|
+
|
105
|
+
def processingInstruction(text)
|
106
|
+
printf("ProcessingInstruction -- [%s]\n", text) if verbose
|
107
|
+
@processingInstructionEventCount += 1
|
108
|
+
@eventCount += 1
|
109
|
+
end
|
110
|
+
|
111
|
+
def comment(text)
|
112
|
+
printf("comment -- [%s]\n", text) if verbose
|
113
|
+
@commentEventCount += 1
|
114
|
+
@eventCount += 1
|
115
|
+
end
|
116
|
+
|
117
|
+
def doctype(text)
|
118
|
+
printf("doctype -- [%s]\n", text) if verbose
|
119
|
+
@doctypeEventCount += 1
|
120
|
+
@eventCount += 1
|
121
|
+
end
|
122
|
+
|
123
|
+
def init
|
124
|
+
@startElementEventCount = 0
|
125
|
+
@endElementEventCount = 0
|
126
|
+
@entityRefCount = 0
|
127
|
+
@resolverCount = 0
|
128
|
+
@textEventCount = 0
|
129
|
+
@cdataEventCount = 0
|
130
|
+
@whitespaceTextEventCount = 0
|
131
|
+
@ignorableWhitespaceEventCount = 0
|
132
|
+
@processingInstructionEventCount = 0
|
133
|
+
@doctypeEventCount = 0
|
134
|
+
@commentEventCount = 0
|
135
|
+
@eventCount = 0
|
136
|
+
@failureCount = 0
|
137
|
+
@successCount = 0
|
138
|
+
@maxDepth = -1
|
139
|
+
end
|
140
|
+
|
141
|
+
def report
|
142
|
+
printf("%5d eventCount\n", @eventCount)
|
143
|
+
printf("%5d successCount\n", @successCount)
|
144
|
+
printf("%5d maxDepth [%d, %d]\n", @maxDepth, @maxDepthLine, @maxDepthColumn)
|
145
|
+
printf("%5d failureCount\n", @failureCount)
|
146
|
+
printf("%5d startElementEventCount\n", @startElementEventCount)
|
147
|
+
printf("%5d endElementEventCount\n", @endElementEventCount)
|
148
|
+
printf("%5d entityRefCount\n", @entityRefCount)
|
149
|
+
printf("%5d resolverCount\n", @resolverCount)
|
150
|
+
printf("%5d textEventCount\n", @textEventCount)
|
151
|
+
printf("%5d cdataEventCount\n", @cdataEventCount)
|
152
|
+
printf("%5d whitespaceTextEventCount\n", @whitespaceTextEventCount)
|
153
|
+
printf("%5d ignorableWhitespaceEventCount\n", @ignorableWhitespaceEventCount)
|
154
|
+
printf("%5d processingInstructionEventCount\n", @processingInstructionEventCount)
|
155
|
+
printf("%5d doctypeEventCount\n", @doctypeEventCount)
|
156
|
+
printf("%5d commentEventCount\n", @commentEventCount)
|
157
|
+
end
|
158
|
+
|
159
|
+
def fileNames(fileNames)
|
160
|
+
init
|
161
|
+
|
162
|
+
@saxparser = SAXish.new
|
163
|
+
@saxparser.handler = self
|
164
|
+
@saxparser.processNamespace = true
|
165
|
+
@saxparser.reportNamespaceAttributes = false
|
166
|
+
|
167
|
+
fileNames.each do
|
168
|
+
| filename |
|
169
|
+
begin
|
170
|
+
@saxparser.parse filename
|
171
|
+
@successCount += 1
|
172
|
+
rescue Exception => message
|
173
|
+
@failureCount += 1
|
174
|
+
print message.backtrace.join("\n")
|
175
|
+
printf("FAILED [%s] '%s'\n", message, filename)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
report
|
180
|
+
end
|
181
|
+
|
182
|
+
def string(string)
|
183
|
+
init
|
184
|
+
|
185
|
+
@saxparser = SAXish.new
|
186
|
+
@saxparser.handler = self
|
187
|
+
@saxparser.processNamespace = true
|
188
|
+
@saxparser.reportNamespaceAttributes = false
|
189
|
+
|
190
|
+
begin
|
191
|
+
@saxparser.parseString string
|
192
|
+
@successCount += 1
|
193
|
+
rescue Exception => message
|
194
|
+
@failureCount += 1
|
195
|
+
print message.backtrace.join("\n")
|
196
|
+
printf("FAILED [%s] '%s'\n", message, string)
|
197
|
+
end
|
198
|
+
|
199
|
+
report
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
string = <<EOS
|
204
|
+
<root>
|
205
|
+
<a>
|
206
|
+
</a>
|
207
|
+
<b>hello</b>
|
208
|
+
<c>hello &there;</c>
|
209
|
+
</root>
|
210
|
+
EOS
|
211
|
+
|
212
|
+
SAXdemo.new.string(string)
|
213
|
+
SAXdemo.new.fileNames(ARGV)
|
214
|
+
|