hutch-xamplr-pp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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