diff options
author | Hans Hagen <pragma@wxs.nl> | 2018-06-22 16:42:14 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2018-06-22 16:42:14 +0200 |
commit | da8162d4e816cf49d9790a1c81556b499f442bed (patch) | |
tree | 5c631b1fb8282670a6cea1087afa766a8b94db43 /scripts/context/lua/mtx-package.lua | |
parent | 204057fdc5023b5f4ff55a69bc6593388ea427e7 (diff) | |
download | context-da8162d4e816cf49d9790a1c81556b499f442bed.tar.gz |
2018-06-22 16:02:00
Diffstat (limited to 'scripts/context/lua/mtx-package.lua')
-rw-r--r-- | scripts/context/lua/mtx-package.lua | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/scripts/context/lua/mtx-package.lua b/scripts/context/lua/mtx-package.lua index c4487faec..6307e91e0 100644 --- a/scripts/context/lua/mtx-package.lua +++ b/scripts/context/lua/mtx-package.lua @@ -71,13 +71,19 @@ function scripts.package.merge_luatex_files(name) end collected = table.concat(collected) if environment.argument("stripcontext") then - local n = 0 - collected = string.gsub(collected,"\nif context then.-\nend",function(s) - n = n + #s - return "" - end) - if n > 0 then - report("%i context specific bytes stripped",n) + local stripped = 0 + local eol = lpeg.patterns.eol + local space = lpeg.patterns.space^0 + local start = eol * lpeg.P("if context then") * space * eol + local stop = eol * (lpeg.P("else") + lpeg.P("end")) * space * eol + local noppes = function() + stripped = striped + 1 + return "\n--removed\n" + end + local pattern = lpeg.Cs((start * ((1-stop)^1/noppes) * stop + lpeg.P(1))^0) + collected = lpeg.match(pattern,collected) + if stripped > 0 then + report("%i context specific sections stripped",stripped) end end report("saving %q (%i bytes)",newname,#collected) |