• 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

84.69
/inputters/sil.lua
1
local base = require("inputters.base")
41✔
2

3
local _variant = "epnf"
41✔
4
local parser
5
local function load_parser ()
6
   parser = require("inputters.sil-" .. _variant)
34✔
7
end
8

9
local inputter = pl.class(base)
41✔
10
inputter._name = "sil"
41✔
11

12
inputter.order = 50
41✔
13

14
inputter.appropriate = function (round, filename, doc)
15
   if not parser then
34✔
16
      load_parser()
34✔
17
   end
18
   if round == 1 then
34✔
19
      return filename:match(".sil$")
34✔
20
   elseif round == 2 then
×
21
      local sniff = doc:sub(1, 100)
×
22
      local promising = sniff:match("\\begin") or sniff:match("\\document") or sniff:match("\\sile")
×
23
      return promising and inputter.appropriate(3, filename, doc) or false
×
24
   elseif round == 3 then
×
25
      local status, _ = pcall(parser, doc)
×
26
      return status
×
27
   end
28
end
29

30
function inputter:_init (options)
41✔
31
   options = options or {}
34✔
32
   if options.variant then
34✔
33
      _variant = options.variant
×
34
      load_parser()
×
35
   else
36
      if not parser then
34✔
37
         load_parser()
×
38
      end
39
   end
40
   -- Save time when parsing strings by only setting up the grammar once per
41
   -- instantiation then re-using it on every use.
42
   self._parser = parser
34✔
43
   base._init(self)
34✔
44
end
45

46
local linecache = {}
41✔
47
local lno, col, lastpos
48
local function resetCache ()
49
   lno = 1
34✔
50
   col = 1
34✔
51
   lastpos = 0
34✔
52
   linecache = { { lno = 1, pos = 1 } }
34✔
53
end
54

55
local function getline (str, pos)
56
   local start = 1
1,078✔
57
   lno = 1
1,078✔
58
   if pos > lastpos then
1,078✔
59
      lno = linecache[#linecache].lno
998✔
60
      start = linecache[#linecache].pos + 1
998✔
61
      col = 1
998✔
62
   else
63
      for j = 1, #linecache - 1 do
1,152✔
64
         if linecache[j + 1].pos >= pos then
1,152✔
65
            lno = linecache[j].lno
80✔
66
            col = pos - linecache[j].pos
80✔
67
            return lno, col
80✔
68
         end
69
      end
70
   end
71
   for i = start, pos do
31,575✔
72
      if string.sub(str, i, i) == "\n" then
61,154✔
73
         lno = lno + 1
750✔
74
         col = 1
750✔
75
         linecache[#linecache + 1] = { pos = i, lno = lno }
750✔
76
         lastpos = i
750✔
77
      end
78
      col = col + 1
30,577✔
79
   end
80
   return lno, col
998✔
81
end
82

83
local function massage_ast (tree, doc)
84
   if type(tree) == "string" then
1,512✔
85
      return tree
21✔
86
   end
87
   if tree.pos then
1,491✔
88
      tree.lno, tree.col = getline(doc, tree.pos)
2,156✔
89
      tree.pos = nil
1,078✔
90
   end
91
   SU.debug("inputter", "Processing ID:", tree.id)
1,491✔
92
   if false or tree.id == "comment" then
1,491✔
93
      SU.debug("inputter", "Discarding comment:", pl.stringx.strip(tree[1]))
72✔
94
      return {}
36✔
95
   elseif
×
96
      false
97
      or tree.id == "document"
1,455✔
98
      or tree.id == "braced_content"
1,455✔
99
      or tree.id == "passthrough_content"
1,403✔
100
      or tree.id == "braced_passthrough_content"
1,382✔
101
      or tree.id == "env_passthrough_content"
1,382✔
102
   then
103
      SU.debug("inputter", "Re-massage subtree", tree.id)
89✔
104
      return massage_ast(tree[1], doc)
89✔
105
   elseif
×
106
      false
107
      or tree.id == "text"
1,366✔
108
      or tree.id == "passthrough_text"
945✔
109
      or tree.id == "braced_passthrough_text"
945✔
110
      or tree.id == "env_passthrough_text"
924✔
111
   then
112
      SU.debug("inputter", "  - Collapse subtree")
458✔
113
      return tree[1]
458✔
114
   elseif false or tree.id == "content" or tree.id == "environment" or tree.id == "command" then
908✔
115
      SU.debug("inputter", "  - Massage in place", tree.id)
908✔
116
      for key, val in ipairs(tree) do
2,804✔
117
         SU.debug("inputter", "    -", val.id)
1,896✔
118
         if val.id == "content" then
1,896✔
119
            SU.splice(tree, key, key, massage_ast(val, doc))
282✔
120
         elseif val.id then -- requiring an id discards nodes with no content such as comments
1,802✔
121
            tree[key] = massage_ast(val, doc)
2,590✔
122
         end
123
      end
124
      return tree
908✔
125
   end
126
end
127

128
function inputter:parse (doc)
41✔
129
   local status, result = pcall(self._parser, doc)
34✔
130
   if not status then
34✔
131
      return SU.error(([[Unable to parse input document to an AST tree. Parser error:
×
132

133
%s  thrown from document beginning]]):format(pl.stringx.indent(result, 6)))
×
134
   end
135
   resetCache()
34✔
136
   local top = massage_ast(result[1], doc)
34✔
137
   local tree
138
   -- Content not part of a tagged command could either be part of a document
139
   -- fragment or junk (e.g. comments, whitespace) outside of a document tag. We
140
   -- need to either capture the document tag only or decide this is a fragment
141
   -- and wrap it in a document tag.
142
   for _, leaf in ipairs(top) do
34✔
143
      if leaf.command and (leaf.command == "document" or leaf.command == "sile") then
34✔
144
         tree = leaf
34✔
145
         break
34✔
146
      end
147
   end
148
   -- In the event we didn't isolate a top level document tag above, assume this
149
   -- is a fragment and wrap it in one.
150
   if not tree then
34✔
151
      tree = { top, command = "document" }
×
152
   end
153
   -- SU.dump(tree)
154
   return { tree }
34✔
155
end
156

157
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