Skip to content

Commit

Permalink
Merge pull request #13 from atticus-sullivan/chore-teal
Browse files Browse the repository at this point in the history
Chore teal 0.24

Update so that teal 0.24 can be used.
  • Loading branch information
atticus-sullivan authored Dec 11, 2024
2 parents 216e8ea + 6723442 commit 7790cc5
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ jobs:
- name: Install lua
uses: jkl1337/gh-actions-lua@v11
with:
luaVersion: "5.4.6"
luaVersion: "5.4.7"
- name: Install LuaRocks (latest)
uses: jkl1337/gh-actions-luarocks@v5

- name: install luarocks deps
run: |
luarocks install --dev tl
luarocks install cyan
- name: make
run: make FD=fdfind build doc
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: install luarocks deps
run: |
luarocks install --dev tl
luarocks install cyan
- name: make
run: make FD=fdfind build doc
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
.PHONY: all checkAll doc install build
.PHONY: all checkAll doc install build clean

FD ?= fd

all: build doc install

build: checkAll
eval $$(luarocks path) && tl build
@cyan version
mkdir -p src_lua/texrunner
cd src_teal && $(FD) "\.lua" . --exec cp {} ../src_lua/{}
@cyan version
eval $$(luarocks path) && cyan build
sed -i '1s;^;#!/usr/bin/env texlua\n;' src_lua/cluttealtex.lua
cp src_teal/texrunner/*lua src_lua/texrunner/
cp src_teal/os_.lua src_lua/
make -f Makefile.cluttealtex

clean:
$(RM) -r src_lua

doc:
l3build doc

install: build
l3build install --full

checkAll:
eval $$(luarocks path) && tl check $$($(FD) "\.tl" ./src_teal)
eval $$(luarocks path) && cyan check $$($(FD) "\.tl" ./src_teal)
18 changes: 9 additions & 9 deletions src_teal/cluttealtex.tl
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ local function single_run(auxstatus:{string:reruncheck.Status}, iteration:intege
local updated_dot_bib = false
-- get the .bib files, the bcf uses as input
for l in io.lines(file.abspath) do
local bib = l:match("<bcf:datasource .*>(.*)</bcf:datasource>") -- might be unstable if biblatex adds e.g. a linebreak
local bib = string.match(l, "<bcf:datasource .*>(.*)</bcf:datasource>") -- might be unstable if biblatex adds e.g. a linebreak
if bib then
local bibfile = pathutil.join(original_wd, bib)
local succ, err = io.open(bibfile, "r") -- check if file is present, don't use touch to avoid triggering a rerun
Expand Down Expand Up @@ -474,7 +474,7 @@ local function single_run(auxstatus:{string:reruncheck.Status}, iteration:intege
local memoizefileinfo = {path = file.path, abspath = file.abspath, kind = "auxiliary"}
local must_extract = false
for l in io.lines(file.abspath) do
local newExtern = l:match("^\\mmzNewExtern")
local newExtern = string.match(l, "^\\mmzNewExtern")
must_extract = must_extract or newExtern ~= nil
end
if must_extract then
Expand Down Expand Up @@ -540,7 +540,7 @@ end

-- Run (La)TeX (possibly multiple times) and produce a PDF file.
-- This function should be run in a coroutine.
local function do_typeset_c()
local function do_typeset_c(): string, function
local iteration = 0
local should_rerun, auxstatus: boolean|string, {string:reruncheck.Status}
repeat
Expand Down Expand Up @@ -623,7 +623,7 @@ local function do_typeset(): boolean, string, integer
if command is string and (recover is function or recover is nil) then
message.exec(command)
local success, termination, status_or_signal = os.execute(command)
if success ~= 0 and not (recover and recover()) then
if success ~= 0 and not (recover and (recover as function)()) then
if termination == "exit" then
message.error("Command exited abnormally: exit status ", tostring(status_or_signal))
elseif termination == "signal" then
Expand All @@ -634,7 +634,7 @@ local function do_typeset(): boolean, string, integer
return false, termination, status_or_signal
end
else
error(("invalid type. command: %s recover: %s"):format(type(command), type(recover)))
error(string.format("invalid type. command: %s recover: %s", type(command), type(recover)))
end
end
-- Successful
Expand Down Expand Up @@ -754,15 +754,15 @@ if options.watch then
watch = false
for _,v in ipairs(options.watch_inc_exc) do
if v.type == "only_path" then
if fileinfo.abspath:sub(1, #v.param) == v.param then
if string.sub(fileinfo.abspath, 1, #v.param) == v.param then
watch = true
end
elseif v.type == "only_ext" then
if pathutil.ext(fileinfo.abspath) == v.param then
watch = true
end
elseif v.type == "not_path" then
if fileinfo.abspath:sub(1, #v.param) == v.param then
if string.sub(fileinfo.abspath, 1, #v.param) == v.param then
watch = false
end
elseif v.type == "not_ext" then
Expand All @@ -781,11 +781,11 @@ if options.watch then
end
end
if max_watches >= 0 and #input_files_to_watch > max_watches then
message.warn((
message.warn(string.format(
"Collected %d input files to watch on. Typically only %d hooks are created." ..
"The hooks exceeding this limit typically will simply not being installed." ..
"Consider either to increase this limit (how/if possible depends on the watcher engine) or" ..
"make use of the --watch-{only,no}-{ext,path} options to restrict the files which CluttealTeX should watch."):format(
"make use of the --watch-{only,no}-{ext,path} options to restrict the files which CluttealTeX should watch.",
#input_files_to_watch, max_watches
))
end
Expand Down
2 changes: 1 addition & 1 deletion src_teal/lfs.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ local record lfs
symlinkattributes: function(string, string): string|number -- |FileMode
symlinkattributes: function(string, Attributes): Attributes

touch: function(string, number, number): boolean, string
touch: function(string, ?number, ?number): boolean, string

-- TODO: FILE needs to be renamed to io.FILE in tl itself
lock: function(FILE, LockMode, number, number): boolean, string
Expand Down
2 changes: 1 addition & 1 deletion src_teal/os_.d.tl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local record os_
-- year: integer) and function(string, number): string)
difftime: function(number, number): number
execute: function(string): integer, string, integer
exit: function(number | boolean, boolean)
exit: function(number | boolean, ?boolean)
getenv: function(string): string
remove: function(string): boolean, string
rename: function(string, string): boolean, string
Expand Down
4 changes: 2 additions & 2 deletions src_teal/texrunner/auxfile.tl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ made_new_directory: boolean
end

-- for LaTeX
local function parse_aux_file(auxfile:string, outdir:string, report:Report, seen:{string:boolean}): Report
local function parse_aux_file(auxfile:string, outdir:string, report?:Report, seen?:{string:boolean}): Report
report = report or {}
seen = seen or {}
seen[auxfile] = true
Expand All @@ -51,7 +51,7 @@ local function parse_aux_file(auxfile:string, outdir:string, report:Report, seen
end

-- \citation, \bibdata, \bibstyle and \@input
local function extract_bibtex_from_aux_file(auxfile:string, outdir:string, biblines:{string}): {string}
local function extract_bibtex_from_aux_file(auxfile:string, outdir:string, biblines?:{string}): {string}
biblines = biblines or {}
for l in io.lines(auxfile) do
local name = string_match(l, "\\([%a@]+)")
Expand Down
2 changes: 1 addition & 1 deletion src_teal/texrunner/fswatcher.tl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local record Module
path: string
end
record Watcher
add_file: function(Watcher, string)
add_file: function(Watcher, string): boolean, string
next: function(Watcher): Watcher_ele
close: function(Watcher)
-- TODO function definition
Expand Down
2 changes: 1 addition & 1 deletion src_teal/texrunner/handleoption.tl
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ local function handle_cluttealtex_options(arg:{string}): string,TexEngine.Engine

elseif name == "max-iterations" then
assert(options.max_iterations == nil, "multiple --max-iterations options")
options.max_iterations = assert(tonumber(param), "invalid value for --max-iterations option")
options.max_iterations = assert(tonumber(param) as integer, "invalid value for --max-iterations option")
assert(options.max_iterations >= 1, "invalid value for --max-iterations option")

elseif name == "skip-first" then
Expand Down
9 changes: 5 additions & 4 deletions src_teal/texrunner/pathutil_unix.tl
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,17 @@ local function joinpath2(x: string, y: string): string
end

local function joinpath(...: string): string
local args = {...}
local n = select("#", ...)
if n == 2 then
return joinpath2(...)
return joinpath2(args[1], args[2])
elseif n == 0 then
return "."
elseif n == 1 then
return ...
else
-- n is >= 3
return joinpath(joinpath2(...), select(3, ...))
-- n is >= 3
return joinpath(joinpath2(args[1], args[2]), select(3, ...))
end
end

Expand All @@ -189,7 +190,7 @@ assert(joinpath("/path/", "to", "somewhere", "..", "elsewhere") == "/path/to/els
assert(joinpath("/path/", "to", "./somewhere.txt") == "/path/to/somewhere.txt")
-- END TEST CODE

local function abspath(path: string, cwd: string): string
local function abspath(path: string, cwd?: string): string
if string_sub(path, 1, 1) == "/" then
-- absolute path
return path
Expand Down
9 changes: 5 additions & 4 deletions src_teal/texrunner/pathutil_windows.tl
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,17 @@ local function joinpath2(x: string, y: string): string
end

local function joinpath(...: string): string
local args = {...}
local n = select("#", ...)
if n == 2 then
return joinpath2(...)
return joinpath2(args[1], args[2])
elseif n == 0 then
return "."
elseif n == 1 then
return ...
else
-- n is >= 3
return joinpath(joinpath2(...), select(3, ...))
-- n is >= 3
return joinpath(joinpath2(args[1], args[2]), select(3, ...))
end
end

Expand All @@ -201,7 +202,7 @@ local function isabspath(path: string): boolean
return init == "\\" or init == "/" or string_match(path, "^%a:[/\\]") ~= nil
end

local function abspath(path: string, cwd: string): string
local function abspath(path: string, cwd?: string): string
if isabspath(path) then
-- absolute path
return path
Expand Down
4 changes: 2 additions & 2 deletions src_teal/texrunner/reruncheck.tl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local record Module
md5sum: string
end

parse_recorder_file: function(string, options.Options, {Module.Filemap_ele}, {string:Module.Filemap_ele}): {Module.Filemap_ele}, {string:Module.Filemap_ele}
parse_recorder_file: function(string, options.Options, ?{Module.Filemap_ele}, ?{string:Module.Filemap_ele}): {Module.Filemap_ele}, {string:Module.Filemap_ele}
collectfileinfo: function({Module.Filemap_ele}, {string:Module.Status}): {string:Module.Status}
comparefileinfo: function({Module.Filemap_ele}, {string:Module.Status}): boolean, {string:Module.Status}
comparefiletime: function(string, string, {string:Module.Status}): boolean
Expand All @@ -55,7 +55,7 @@ end

-- filelist, filemap = parse_recorder_file("jobname.fls", options [, filelist, filemap])
-- filelist[i] = {path = "...", abspath = "...", kind = "input" or "output" or "auxiliary"}
local function parse_recorder_file(file:string, options:options.Options, filelist:{Module.Filemap_ele}, filemap:{string:Module.Filemap_ele}): {Module.Filemap_ele}, {string:Module.Filemap_ele}
local function parse_recorder_file(file:string, options:options.Options, filelist?:{Module.Filemap_ele}, filemap?:{string:Module.Filemap_ele}): {Module.Filemap_ele}, {string:Module.Filemap_ele}
filelist = filelist or {}
filemap = filemap or {}
for l in io.lines(file) do
Expand Down
2 changes: 1 addition & 1 deletion src_teal/texrunner/safename.tl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local function dounsafechar(c:string):string
if c == " " then
return "_"
else
return string.format("_%02x", c:byte(1))
return string.format("_%02x", string.byte(c, 1))
end
end

Expand Down
9 changes: 3 additions & 6 deletions src_teal/texrunner/shellutil_unix.tl
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,21 @@ local os_execute = os.execute
local function escape(s: string): string
local len = #s
local result = {}
local t,_i = string_match(s, "^([^']*)()")
local t, i = string_match(s, "^([^']*)()") as (string, integer)
assert(t)
local i = tonumber(_i) -- TODO teal issue regarding string.match
if t ~= "" then
table_insert(result, "'")
table_insert(result, t)
table_insert(result, "'")
end
while i < len do
t,_i = string_match(s, "^('+)()", i)
t, i = string_match(s, "^('+)()", i) as (string, integer)
assert(t)
i = tonumber(_i) -- TODO teal issue regarding string.match
table_insert(result, '"')
table_insert(result, t)
table_insert(result, '"')
t,_i = string_match(s, "^([^']*)()", i)
t, i = string_match(s, "^([^']*)()", i) as (string, integer)
assert(t)
i = tonumber(_i) -- TODO teal issue regarding string.match
if t ~= "" then
table_insert(result, "'")
table_insert(result, t)
Expand Down
2 changes: 1 addition & 1 deletion src_teal/texrunner/tex_engine.tl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function meta:build_command(inputline:string, options:Module.Option): string
end

-- constructor
local function engine(name:string, supports_pdf_generation:boolean, handle_additional_options:function(self:Module.Engine, args:{string}, options:Module.Option)): Module.Engine
local function engine(name:string, supports_pdf_generation:boolean, handle_additional_options?:function(self:Module.Engine, args:{string}, options:Module.Option)): Module.Engine
return setmetatable({
name = name,
executable = name,
Expand Down

0 comments on commit 7790cc5

Please sign in to comment.