Class: Xampl_PP

Inherits:
Object
  • Object
show all
Defined in:
lib/xamplr-pp.rb,
lib/no-longer-actively-supported/xampl-pp-wf.rb,
lib/no-longer-actively-supported/xampl-pp-dtd.rb,
lib/no-longer-actively-supported/xamplr-pp-18x.rb

Constant Summary collapse

START_DOCUMENT =

XML ‘event’ types

'START_DOCUMENT'
END_DOCUMENT =
'END_DOCUMENT'
START_ELEMENT =
'START_ELEMENT'
END_ELEMENT =
'END_ELEMENT'
TEXT =
'TEXT'
CDATA_SECTION =
'CDATA_SECTION'
ENTITY_REF =
'ENTITY_REF'
IGNORABLE_WHITESPACE =
'IGNORABLE_WHITESPACE'
PROCESSING_INSTRUCTION =
'PROCESSING_INSTRUCTION'
COMMENT =
'COMMENT'
DOCTYPE =
'DOCTYPE'
UNDECIDED_TYPE =
'UNDECIDED_TYPE'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributeNameObject

Returns the value of attribute attributeName.



64
65
66
# File 'lib/xamplr-pp.rb', line 64

def attributeName
  @attributeName
end

#attributeNamespaceObject

Returns the value of attribute attributeNamespace.



66
67
68
# File 'lib/xamplr-pp.rb', line 66

def attributeNamespace
  @attributeNamespace
end

#attributePrefixObject

Returns the value of attribute attributePrefix.



67
68
69
# File 'lib/xamplr-pp.rb', line 67

def attributePrefix
  @attributePrefix
end

#attributeQNameObject

Returns the value of attribute attributeQName.



65
66
67
# File 'lib/xamplr-pp.rb', line 65

def attributeQName
  @attributeQName
end

#attributeValueObject

Returns the value of attribute attributeValue.



68
69
70
# File 'lib/xamplr-pp.rb', line 68

def attributeValue
  @attributeValue
end

#columnObject

Returns the value of attribute column.



55
56
57
# File 'lib/xamplr-pp.rb', line 55

def column
  @column
end

#elementNameObject

open element information



75
76
77
# File 'lib/xamplr-pp.rb', line 75

def elementName
  @elementName
end

#elementNamespaceObject

Returns the value of attribute elementNamespace.



77
78
79
# File 'lib/xamplr-pp.rb', line 77

def elementNamespace
  @elementNamespace
end

#elementNamespaceDefaultStackObject

Returns the value of attribute elementNamespaceDefaultStack.



86
87
88
# File 'lib/xamplr-pp.rb', line 86

def elementNamespaceDefaultStack
  @elementNamespaceDefaultStack
end

#elementNamespacePrefixStackObject

Returns the value of attribute elementNamespacePrefixStack.



84
85
86
# File 'lib/xamplr-pp.rb', line 84

def elementNamespacePrefixStack
  @elementNamespacePrefixStack
end

#elementNamespaceValueStackObject

Returns the value of attribute elementNamespaceValueStack.



85
86
87
# File 'lib/xamplr-pp.rb', line 85

def elementNamespaceValueStack
  @elementNamespaceValueStack
end

#elementPrefixObject

Returns the value of attribute elementPrefix.



78
79
80
# File 'lib/xamplr-pp.rb', line 78

def elementPrefix
  @elementPrefix
end

#elementQNameObject

Returns the value of attribute elementQName.



76
77
78
# File 'lib/xamplr-pp.rb', line 76

def elementQName
  @elementQName
end

#emptyElementObject

Returns the value of attribute emptyElement.



59
60
61
# File 'lib/xamplr-pp.rb', line 59

def emptyElement
  @emptyElement
end

#entityMapObject

the entities that we will recognise



49
50
51
# File 'lib/xamplr-pp.rb', line 49

def entityMap
  @entityMap
end

#lineObject

some information about where we are



54
55
56
# File 'lib/xamplr-pp.rb', line 54

def line
  @line
end

#nameObject

Returns the value of attribute name.



60
61
62
# File 'lib/xamplr-pp.rb', line 60

def name
  @name
end

#namePatternObject

some pre-compiled patterns



81
82
83
# File 'lib/xamplr-pp.rb', line 81

def namePattern
  @namePattern
end

#namespaceObject

Returns the value of attribute namespace.



62
63
64
# File 'lib/xamplr-pp.rb', line 62

def namespace
  @namespace
end

#prefixObject

Returns the value of attribute prefix.



