tools/erlparse.lua

Tue, 21 Jul 2009 19:23:03 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 21 Jul 2009 19:23:03 +0100
changeset 1571
063d7be32fdd
parent 1523
841d61be198f
child 1572
1b87dfb76caa
permissions
-rw-r--r--

ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)

1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 894
diff changeset
1 -- Prosody IM
760
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
90ce865eebd8 Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents: 759
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 489
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 489
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 489
diff changeset
8
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 489
diff changeset
9
1571
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
10
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
11 local file = nil;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
12 local last = nil;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
13 local function read(expected)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
14 local ch;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
15 if last then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
16 ch = last; last = nil;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
17 else ch = file:read(1); end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
18 if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil")); end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
19 return ch;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
20 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
21 local function pushback(ch)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
22 if last then error(); end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
23 last = ch;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
24 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
25 local function peek()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
26 if not last then last = read(); end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
27 return last;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
28 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
29
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
30 local _A, _a, _Z, _z, _0, _9, __, _space = string.byte("AaZz09_ ", 1, 8);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
31 local function isAlpha(ch)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
32 ch = string.byte(ch) or 0;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
33 return (ch >= _A and ch <= _Z) or (ch >= _a and ch <= _z);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
34 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
35 local function isNumeric(ch)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
36 ch = string.byte(ch) or 0;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
37 return (ch >= _0 and ch <= _9);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
38 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
39 local function isVar(ch)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
40 ch = string.byte(ch) or 0;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
41 return (ch >= _A and ch <= _Z) or (ch >= _a and ch <= _z) or (ch >= _0 and ch <= _9) or ch == __;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
42 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
43 local function isSpace(ch)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
44 ch = string.byte(ch) or "x";
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
45 return ch <= _space;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
46 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
47
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
48 local function readString()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
49 read("\""); -- skip quote
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
50 local slash = nil;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
51 local str = "";
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
52 while true do
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
53 local ch = read();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
54 if ch == "\"" and not slash then break; end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
55 str = str..ch;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
56 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
57 str = str:gsub("\\.", {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"});
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
58 return str;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
59 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
60 local function readSpecialString()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
61 read("<"); read("<"); -- read <<
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
62 local str = "";
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
63 if peek() == "\"" then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
64 str = readString();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
65 elseif peek() ~= ">" then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
66 error();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
67 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
68 read(">"); read(">"); -- read >>
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
69 return str;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
70 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
71 local function readVar()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
72 local var = read();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
73 while isVar(peek()) do
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
74 var = var..read();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
75 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
76 return var;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
77 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
78 local function readNumber()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
79 local num = read();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
80 while isNumeric(peek()) do
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
81 num = num..read();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
82 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
83 return tonumber(num);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
84 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
85 local readItem = nil;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
86 local function readTuple()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
87 local t = {};
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
88 read(); -- read { or [
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
89 while true do
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
90 local item = readItem();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
91 if not item then break; end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
92 table.insert(t, item);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
93 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
94 read(); -- read } or ]
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
95 return t;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
96 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
97 readItem = function()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
98 local ch = peek();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
99 if ch == nil then return nil end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
100 if ch == "{" or ch == "[" then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
101 return readTuple();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
102 elseif isAlpha(ch) then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
103 return readVar();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
104 elseif isNumeric(ch) then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
105 return readNumber();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
106 elseif ch == "\"" then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
107 return readString();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
108 elseif ch == "<" then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
109 return readSpecialString();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
110 elseif isSpace(ch) or ch == "," or ch == "|" then
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
111 read();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
112 return readItem();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
113 else
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
114 --print("Unknown char: "..ch);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
115 return nil;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
116 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
117 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
118 local function readChunk()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
119 local x = readItem();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
120 if x then read("."); end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
121 return x;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
122 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
123 local function readFile(filename)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
124 file = io.open(filename);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
125 if not file then error("File not found: "..filename); os.exit(0); end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
126 return function()
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
127 local x = readChunk();
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
128 if not x and peek() then error("Invalid char: "..peek()); end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
129 return x;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
130 end;
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
131 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
132
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
133 module "erlparse"
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
134
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
135 function parseFile(file)
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
136 return readFile(file);
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
137 end
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
138
063d7be32fdd ejabberd2prosody, erlparse.lua: Convert from Windows line endings (thanks teo)
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
139 return _M;

mercurial