From 19d9ccbd7623926d23822445af25139faf433063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Fri, 12 Jun 2020 21:52:35 +0200 Subject: [PATCH] Workaround for remaining engine bug --- luametalatex-baseregisters.tex | 2 +- luametalatex-init.lua | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/luametalatex-baseregisters.tex b/luametalatex-baseregisters.tex index 2e704ff..67f6ada 100644 --- a/luametalatex-baseregisters.tex +++ b/luametalatex-baseregisters.tex @@ -1,5 +1,5 @@ \begingroup -\catcode`\^^^^ffff=11 +\catcode`\^^^^fffe=11 \catcode`\@=11 \toks0{% do diff --git a/luametalatex-init.lua b/luametalatex-init.lua index fad4b1c..f663e17 100644 --- a/luametalatex-init.lua +++ b/luametalatex-init.lua @@ -78,11 +78,29 @@ do end end callback_register('read_data_file', function(name) error[[TODO]]return kpse.find_file(name, 'tex', true) end) --- local file_meta = {\ +local input_pattern do + local hex = lpeg.R('09', 'af') + local hexx = hex * hex + local tonumber = tonumber + local char = utf8.char + local sub = string.sub + local char = lpeg.Cg('^^' * ( + ('^^' * ('^^' * hexx)^-1 * hexx)^-1 * hexx/function(s) + local cp = tonumber(sub(s, #s/2), 16) + return cp == 0 and '^^@' or char(cp) + end + -- + lpeg.R'\0\63' / function(s) return char(s:byte()+64) end + -- + lpeg.R'\63\127' / function(s) return char(s:byte()-64) end + )) + 1 + input_pattern = lpeg.Cs(char^0) +end callback_register('open_data_file', function(name) local f = io.open(name) return setmetatable({ - reader = function() return f:read() end, + reader = function() + local line = f:read() + return line and input_pattern:match(line) + end, close = function()error[[1]] return f:close() end, }, { __gc = function()f:close()end,