summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-12-14 01:21:29 +0100
committerAki <please@ignore.pl>2023-12-14 01:21:29 +0100
commit4d3eabb6098be217f7dee0015f708d9264b69243 (patch)
treefac01fe3bbdc681d9c423ae25c62708c6bfb69bd
parenta4393a3daf42b2da2f337f3314c35caf5a699f2c (diff)
downloadlua-srcinfo-4d3eabb6098be217f7dee0015f708d9264b69243.zip
lua-srcinfo-4d3eabb6098be217f7dee0015f708d9264b69243.tar.gz
lua-srcinfo-4d3eabb6098be217f7dee0015f708d9264b69243.tar.bz2
Lossened assumed requirements regarding format, added comments, newlines
-rw-r--r--srcinfo.lua15
1 files changed, 8 insertions, 7 deletions
diff --git a/srcinfo.lua b/srcinfo.lua
index bc1900c..2612fd4 100644
--- a/srcinfo.lua
+++ b/srcinfo.lua
@@ -1,13 +1,14 @@
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"^1
-local rest = (1 - lpeg.S"\n")^0
-local definition = lpeg.C(identifier) * whitespace * "=" * whitespace * lpeg.C(rest) * "\n"
-local subdefinition = whitespace * definition
-local emptylines = (whitespace * "\n")^1
-local block = lpeg.Ct(lpeg.Ct(definition) * lpeg.Ct(subdefinition)^0)
-local thing = block * (emptylines * block)^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
local capture = lpeg.Ct(thing)