63
64
65
# File 'lib/xamplr-pp.rb', line 63

def prefix
  @prefix
end

#processNamespaceObject

‘Features’, acutally just processing options



44
45
46
# File 'lib/xamplr-pp.rb', line 44

def processNamespace
  @processNamespace
end

#qnameObject

Returns the value of attribute qname.



61
62
63
# File 'lib/xamplr-pp.rb', line 61

def qname
  @qname
end

#reportNamespaceAttributesObject

1.9.1 , true



45
46
47
# File 'lib/xamplr-pp.rb', line 45

def reportNamespaceAttributes
  @reportNamespaceAttributes
end

#resolverObject

1.9.1 , true



51
52
53
# File 'lib/xamplr-pp.rb', line 51

def resolver
  @resolver
end

#skipWhitespacePatternObject

1.9.1 , true



82
83
84
# File 'lib/xamplr-pp.rb', line 82

def skipWhitespacePattern
  @skipWhitespacePattern
end

#standaloneObject

Returns the value of attribute standalone.



88
89
90
# File 'lib/xamplr-pp.rb', line 88

def standalone
  @standalone
end

#textObject

Returns the value of attribute text.



70
71
72
# File 'lib/xamplr-pp.rb', line 70

def text
  @text
end

#typeObject

element information



58
59
60
# File 'lib/xamplr-pp.rb', line 58

def type
  @type
end

#unresolvedEntityObject

Returns the value of attribute unresolvedEntity.



50
51
52
# File 'lib/xamplr-pp.rb', line 50

def unresolvedEntity
  @unresolvedEntity
end

#utf8encodeObject

1.9.1 , true



46
47
48
# File 'lib/xamplr-pp.rb', line 46

def utf8encode
  @utf8encode
end

Instance Method Details

#cdata?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/xamplr-pp.rb', line 112

def cdata?
  @type.equal? CDATA_SECTION
end

#comment?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/xamplr-pp.rb', line 132

def comment?
  @type.equal? COMMENT
end

#depthObject



239
240
241
# File 'lib/xamplr-pp.rb', line 239

def depth
  return @elementName.length
end

#doctype?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/xamplr-pp.rb', line 136

def doctype?
  @type.equal? DOCTYPE
end

#encodeBaseObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/no-longer-actively-supported/xampl-pp-wf.rb', line 24

def encode(c)
  if @utf8encode then
#      if c < 0x80 then
#        @textBuffer << c
#       elsif c < 0x0800
#         @textBuffer << ((c >> 6) | 0xC0)
#         @textBuffer << (c & (0x3F | 0x80))
#       elsif c < 0x10000
#         @textBuffer << ((c >> 12) | 0xE0)
#         @textBuffer << ((c >> 6) & (0x3F | 0x80))
#         @textBuffer << (c & (0x3F | 0x80))
#       else
#         @textBuffer << ((c >> 18) | 0xF0)
#         @textBuffer << ((c >> 12) & (0x3F | 0x80))
#         @textBuffer << ((c >> 6) & (0x3F | 0x80))
#         @textBuffer << (c & (0x3F | 0x80))
#      end
    if c < 0x80 then
      @textBuffer << c
    elsif c < 0x0800
      @textBuffer << ((c >> 6) | 0xC0)
      @textBuffer << ((c & 0x3F) | 0x80)
    elsif c < 0x10000
      @textBuffer << ((c >> 12) | 0xE0)
      @textBuffer << (((c >> 6) & 0x3F) | 0x80)
      @textBuffer << ((c & 0x3F) | 0x80)
    else
      @textBuffer << ((c >> 18) | 0xF0)
      @textBuffer << (((c >> 12) & 0x3F) | 0x80)
      @textBuffer << (((c >> 6) & 0x3F) | 0x80)
      @textBuffer << ((c & 0x3F) | 0x80)
    end
  else
    @textBuffer << c
  end
end

#endDocument?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/xamplr-pp.rb', line 96

def endDocument?
  @type.equal? END_DOCUMENT
end

#endElement?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/xamplr-pp.rb', line 104

def endElement?
  @type.equal? END_ELEMENT
end

#entityRef?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/xamplr-pp.rb', line 116

def entityRef?
  @type.equal? ENTITY_REF
end

#first_byte(str) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/xamplr-pp.rb', line 35

def first_byte(str)
  if "9" == RUBY_VERSION[2..2] then
    str.bytes.first
  else
    str[0]
  end
end

#ignorableWhitespace?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/xamplr-pp.rb', line 120

