• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 15507594683

07 Jun 2025 11:54AM UTC coverage: 30.951% (-30.4%) from 61.309%
15507594683

push

github

alerque
chore(tooling): Add post-checkout hook to clear makedeps on branch switch

6363 of 20558 relevant lines covered (30.95%)

3445.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.22
/core/process.lua
1
local function process (ast)
2
   if not ast then
211✔
3
      return
×
4
   end
5
   if SU.debugging("ast") then
422✔
6
      SU.debugAST(ast, 0)
×
7
   end
8
   if type(ast) == "function" then
211✔
9
      return ast()
24✔
10
   end
11
   for _, content in ipairs(ast) do
1,272✔
12
      if type(content) == "string" then
1,085✔
13
         SILE.typesetter:typeset(content)
1,208✔
14
      elseif type(content) == "function" then
481✔
15
         content()
×
16
      elseif SILE.commands:exists(content.command) then
1,443✔
17
         SILE.commands:call(content.command, content.options, content)
1,443✔
18
      elseif not content.command and not content.id then
×
19
         local pId = SILE.traceStack:pushContent(content, "content")
×
20
         SILE.process(content)
×
21
         SILE.traceStack:pop(pId)
×
22
      elseif type(content) ~= "nil" then
×
23
         local pId = SILE.traceStack:pushContent(content)
×
24
         SU.error("Unknown command " .. (tostring(content.command or content.id)))
×
25
         SILE.traceStack:pop(pId)
×
26
      end
27
   end
28
end
29

30
local preloadedinputters = { "xml", "lua", "sil" }
107✔
31

32
local function detectFormat (doc, filename)
33
   -- Preload default reader types so content detection has something to work with
34
   if #SILE.inputters == 0 then
53✔
35
      for _, format in ipairs(preloadedinputters) do
212✔
36
         local _ = SILE.inputters[format]
159✔
37
      end
38
   end
39
   local contentDetectionOrder = {}
53✔
40
   for _, inputter in pairs(SILE.inputters) do
212✔
41
      if inputter.order then
159✔
42
         table.insert(contentDetectionOrder, inputter)
159✔
43
      end
44
   end
45
   table.sort(contentDetectionOrder, function (a, b)
106✔
46
      return a.order < b.order
140✔
47
   end)
48
   local initialround = filename and 1 or 2
53✔
49
   for round = initialround, 3 do
53✔
50
      for _, inputter in ipairs(contentDetectionOrder) do
99✔
51
         SU.debug("inputter", "Running content type detection round", round, "with", inputter._name)
99✔
52
         if inputter.appropriate(round, filename, doc) then
198✔
53
            return inputter._name
53✔
54
         end
55
      end
56
   end
57
   SU.error(("Unable to pick inputter to process input from '%s'"):format(filename))
×
58
end
59

60
local function processString (doc, format, filename, options)
61
   local cpf
62
   if not filename then
72✔
63
      cpf = SILE.currentlyProcessingFile
19✔
64
      local caller = debug.getinfo(2, "Sl")
19✔
65
      SILE.currentlyProcessingFile = caller.short_src .. ":" .. caller.currentline
19✔
66
   end
67
   -- In the event we're processing the master file *and* the user gave us
68
   -- a specific inputter to use, use it at the exclusion of all content type
69
   -- detection
70
   local inputter
71
   if
72
      filename
73
      and pl.path.normcase(pl.path.normpath(filename)) == pl.path.normcase(SILE.input.filenames[1])
231✔
74
      and SILE.inputter
53✔
75
   then
76
      inputter = SILE.inputter
×
77
   else
78
      format = format or detectFormat(doc, filename)
125✔
79
      if not SILE.quiet then
72✔
80
         io.stderr:write(("<%s> as %s\n"):format(SILE.currentlyProcessingFile, format))
72✔
81
      end
82
      inputter = SILE.inputters[format](options)
144✔
83
      -- If we did content detection *and* this is the master file, save the
84
      -- inputter for posterity and postambles
85
      if filename and pl.path.normcase(filename) == pl.path.normcase(SILE.input.filenames[1]:gsub("^-$", "STDIN")) then
178✔
86
         SILE.inputter = inputter
53✔
87
      end
88
   end
89
   local pId = SILE.traceStack:pushDocument(SILE.currentlyProcessingFile, doc)
72✔
90
   inputter:process(doc)
72✔
91
   SILE.traceStack:pop(pId)
72✔
92
   if cpf then
72✔
93
      SILE.currentlyProcessingFile = cpf
19✔
94
   end
95
end
96

97
local function processFile (filename, format, options)
98
   local lfs = require("lfs")
53✔
99
   local doc
100
   if filename == "-" then
53✔
101
      filename = "STDIN"
×
102
      doc = io.stdin:read("*a")
×
103
   else
104
      -- Turn slashes around in the event we get passed a path from a Windows shell
105
      filename = filename:gsub("\\", "/")
53✔
106
      if not SILE.masterFilename then
53✔
107
         SILE.masterFilename = pl.path.splitext(pl.path.normpath(filename))
212✔
108
      end
109
      if SILE.input.filenames[1] and not SILE.masterDir then
53✔
110
         SILE.masterDir = pl.path.dirname(SILE.input.filenames[1])
106✔
111
      end
112
      if SILE.masterDir and SILE.masterDir:len() >= 1 then
106✔
113
         _G.extendSilePath(SILE.masterDir)
53✔
114
         _G.extendSilePathRocks(SILE.masterDir .. "/lua_modules")
53✔
115
      end
116
      filename = SILE.resolveFile(filename) or SU.error("Could not find file '" .. filename .. "'")
106✔
117
      local mode = lfs.attributes(filename).mode
53✔
118
      if mode ~= "file" and mode ~= "named pipe" then
53✔
119
         SU.error(filename .. " isn't a file or named pipe, it's a " .. mode .. "!")
×
120
      end
121
      if SILE.makeDeps then
53✔
122
         SILE.makeDeps:add(filename)
53✔
123
      end
124
      local file, err = io.open(filename)
53✔
125
      if not file then
53✔
126
         print("Could not open " .. filename .. ": " .. err)
×
127
         return
×
128
      end
129
      doc = file:read("*a")
53✔
130
   end
131
   local cpf = SILE.currentlyProcessingFile
53✔
132
   SILE.currentlyProcessingFile = filename
53✔
133
   local pId = SILE.traceStack:pushDocument(filename, doc)
53✔
134
   local ret = SILE.processString(doc, format, filename, options)
53✔
135
   SILE.traceStack:pop(pId)
53✔
136
   SILE.currentlyProcessingFile = cpf
53✔
137
   return ret
53✔
138
end
139

140
return {
107✔
141
   process = process,
107✔
142
   processString = processString,
107✔
143
   processFile = processFile,
107✔
144
}
107✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc