diff options
author | Aki <please@ignore.pl> | 2023-12-13 01:03:54 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-12-13 01:03:54 +0100 |
commit | a4393a3daf42b2da2f337f3314c35caf5a699f2c (patch) | |
tree | 77ca4564b42a1d24165a489d6939ee1288409976 | |
download | lua-srcinfo-a4393a3daf42b2da2f337f3314c35caf5a699f2c.zip lua-srcinfo-a4393a3daf42b2da2f337f3314c35caf5a699f2c.tar.gz lua-srcinfo-a4393a3daf42b2da2f337f3314c35caf5a699f2c.tar.bz2 |
Initialized repository with part from depstage
-rw-r--r-- | Makefile | 17 | ||||
-rw-r--r-- | srcinfo.lua | 20 |
2 files changed, 37 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..892082b --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +LUAVERSION?=5.4 +PREFIX?=/usr/local +DATADIR=$(PREFIX)/share +LUADIR=$(DATADIR)/lua/$(LUAVERSION) + +all: + +test: + busted + +install: + install -m644 -Dt $(DESTDIR)$(LUADIR) srcinfo.lua + +uninstall: + rm -f $(DESTDIR)$(LUADIR)/srcinfo.lua + +.PHONY: all test install uninstall diff --git a/srcinfo.lua b/srcinfo.lua new file mode 100644 index 0000000..bc1900c --- /dev/null +++ b/srcinfo.lua @@ -0,0 +1,20 @@ +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 capture = lpeg.Ct(thing) + + +local +function srcinfo (handle) + return capture:match(handle:read"a") +end + + +return srcinfo |