def ignorableWhitespace?
  @type.equal? IGNORABLE_WHITESPACE
end

#initInputObject



204
205
206
# File 'lib/xamplr-pp.rb', line 204

def initInput
  # redefine this method if you have some initialisation you need done
end

#input=(v) ⇒ Object



144
145
146
# File 'lib/xamplr-pp.rb', line 144

def input=(v)
  setInput(v)
end

#nextEventObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/xamplr-pp.rb', line 208

def nextEvent
  begin
    @type = END_DOCUMENT
    if (nil == @inputBuffer) and (nil == @input) then
      return @type
    end

    @unresolvedEntity = false

    @text = nil

    parseNextEvent

    return @type
  rescue Exception => message
    print message.backtrace.join("\n")
    if nil != @inputBuffer then
      @errorMessage = sprintf("parse error: '%s' -- String input, line %d, column %d", message, @line, @column)
    elsif nil != @input then
      if @input.kind_of? File then
        @errorMessage = sprintf("parse error: '%s' -- file '%s', line %d, column %d", message, @input.path, @line, @column)
      else
        @errorMessage = sprintf("parse error: '%s' -- unnamed IO stream, line %d, column %d", message, @line, @column)
      end
    else
      @errorMessage = sprintf("parse error: '%s' -- unknown source, line %d, column %d", message, @line, @column)
    end
    raise @errorMessage
  end
end

#nextEventBaseObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/no-longer-actively-supported/xampl-pp-wf.rb', line 22

def nextEvent
  begin
    @type = END_DOCUMENT
    if (nil == @inputBuffer) and (nil == @input) then
      return @type
    end

    @unresolvedEntity = false

    @text = nil

    parseNextEvent

    return @type
  rescue Exception => message
    print message.backtrace.join("\n")
    if nil != @inputBuffer then
      @errorMessage = sprintf("parse error: '%s' -- String input, line %d, column %d", message, @line, @column)
    elsif nil != @input then
      if @input.kind_of? File then
        @errorMessage = sprintf("parse error: '%s' -- file '%s', line %d, column %d", message, @input.path, @line, @column)
      else
        @errorMessage = sprintf("parse error: '%s' -- unnamed IO stream, line %d, column %d", message, @line, @column)
      end
    else
      @errorMessage = sprintf("parse error: '%s' -- unknown source, line %d, column %d", message, @line, @column)
    end
    raise @errorMessage
  end
end

#parseAttlistDefinition(defn, internal) ⇒ Object



111
112
113
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 111

def parseAttlistDefinition(defn, internal)
	printf("attlist '%s' internal? %s\n", defn, internal)
end

#parseElementDefinition(defn, internal) ⇒ Object



74
75
76
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 74

def parseElementDefinition(defn, internal)
	#printf("element '%s' internal? %s\n", defn, internal)
end

#parseEntityDefinition(defn, internal) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 78

def parseEntityDefinition(defn, internal)
	if !internal then
		raise "unexpected GEDecl"
	end
#printf("entity '%s' internal? %s\n", defn, internal)
   regex = /<!ENTITY[\n\r\t ]+([^\n\r\t ]+)[\n\r\t ]+"([^"]*)"[\n\r\t ]*>/mu
	match = defn.match(regex).to_a
	if 3 != match.length then
   	regex = /<!ENTITY[\n\r\t ]+([^\n\r\t ]+)[\n\r\t ]+'([^']*)'[\n\r\t ]*>/mu
		match = defn.match(regex).to_a
		if 3 != match.length then
			raise sprintf("invalid GEDecl")
		end
		#raise sprintf("invalid GEDecl '%s'", defn)
	end
	name = match[1]
	value = match[2]
#printf("name [%s] value [%s]\n", name, value)
   entityMap[name] = value
end

#parseNotationDefinition(defn, internal) ⇒ Object



115
116
117
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 115

def parseNotationDefinition(defn, internal)
	#printf("notation '%s' internal? %s\n", defn, internal)
end

#parseParameterEntityDefinition(defn, internal) ⇒ Object



99
100
101
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 99

def parseParameterEntityDefinition(defn, internal)
	#printf("pentity '%s' internal? %s\n", defn, internal)
end

#parsePIDefinition(defn, internal) ⇒ Object



119
120
121
122
123
124
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 119

def parsePIDefinition(defn, internal)
	if !internal then
		raise "unexpected processing instruction"
	end
	#printf("PI '%s' internal? %s\n", defn, internal)
end

#parsePublicEntityDefinition(defn, internal) ⇒ Object



