Wed, 05 Jan 2011 17:09:08 +0000
util.xmllex: Decode XML entities
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
1 | local assert , ipairs , pairs , setmetatable , rawget , rawset , tostring = |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
2 | assert , ipairs , pairs , setmetatable , rawget , rawset , tostring |
4003
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
3 | local strchar , strgmatch , strgsub , strsub , strmatch = string.char , string.gmatch , string.gsub , string.sub , string.match |
3990 | 4 | local tblconcat = table.concat |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
5 | local tblinsert = table.insert |
3990 | 6 | |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
7 | local stanza_methods = require "util.stanza".stanza_mt; |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
8 | |
4003
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
9 | local entities = setmetatable ( { |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
10 | amp = "&" ; |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
11 | lt = "<" ; |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
12 | gt = ">" ; |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
13 | apos = "'" ; |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
14 | quot = '"' ; |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
15 | } , { __index = function ( entity ) |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
16 | return strchar ( tonumber ( entity:match ( "^#%d+" ) ) or error ( "invalid entity " .. entity ) ) |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
17 | end } ) |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
18 | local function xml_unescape ( str ) |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
19 | return ( strgsub ( str , "&([^;]*);" , entities ) ) |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
20 | end |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
21 | |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
22 | local function getstring ( msgs , startpos , finishpos ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
23 | if #msgs == 1 then --All originated in same string |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
24 | return strsub ( msgs[1] , startpos , finishpos ) |
3990 | 25 | else -- Over multiple source strings |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
26 | return strsub ( msgs[1] , startpos , -1 ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
27 | .. tblconcat ( msgs , "" , 2 , #msgs - 1 ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
28 | .. strsub ( msgs[#msgs] , 1 , finishpos ) |
3990 | 29 | end |
30 | end | |
31 | ||
32 | local m_mt = { | |
33 | __tostring = function ( v ) | |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
34 | local str = v.stringform |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
35 | if str then |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
36 | return str |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
37 | else |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
38 | str = getstring ( v.msgs , v.start , v.finish ) |
4003
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
39 | if v.type == "text" then |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
40 | str = xml_unescape ( str ) |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
41 | end |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
42 | v.stringform = str |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
43 | return str |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
44 | end |
3990 | 45 | end |
46 | } | |
47 | ||
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
48 | local function handleoutside ( str , r , initial ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
49 | local a , b , close = str:find ( "<(/?)" , initial ) |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
50 | |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
51 | if not a then |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
52 | r.state = "outside" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
53 | return false |
3990 | 54 | end |
55 | ||
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
56 | --Finalise text object |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
57 | local m = r[#r] |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
58 | m.finish = a - 1 |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
59 | m.type = "text" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
60 | |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
61 | local m = setmetatable ( { |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
62 | msgs = { str } ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
63 | start = a ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
64 | starte = b + 1 ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
65 | } , m_mt ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
66 | |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
67 | if close ~= "/" then |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
68 | r.depth = r.depth + 1 |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
69 | m.type = "open" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
70 | else |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
71 | r.depth = r.depth - 1 |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
72 | m.type = "close" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
73 | end |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
74 | |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
75 | tblinsert ( r , m ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
76 | |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
77 | r.state = "inside" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
78 | return true |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
79 | end |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
80 | |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
81 | local function handleinside ( str, r , initial ) |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
82 | local c , d , selfclosing = str:find ( "([/?]?)>" , initial ) |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
83 | if not c then |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
84 | r.state = "inside" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
85 | return false |
3990 | 86 | end |
87 | ||
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
88 | local m = r[#r] |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
89 | m.finish = d |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
90 | m.finishs = c - 1 |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
91 | if selfclosing == "/" or selfclosing == "?" then |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
92 | m.type = "selfclosing" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
93 | r.depth = r.depth - 1 |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
94 | end |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
95 | |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
96 | local m = setmetatable ( { |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
97 | msgs = { str } ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
98 | start = d + 1 ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
99 | type = "text" ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
100 | } , m_mt ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
101 | tblinsert ( r , m ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
102 | |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
103 | r.state = "outside" |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
104 | return true |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
105 | end |
3990 | 106 | |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
107 | local function index ( str , r ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
108 | r = r or { depth = 0, state = "outside" } |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
109 | |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
110 | local initial = 1 |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
111 | |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
112 | if not r[#r] then |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
113 | r[1] = setmetatable ( { |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
114 | msgs = { str } ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
115 | type = "text" ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
116 | start = 1 ; |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
117 | } , m_mt ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
118 | else |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
119 | tblinsert ( r[#r].msgs , str ) |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
120 | end |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
121 | |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
122 | while true do |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
123 | if r.state == "outside" then |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
124 | if not handleoutside ( str , r , initial ) then |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
125 | break |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
126 | end |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
127 | else |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
128 | if not handleinside ( str , r , initial ) then |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
129 | break |
3990 | 130 | end |
131 | end | |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
132 | initial = r[#r].start |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
133 | end |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
134 | |
3990 | 135 | return r |
136 | end | |
137 | ||
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
138 | local function get_name ( str ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
139 | return strmatch ( str , "^<([^%s>/]+)" ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
140 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
141 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
142 | local function get_attr ( str ) |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
143 | local attr = { } |
4003
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
144 | for name , quote, attvalue in strgmatch ( str , [=[([^%s=/<]+)%s*=%s*(["'])([^'"]*)%2]=] ) do |
cb6ddda1cb5f
util.xmllex: Decode XML entities
daurnimator <quae@daurnimator.com>
parents:
4002
diff
changeset
|
145 | attr [ name ] = xml_unescape ( attvalue ) |
3990 | 146 | end |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
147 | return attr |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
148 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
149 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
150 | function resolve_attr_namespaces ( attr ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
151 | local namespace = { } |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
152 | local prefixattr = { } |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
153 | for k , attr_value in pairs ( attr ) do |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
154 | local attr_prefix , attr_name = k:match ( "^([^:\1]+):?([^\1]-)$" ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
155 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
156 | if attr_prefix == nil then |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
157 | error ( "already resolved" ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
158 | elseif attr_prefix == "xmlns" then |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
159 | namespace [ attr_name ] = attr_value |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
160 | elseif #attr_name ~= 0 and attr_prefix ~= "xml" then |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
161 | local t = prefixattr [ attr_prefix ] |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
162 | if not t then |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
163 | t = { } |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
164 | prefixattr [ attr_prefix ] = t |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
165 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
166 | t [ attr_name ] = attr_value |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
167 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
168 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
169 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
170 | for k , v in pairs ( prefixattr ) do |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
171 | for name , value in pairs ( v ) do |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
172 | attr [ namespace [ k ] .. "\1" .. name ] = value |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
173 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
174 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
175 | return namespace |
3990 | 176 | end |
177 | ||
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
178 | local currentindex = 1 |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
179 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
180 | local function resolve_namespace ( element ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
181 | local parent = element.parent |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
182 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
183 | local prefix = get_name ( element.str ):match ( "^([^:]+):" ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
184 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
185 | local namespace = setmetatable ( resolve_attr_namespaces ( element.attr ) , { __index = parent.namespace } ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
186 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
187 | local current_namespace = prefix and ( namespace [ prefix ] or error ("unbound prefix: "..prefix) ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
188 | or rawget(element.attr, "xmlns") |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
189 | or parent.attr.xmlns |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
190 | or parent.namespace [ currentindex ] |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
191 | namespace [ currentindex ] = current_namespace |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
192 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
193 | return namespace |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
194 | end |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
195 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
196 | local dynamic_properties = { |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
197 | name = function ( t ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
198 | return get_name ( t.str ):match("[^:]+$") |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
199 | end; |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
200 | attr = function ( t , k ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
201 | return setmetatable ( get_attr ( t.str ) , { __index = function ( attr_table , attr ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
202 | local _ = t.namespace -- DO NOT OPTIMISE AWAY WAQAS |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
203 | setmetatable ( attr_table , { __index = { xmlns = t.namespace[currentindex] } } ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
204 | return attr_table [ attr ] |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
205 | end } ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
206 | end; |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
207 | str = function ( t , k ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
208 | return tostring ( t.opentag ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
209 | end; |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
210 | namespace = resolve_namespace ; |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
211 | } |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
212 | |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
213 | local stanza_mt = { |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
214 | __index = function ( t , k ) |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
215 | local f = dynamic_properties [ k ] |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
216 | if f then |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
217 | local v = f ( t ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
218 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
219 | rawset ( t , k , v ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
220 | return v |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
221 | else |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
222 | return stanza_methods[k] |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
223 | end |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
224 | end ; |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
225 | |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
226 | __tostring = function ( t ) |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
227 | if t.modified then |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
228 | return stanza_methods.__tostring ( t ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
229 | end |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
230 | local opentag = t.opentag |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
231 | local endtag = assert ( rawget ( t , "endtag" ) or rawget ( t , "selfclosing" ) and t.opentag ) |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
232 | return getstring ( opentag.msgs , opentag.start , endtag.finish ) |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
233 | end ; |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
234 | |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
235 | __newindex = function ( t , k , v ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
236 | rawset ( t , "modified", true ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
237 | rawset ( t , k , v ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
238 | end ; |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
239 | } |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
240 | |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
241 | local function new_stanza ( parent ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
242 | return setmetatable ( { tags = { } , parent = parent } , stanza_mt ) |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
243 | end |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
244 | |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
245 | local function tagindex_to_tree(indices, start, finish,root) |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
246 | if not start then |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
247 | start = 1 |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
248 | finish = #indices |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
249 | end |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
250 | |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
251 | root = root or { attr = { } } |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
252 | root.namespace = resolve_attr_namespaces ( root.attr ) |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
253 | root.root = true |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
254 | root.tags = { } |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
255 | local leaf = root |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
256 | |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
257 | for i = start , finish do |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
258 | local v = indices [ i ] |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
259 | |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
260 | if v.type == "selfclosing" then |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
261 | local newleaf = new_stanza ( leaf ) |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
262 | newleaf.opentag = v |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
263 | newleaf.selfclosing = true |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
264 | |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
265 | tblinsert ( leaf , newleaf ) |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
266 | tblinsert ( leaf.tags , newleaf ) |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
267 | elseif v.type == "close" then -- Close tag |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
268 | leaf.endtag = v |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
269 | leaf = leaf.parent |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
270 | elseif v.type == "text" then |
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
271 | tblinsert ( leaf, v ) |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
272 | else -- Open tag |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
273 | local newleaf = new_stanza ( leaf ) |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
274 | newleaf.opentag = v |
3992
de77ec2b49bc
All correcthg diff util/xmppstream.lua
Matthew Wild <mwild1@gmail.com>
parents:
3991
diff
changeset
|
275 | |
3991
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
276 | tblinsert ( leaf , newleaf ) |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
277 | tblinsert ( leaf.tags , newleaf ) |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
278 | |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
279 | leaf = newleaf |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
280 | end |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
281 | end |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
282 | |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
283 | assert ( leaf == root , "Mismatched opening/closing tags" ) |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
284 | return root; |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
285 | end |
7a2856c8ab7a
Tree structure now similar to prosody stanza format
Daurnimator <quae@daurnimator.com>
parents:
3990
diff
changeset
|
286 | |
3990 | 287 | return { |
3995
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
288 | index = index ; |
7214dc7a5642
util.xmppstream, util.xmllex: Basic test passes
Daurnimator <quae@daurnimator.com>
parents:
3992
diff
changeset
|
289 | tagindex_to_tree = tagindex_to_tree ; |
4002
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
290 | get_name = get_name ; |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
291 | get_attr = get_attr ; |
2b53b4b5d46e
util.xmllex, util.xmppstream: It runs
daurnimator <quae@daurnimator.com>
parents:
3995
diff
changeset
|
292 | resolve_attr_namespaces = resolve_attr_namespaces ; |
3990 | 293 | }; |