Class: Xpp

Inherits:
Object
  • Object
show all
Defined in:
lib/xamplr-pp/xpp.rb,
lib/xamplr-pp/xppIter.rb,
lib/xamplr-pp/xppDeluxe.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'
LOOK_FURTHER =
'LOOK_FURTHER'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributeNameObject (readonly)

Returns the value of attribute attributeName.



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

def attributeName
  @attributeName
end

#attributeNamespaceObject (readonly)

Returns the value of attribute attributeNamespace.



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

def attributeNamespace
  @attributeNamespace
end

#attributePrefixObject (readonly)

Returns the value of attribute attributePrefix.



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

def attributePrefix
  @attributePrefix
end

#attributeQNameObject (readonly)

Returns the value of attribute attributeQName.



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

def attributeQName
  @attributeQName
end

#attributeValueObject (readonly)

Returns the value of attribute attributeValue.



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

def attributeValue
  @attributeValue
end

#checkWellFormedObject

Returns the value of attribute checkWellFormed.



38
39
40
# File 'lib/xamplr-pp/xpp.rb', line 38

def checkWellFormed
  @checkWellFormed
end

#columnObject (readonly)

Returns the value of attribute column.



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

def column
  @column
end

#elementNameObject (readonly)

open element information



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

def elementName
  @elementName
end

#elementNamespaceObject (readonly)

Returns the value of attribute elementNamespace.



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

def elementNamespace
  @elementNamespace
end

#elementNamespaceDefaultStackObject (readonly)

Returns the value of attribute elementNamespaceDefaultStack.



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

def elementNamespaceDefaultStack
  @elementNamespaceDefaultStack
end

#elementNamespacePrefixStackObject (readonly)

Returns the value of attribute elementNamespacePrefixStack.



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

def elementNamespacePrefixStack
  @elementNamespacePrefixStack
end

#elementNamespaceValueStackObject (readonly)

Returns the value of attribute elementNamespaceValueStack.



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

def elementNamespaceValueStack
  @elementNamespaceValueStack
end

#elementPrefixObject (readonly)

Returns the value of attribute elementPrefix.



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

def elementPrefix
  @elementPrefix
end

#elementQNameObject (readonly)

Returns the value of attribute elementQName.



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

def elementQName
  @elementQName
end

#emptyElementObject (readonly)

Returns the value of attribute emptyElement.



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

def emptyElement
  @emptyElement
end

#entityMapObject

the entities that we will recognise



42
43
44
# File 'lib/xamplr-pp/xpp.rb', line 42

def entityMap
  @entityMap
end

#lineObject (readonly)

some information about where we are



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

def line
  @line
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#namePatternObject

some pre-compiled patterns



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

def namePattern
  @namePattern
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#processNamespaceObject

‘Features’, acutally just processing options



36
37
38
# File 'lib/xamplr-pp/xpp.rb', line 36

def processNamespace
  @processNamespace
end

#qnameObject (readonly)

Returns the value of attribute qname.



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

def qname
  @qname
end

#reportNamespaceAttributesObject

Returns the value of attribute reportNamespaceAttributes.



37
38
39
# File 'lib/xamplr-pp/xpp.rb', line 37

def reportNamespaceAttributes
  @reportNamespaceAttributes
end

#resolverObject

Returns the value of attribute resolver.



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

def resolver
  @resolver
end

#skipWhitespacePatternObject

Returns the value of attribute skipWhitespacePattern.



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

def skipWhitespacePattern
  @skipWhitespacePattern
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

#typeObject (readonly)

element information



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

def type
  @type
end

#unresolvedEntityObject (readonly)

Returns the value of attribute unresolvedEntity.



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

def unresolvedEntity
  @unresolvedEntity
end

#utf8encodeObject

Returns the value of attribute utf8encode.



39
40
41
# File 'lib/xamplr-pp/xpp.rb', line 39

def utf8encode
  @utf8encode
end

#whitespaceObject (readonly)

is the current text whitespace?



30
31
32
# File 'lib/xamplr-pp/xppIter.rb', line 30

def whitespace
  @whitespace
end

Instance Method Details

#cdata?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/xamplr-pp/xpp.rb', line 102

def cdata?
  @type.equal? CDATA_SECTION
end

#comment?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/xamplr-pp/xpp.rb', line 122

def comment?
  @type.equal? COMMENT
end

#doctype?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/xamplr-pp/xpp.rb', line 126

def doctype?
  @type.equal? DOCTYPE
end

#endDocument?Boolean

Returns:

  • (Boolean)


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

def endDocument?
  @type.equal? END_DOCUMENT
end

#endElement?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/xamplr-pp/xpp.rb', line 94

def endElement?
  @type.equal? END_ELEMENT
end

#entityRef?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/xamplr-pp/xpp.rb', line 106

def entityRef?
  @type.equal? ENTITY_REF
end

#ignorableWhitespace?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/xamplr-pp/xpp.rb', line 110

def ignorableWhitespace?
  @type.equal? IGNORABLE_WHITESPACE
end

#initInputObject



183
184
185
# File 'lib/xamplr-pp/xpp.rb', line 183

def initInput
  # override this if needed
end

#input=(v) ⇒ Object

end



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/xamplr-pp/xppIter.rb', line 114

def input=(v)
  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

  @haveRoot = false

  initInput
end

#lookFurther?Boolean

Returns:

  • (Boolean)


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

def lookFurther?
	@type.equal? LOOK_FURTHER
end

#nextEventObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/xamplr-pp/xpp.rb', line 187

def nextEvent
  begin
    @type = END_DOCUMENT
    if (nil == @inputBuffer) and (nil == @input) then
      #if END_DOCUMENT == @type then
        return @type
      #end
      #raise "no input defined"
    end

    @unresolvedEntity = false

    @text = nil

    parseNextEvent

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

#processingInstruction?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/xamplr-pp/xpp.rb', line 118

def processingInstruction?
  @type.equal? PROCESSING_INSTRUCTION
end

#startDocument?Boolean

Returns:

  • (Boolean)


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

def startDocument?
  @type.equal? START_DOCUMENT
end

#startElement?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/xamplr-pp/xpp.rb', line 90

def startElement?
  @type.equal? START_ELEMENT
end

#text?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/xamplr-pp/xpp.rb', line 98

def text?
  @type.equal? TEXT
end

#whitespace?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/xamplr-pp/xpp.rb', line 114

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