blob: 9982a9889b4b159b81cf44c82ea3945cff2f28e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
local lpeg = require "lpeg"
local identifier = lpeg.R"az" + lpeg.R"09" + lpeg.S"@+_"
identifier = identifier * (identifier + lpeg.S".-")^0
local whitespace = lpeg.S" \t"^0
local newline = lpeg.P"\r\n" + "\n"
local rest = (1 - newline)^0
local definition = whitespace * lpeg.C(identifier) * whitespace * "=" * whitespace * lpeg.C(rest) * newline
local emptylines = (whitespace * newline)^1
local comment = lpeg.P"#" * rest * newline
local block = lpeg.Ct((lpeg.Ct(definition) + comment)^1)
local thing = emptylines^0 * block * (emptylines * block)^0 * emptylines^0 * -lpeg.P(1)
local capture = lpeg.Ct(thing)
local
function srcinfo (handle)
return capture:match(handle:read"a")
end
return srcinfo
|