103
104
105
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 103

def parsePublicEntityDefinition(defn, internal)
	#printf("public entity '%s' internal? %s\n", defn, internal)
end

#parseSystemEntityDefinition(defn, internal) ⇒ Object



107
108
109
# File 'lib/no-longer-actively-supported/xampl-pp-dtd.rb', line 107

def parseSystemEntityDefinition(defn, internal)
	#printf("system entity '%s' internal? %s\n", defn, internal)
end

#processingInstruction?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/xamplr-pp.rb', line 128

def processingInstruction?
  @type.equal? PROCESSING_INSTRUCTION
end

#readBaseObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/no-longer-actively-supported/xampl-pp-wf.rb', line 25

def read
  if (nil == @inputBuffer) or (@inputBufferLength <= @column) then
    getMoreInput
    if nil == @inputBuffer then
      return nil
    end
  end

  #puts "#{ __FILE__ }:#{ __LINE__ } READ COLUMN #{ @column } FROM: #{ @inputBuffer }"
  #puts "#{ __FILE__ }:#{ __LINE__ } READ: #{  @inputBuffer[@column] }"
  if "9" == RUBY_VERSION[2..2] then
    c = @inputBuffer[@column].bytes.first # 1.9.1 fixup
  else
    c = @inputBuffer[@column]
  end
  @column += 1
  return c
end

#resolve(name) ⇒ Object



140
141
142
# File 'lib/xamplr-pp.rb', line 140

def resolve(name)
  raise sprintf("unresolved entity '%s'", name)
end

#setInput(v) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/xamplr-pp.rb', line 148

def setInput(v)
  if (defined? @input) and (nil != @input) then
    @input.close
  end
  if nil == v then
    @input = nil
    @inputBuffer = nil
    @inputBufferLength = 0
    @column = 0
    @line = 0
  elsif v.kind_of? String then
    @input = nil
    @inputBuffer = v
    @inputBufferLength = v.length
    @line = 1
    @column = 0
  elsif v.kind_of? IO then
    @input = v
    @inputBuffer = nil
    @inputBufferLength = 0
    @column = 0
    @line = 0
  else
    raise "illegalInput"
  end
  @nextInputBuffer = nil
  @textBuffer = ''

  @elementNamespacePrefixStack = []
  @elementNamespaceValueStack = []
  @elementNamespaceDefaultStack = []

  @elementName = []
  @elementQName = []
  @elementNamespace = []
  @elementPrefix = []

  @type = START_DOCUMENT
  @unresolvedEntity = false

  @name = nil
  @namespace = nil

  @attributeName = []
  @attributeQName = []
  @attributeNamespace = []
  @attributePrefix = []
  @attributeValue = []

  @emptyElement = false

  @errorMessage = nil

  initInput
end

#setInputBaseObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/no-longer-actively-supported/xampl-pp-wf.rb', line 23

def setInput(v)
  if (defined? @input) and (nil != @input) then
    @input.close
  end
  if nil == v then
    @input = nil
    @inputBuffer = nil
    @inputBufferLength = 0
    @column = 0
    @line = 0
  elsif v.kind_of? String then
    @input = nil
    @inputBuffer = v
    @inputBufferLength = v.length
    @line = 1
    @column = 0
  elsif v.kind_of? IO then
    @input = v
    @inputBuffer = nil
    @inputBufferLength = 0
    @column = 0
    @line = 0
  else
    raise "illegalInput"
  end
  @nextInputBuffer = nil
  @textBuffer = ''

  @elementNamespacePrefixStack = []
  @elementNamespaceValueStack = []
  @elementNamespaceDefaultStack = []

  @elementName = []
  @elementQName = []
  @elementNamespace = []
  @elementPrefix = []

  @type = START_DOCUMENT
  @unresolvedEntity = false

  @name = nil
  @namespace = nil

  @attributeName = []
  @attributeQName = []
  @attributeNamespace = []
  @attributePrefix = []
  @attributeValue = []

  @emptyElement = false

  @errorMessage = nil

  initInput
end

#startDocument?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/xamplr-pp.rb', line 92

def startDocument?
  @type.equal? START_DOCUMENT
end

#startElement?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/xamplr-pp.rb', line 100

def startElement?
  @type.equal? START_ELEMENT
end

#text?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/xamplr-pp.rb', line 108

def text?
  @type.equal? TEXT
end

#whitespace?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/xamplr-pp.rb', line 124

def whitespace?
  nil == @text.index(@skipWhitespacePattern)
end