Annotate

fallbacks/lxp.lua @ 3767:3ba97d1d7a62

prosody.cfg.lua.dist: Update to reflect new mod_admin_* modules
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Dec 2010 17:11:04 +0000
parent 3681:3dbdcc79bd66
child 3899:eff0c5fe9119
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3681
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
1
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
2 local coroutine = coroutine;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
3 local tonumber = tonumber;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
4 local string = string;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
5 local setmetatable, getmetatable = setmetatable, getmetatable;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
6 local pairs = pairs;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
7
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
8 local deadroutine = coroutine.create(function() end);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
9 coroutine.resume(deadroutine);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
10
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
11 module("lxp")
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
12
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
13 local entity_map = setmetatable({
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
14 ["amp"] = "&";
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
15 ["gt"] = ">";
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
16 ["lt"] = "<";
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
17 ["apos"] = "'";
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
18 ["quot"] = "\"";
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
19 }, {__index = function(_, s)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
20 if s:sub(1,1) == "#" then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
21 if s:sub(2,2) == "x" then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
22 return string.char(tonumber(s:sub(3), 16));
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
23 else
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
24 return string.char(tonumber(s:sub(2)));
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
25 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
26 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
27 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
28 });
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
29 local function xml_unescape(str)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
30 return (str:gsub("&(.-);", entity_map));
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
31 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
32 local function parse_tag(s)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
33 local name,sattr=(s):gmatch("([^%s]+)(.*)")();
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
34 local attr = {};
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
35 for a,b in (sattr):gmatch("([^=%s]+)=['\"]([^'\"]*)['\"]") do attr[a] = xml_unescape(b); end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
36 return name, attr;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
37 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
38
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
39 local function parser(data, handlers, ns_separator)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
40 local function read_until(str)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
41 local pos = data:find(str, nil, true);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
42 while not pos do
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
43 data = data..coroutine.yield();
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
44 pos = data:find(str, nil, true);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
45 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
46 local r = data:sub(1, pos);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
47 data = data:sub(pos+1);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
48 return r;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
49 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
50 local function read_before(str)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
51 local pos = data:find(str, nil, true);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
52 while not pos do
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
53 data = data..coroutine.yield();
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
54 pos = data:find(str, nil, true);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
55 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
56 local r = data:sub(1, pos-1);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
57 data = data:sub(pos);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
58 return r;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
59 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
60 local function peek()
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
61 while #data == 0 do data = coroutine.yield(); end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
62 return data:sub(1,1);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
63 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
64
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
65 local ns = { xml = "http://www.w3.org/XML/1998/namespace" };
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
66 ns.__index = ns;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
67 local function apply_ns(name, dodefault)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
68 local prefix,n = name:match("^([^:]*):(.*)$");
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
69 if prefix and ns[prefix] then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
70 return ns[prefix]..ns_separator..n;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
71 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
72 if dodefault and ns[""] then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
73 return ns[""]..ns_separator..name;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
74 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
75 return name;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
76 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
77 local function push(tag, attr)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
78 ns = setmetatable({}, ns);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
79 for k,v in pairs(attr) do
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
80 local xmlns = k == "xmlns" and "" or k:match("^xmlns:(.*)$");
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
81 if xmlns then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
82 ns[xmlns] = v;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
83 attr[k] = nil;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
84 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
85 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
86 local newattr, n = {}, 0;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
87 for k,v in pairs(attr) do
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
88 n = n+1;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
89 k = apply_ns(k);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
90 newattr[n] = k;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
91 newattr[k] = v;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
92 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
93 tag = apply_ns(tag, true);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
94 ns[0] = tag;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
95 ns.__index = ns;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
96 return tag, newattr;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
97 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
98 local function pop()
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
99 local tag = ns[0];
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
100 ns = getmetatable(ns);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
101 return tag;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
102 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
103
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
104 while true do
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
105 if peek() == "<" then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
106 local elem = read_until(">"):sub(2,-2);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
107 if elem:sub(1,1) == "!" or elem:sub(1,1) == "?" then -- neglect comments and processing-instructions
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
108 elseif elem:sub(1,1) == "/" then -- end tag
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
109 elem = elem:sub(2);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
110 local name = pop();
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
111 handlers:EndElement(name); -- TODO check for start-end tag name match
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
112 elseif elem:sub(-1,-1) == "/" then -- empty tag
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
113 elem = elem:sub(1,-2);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
114 local name,attr = parse_tag(elem);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
115 name,attr = push(name,attr);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
116 handlers:StartElement(name,attr);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
117 name = pop();
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
118 handlers:EndElement(name);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
119 else -- start tag
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
120 local name,attr = parse_tag(elem);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
121 name,attr = push(name,attr);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
122 handlers:StartElement(name,attr);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
123 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
124 else
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
125 local text = read_before("<");
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
126 handlers:CharacterData(xml_unescape(text));
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
127 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
128 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
129 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
130
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
131 function new(handlers, ns_separator)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
132 local co = coroutine.create(parser);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
133 return {
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
134 parse = function(self, data)
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
135 if not data then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
136 co = deadroutine;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
137 return true; -- eof
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
138 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
139 local success, result = coroutine.resume(co, data, handlers, ns_separator);
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
140 if result then
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
141 co = deadroutine;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
142 return nil, result; -- error
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
143 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
144 return true; -- success
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
145 end;
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
146 };
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
147 end
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
148
3dbdcc79bd66 fallbacks/lxp.lua: CRLF -> LF.
Waqas Hussain <waqas20@gmail.com>
parents: 3680
diff changeset
149 return _M;