Mostly language stuff

This commit is contained in:
Marcel Fabian Krüger 2021-11-20 15:39:43 +01:00
parent d693023ebd
commit 8494bde0a5
4 changed files with 72 additions and 2 deletions

View File

@ -14,6 +14,10 @@ font.fonts = all_fonts
function font.getfont(id)
return all_fonts[id]
end
-- Currently either nil or true, false (defined but not yet frozen) isn't implemented right now
function font.frozen(id)
return all_fonts[id] and true
end
local fontextensions = {
ttf = "truetype",

View File

@ -2,10 +2,14 @@
% See baseregisters for list of toks pdfvariables
\directlua{initialize_pdf_toks()}
% We hardcode the ids of two catcodetables. If they ever change in the format, abort.
\if 0\ifnum1=\catcodetable@initex\else\expandafter1\fi\ifnum2=\catcodetable@string\else\expandafter1\fi 0\else
\if 0\ifnum1=\catcodetable@initex\else1\fi\ifnum2=\catcodetable@string\else1\fi 0\else
\errmessage{Inconsistent catcodetable identifiers}
\fi
\ifx\@tfor\undefined
\def\@tfor#1\do#2{}
\fi
\expanded {\def \noexpand \newlanguage #1\expandafter}\expandafter {%
\newlanguage{#1}%
\directlua{language.new(tex.count.allocationnumber)}%
}%
\input expl3.ltx

View File

@ -75,3 +75,50 @@ rewrite(token)
('set_lua', 'setlua')
('set_macro', 'setmacro')
('set_char', 'setchar')
('is_defined', 'isdefined')
do
lang = {}
for k,v in next, language do
lang[k] = v
end
local patterns = language.patterns
function lang.patterns(l, patt)
if not patt then
return patterns(l)
end
patt = patt:gsub('%s', ' ')
return patterns(l, patt)
end
end
do
local l = lpeg or require'lpeg'
local match = l.match
local P = l.P
local C = l.C
local sub = string.sub
local any = C(P(1)^0)
local char = C(1)
function string.explode(s, delim)
delim = delim or ' +'
if s == '' then
return {s}
else
local patt
if delim == '' then -- Split into individual characters
patt = char
else
local del = P(sub(delim, 1, 1))
if sub(delim, 2, 2) == '+' then
local elem = C((1-del)^1)
patt = del^0 * elem * (del^1 * elem)^0
else
local elem = C((1-del)^0)
patt = elem * (del * elem)^0
end
end
return {match(patt, s)}
end
end
end

View File

@ -17,5 +17,20 @@
\endgroup
\input load-unicode-data.tex
\input etex.src
\directlua{initialize_pdf_toks()}
\directlua{initialize_pdf_toks()}%
%
\expanded {\def \noexpand \newlanguage #1\expandafter}\expandafter {%
\newlanguage{#1}%
\directlua{language.new(tex.count.allocationnumber)}%
}%
%
\expanded {\def \noexpand \uselanguage #1\expandafter}\expandafter {%
\expanded {%
\noexpand \ifcsname lang@#1\endcsname
\noexpand \directlua {lang.new(\noexpand\number\noexpand\lastnamedcs)}%
\noexpand \fi
\expandafter
}%
\uselanguage{#1}%
}%
\dump