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

sile-typesetter / sile / 10728217744

05 Sep 2024 09:07PM UTC coverage: 58.013% (-4.5%) from 62.464%
10728217744

push

github

alerque
refactor(cli): Satiate clippy's new "never type fallback" lint

New in Rust 1.81.0, scheduled to be an error in edition 2024:

https://github.com/rust-lang/rust/issues/123748

It looks like mlua v0.10 won't need this workaround:

https://github.com/mlua-rs/mlua/commit/3641c9895

10103 of 17415 relevant lines covered (58.01%)

1419.94 hits per line

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

72.88
/inputters/xml.lua
1
local base = require("inputters.base")
41✔
2
local lxp = require("lxp")
41✔
3

4
local inputter = pl.class(base)
41✔
5
inputter._name = "xml"
41✔
6

7
inputter.order = 2
41✔
8

9
local function startcommand (parser, command, options)
10
   local stack = parser:getcallbacks().stack
698✔
11
   local lno, col, pos = parser:pos()
698✔
12
   local position = { lno = lno, col = col, pos = pos }
698✔
13
   -- create an empty command which content will be filled on closing tag
14
   local element = SU.ast.createCommand(command, options, nil, position)
698✔
15
   table.insert(stack, element)
698✔
16
end
17

18
local function endcommand (parser, command)
19
   local stack = parser:getcallbacks().stack
698✔
20
   local element = table.remove(stack)
698✔
21
   assert(element.command == command)
698✔
22
   local level = #stack
698✔
23
   table.insert(stack[level], element)
698✔
24
end
25

26
local function text (parser, msg)
27
   local stack = parser:getcallbacks().stack
1,055✔
28
   local element = stack[#stack]
1,055✔
29
   local n = #element
1,055✔
30
   if type(element[n]) == "string" then
1,055✔
31
      element[n] = element[n] .. msg
×
32
   else
33
      table.insert(element, msg)
1,055✔
34
   end
35
end
36

37
local function parse (doc)
38
   local content = {
7✔
39
      StartElement = startcommand,
7✔
40
      EndElement = endcommand,
7✔
41
      CharacterData = text,
7✔
42
      _nonstrict = true,
43
      stack = { {} },
7✔
44
   }
45
   local parser = lxp.new(content)
7✔
46
   local status, err
47
   if type(doc) == "string" then
7✔
48
      status, err = parser:parse(doc)
7✔
49
      if not status then
7✔
50
         return nil, err
×
51
      end
52
   else
53
      for element in pairs(doc) do
×
54
         status, err = parser:parse(element)
×
55
         if not status then
×
56
            return nil, err
×
57
         end
58
      end
59
   end
60
   status, err = parser:parse()
7✔
61
   if not status then
7✔
62
      return nil, err
×
63
   end
64
   parser:close()
7✔
65
   return content.stack[1][1]
7✔
66
end
67

68
function inputter.appropriate (round, filename, doc)
41✔
69
   if round == 1 then
41✔
70
      return filename:match(".xml$")
41✔
71
   elseif round == 2 then
×
72
      local sniff = doc:sub(1, 100):gsub("begin.*", "") or ""
×
73
      local promising = sniff:match("<")
×
74
      return promising and inputter.appropriate(3, filename, doc)
×
75
   elseif round == 3 then
×
76
      local _, err = parse(doc)
×
77
      return not err
×
78
   end
79
end
80

81
function inputter.parse (_, doc)
41✔
82
   local tree, err = parse(doc)
7✔
83
   if not tree then
7✔
84
      SU.error(err)
×
85
   end
86
   -- XML documents can have any root element, and it should be up to the class
87
   -- to supply handling far whatever that element that is in a specific format.
88
   -- Hence we wrap the actual DOM in an extra element of our own if and only if
89
   -- it doesn't look like a native SILE one already.
90
   local rootelement = tree.command
7✔
91
   if rootelement ~= "sile" and rootelement ~= "document" then
7✔
92
      tree = SU.ast.createCommand("document", {}, tree)
×
93
   end
94
   return { tree }
7✔
95
end
96

97
return inputter
41✔
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

© 2026 Coveralls, Inc