hutch-xamplr-pp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/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/lib/xamplr-pp.rb +991 -0
- data/test/test_helper.rb +10 -0
- data/test/xamplr_pp_gem_test.rb +7 -0
- metadata +79 -0
data/lib/xampl-pp-dtd.rb
ADDED
@@ -0,0 +1,126 @@
|
|
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
|
+
#
|
18
|
+
|
19
|
+
require "xampl-pp"
|
20
|
+
|
21
|
+
class Xampl_PP
|
22
|
+
|
23
|
+
def parseXMLDecl
|
24
|
+
@standalone = false
|
25
|
+
return nil != @text.index(/^xml[\n\r\t ]/mu)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parseDefinition(defn, internal)
|
29
|
+
return if defn.length <= 0
|
30
|
+
|
31
|
+
p = defn.index(/<!ELEMENT/u)
|
32
|
+
if 0 == p then
|
33
|
+
return parseElementDefinition(defn, internal)
|
34
|
+
end
|
35
|
+
|
36
|
+
p = defn.index(/<!ATTLIST/u)
|
37
|
+
if 0 == p then
|
38
|
+
return parseAttlistDefinition(defn, internal)
|
39
|
+
end
|
40
|
+
|
41
|
+
p = defn.index(/<!NOTATION/u)
|
42
|
+
if 0 == p then
|
43
|
+
return parseNotationDefinition(defn, internal)
|
44
|
+
end
|
45
|
+
|
46
|
+
p = defn.index(/<!ENTITY.*%/mu)
|
47
|
+
if 0 == p then
|
48
|
+
return parseParameterEntityDefinition(defn, internal)
|
49
|
+
end
|
50
|
+
|
51
|
+
p = defn.index(/<!ENTITY.*SYSTEM/mu)
|
52
|
+
if 0 == p then
|
53
|
+
return parseSystemEntityDefinition(defn, internal)
|
54
|
+
end
|
55
|
+
|
56
|
+
p = defn.index(/<!ENTITY.*PUBLIC/mu)
|
57
|
+
if 0 == p then
|
58
|
+
return parsePublicEntityDefinition(defn, internal)
|
59
|
+
end
|
60
|
+
|
61
|
+
p = defn.index(/<!ENTITY/u)
|
62
|
+
if 0 == p then
|
63
|
+
return parseEntityDefinition(defn, internal)
|
64
|
+
end
|
65
|
+
|
66
|
+
p = defn.index(/<\?.*\?>/mu)
|
67
|
+
if 0 == p then
|
68
|
+
return parsePIDefinition(defn, internal)
|
69
|
+
end
|
70
|
+
|
71
|
+
raise sprintf("NOT recognised in the %s subset", (internal ? "internal" : "external"))
|
72
|
+
end
|
73
|
+
|
74
|
+
def parseElementDefinition(defn, internal)
|
75
|
+
#printf("element '%s' internal? %s\n", defn, internal)
|
76
|
+
end
|
77
|
+
|
78
|
+
def parseEntityDefinition(defn, internal)
|
79
|
+
if !internal then
|
80
|
+
raise "unexpected GEDecl"
|
81
|
+
end
|
82
|
+
#printf("entity '%s' internal? %s\n", defn, internal)
|
83
|
+
regex = /<!ENTITY[\n\r\t ]+([^\n\r\t ]+)[\n\r\t ]+"([^"]*)"[\n\r\t ]*>/mu
|
84
|
+
match = defn.match(regex).to_a
|
85
|
+
if 3 != match.length then
|
86
|
+
regex = /<!ENTITY[\n\r\t ]+([^\n\r\t ]+)[\n\r\t ]+'([^']*)'[\n\r\t ]*>/mu
|
87
|
+
match = defn.match(regex).to_a
|
88
|
+
if 3 != match.length then
|
89
|
+
raise sprintf("invalid GEDecl")
|
90
|
+
end
|
91
|
+
#raise sprintf("invalid GEDecl '%s'", defn)
|
92
|
+
end
|
93
|
+
name = match[1]
|
94
|
+
value = match[2]
|
95
|
+
#printf("name [%s] value [%s]\n", name, value)
|
96
|
+
entityMap[name] = value
|
97
|
+
end
|
98
|
+
|
99
|
+
def parseParameterEntityDefinition(defn, internal)
|
100
|
+
#printf("pentity '%s' internal? %s\n", defn, internal)
|
101
|
+
end
|
102
|
+
|
103
|
+
def parsePublicEntityDefinition(defn, internal)
|
104
|
+
#printf("public entity '%s' internal? %s\n", defn, internal)
|
105
|
+
end
|
106
|
+
|
107
|
+
def parseSystemEntityDefinition(defn, internal)
|
108
|
+
#printf("system entity '%s' internal? %s\n", defn, internal)
|
109
|
+
end
|
110
|
+
|
111
|
+
def parseAttlistDefinition(defn, internal)
|
112
|
+
printf("attlist '%s' internal? %s\n", defn, internal)
|
113
|
+
end
|
114
|
+
|
115
|
+
def parseNotationDefinition(defn, internal)
|
116
|
+
#printf("notation '%s' internal? %s\n", defn, internal)
|
117
|
+
end
|
118
|
+
|
119
|
+
def parsePIDefinition(defn, internal)
|
120
|
+
if !internal then
|
121
|
+
raise "unexpected processing instruction"
|
122
|
+
end
|
123
|
+
#printf("PI '%s' internal? %s\n", defn, internal)
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|