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

sile-typesetter / sile / 11645827362

02 Nov 2024 09:08PM UTC coverage: 54.19% (-15.2%) from 69.34%
11645827362

push

github

web-flow
Merge pull request #2151 from Omikhleia/math-more-fixes-and-features

Math more fixes and features

103 of 208 new or added lines in 4 files covered. (49.52%)

2652 existing lines in 91 files now uncovered.

9816 of 18114 relevant lines covered (54.19%)

671.83 hits per line

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

87.72
/core/parserbits.lua
1
local lpeg = require("lpeg")
35✔
2

3
local R, S, P, B = lpeg.R, lpeg.S, lpeg.P, lpeg.B
35✔
4
local C, Cf, Cg, Ct, Cmt = lpeg.C, lpeg.Cf, lpeg.Cg, lpeg.Ct, lpeg.Cmt
35✔
5

6
local function isaunit (_, _, unit)
7
   -- TODO: fix race condition so we can validate units
8
   local factory = rawget(SILE.types, "unit")
10,251✔
9
   if not SILE or not factory then
10,251✔
10
      return true
340✔
11
   end
12
   return factory[unit] and true or false
9,911✔
13
end
14

15
local function inferpoints (number)
UNCOV
16
   return { amount = number, unit = "pt" }
×
17
end
18

19
local function unwrapper (...)
20
   local tbl = { ... }
145✔
21
   return tbl[1], tbl[#tbl]
145✔
22
end
23

24
-- UTF-8 characters
25
-- decode a two-byte UTF-8 sequence
26
local function f2 (s)
27
   local c1, c2 = string.byte(s, 1, 2)
×
28
   return c1 * 64 + c2 - 12416
×
29
end
30
-- decode a three-byte UTF-8 sequence
31
local function f3 (s)
32
   local c1, c2, c3 = string.byte(s, 1, 3)
×
33
   return (c1 * 64 + c2) * 64 + c3 - 925824
×
34
end
35
-- decode a four-byte UTF-8 sequence
36
local function f4 (s)
37
   local c1, c2, c3, c4 = string.byte(s, 1, 4)
×
38
   return ((c1 * 64 + c2) * 64 + c3) * 64 + c4 - 63447168
×
39
end
40

41
-- stylua: ignore start
42
local cont = lpeg.R("\128\191")   -- continuation byte
35✔
43
local utf8char = lpeg.R("\0\127") / string.byte
35✔
44
   + lpeg.R("\194\223") * cont / f2
35✔
45
   + lpeg.R("\224\239") * cont * cont / f3
35✔
46
   + lpeg.R("\240\244") * cont * cont * cont / f4
35✔
47

48
local bits = {}
35✔
49

50
bits.digit = R"09"
35✔
51
bits.ws = S" \r\n\t\f\v"^0
35✔
52
bits.letter = R("az", "AZ") + P"_"
35✔
53
bits.identifier = (bits.letter + bits.digit)^1
35✔
54
local sign = S"+-"^-1
35✔
55
bits.integer = sign * bits.digit^1
35✔
56
local sep = P"."
35✔
57
bits.decimal = sign * (bits.digit^0 * sep)^-1 * bits.digit^1
35✔
58
bits.scientific = bits.decimal * S"Ee" * bits.integer
35✔
59
bits.number = (bits.scientific + bits.decimal) / tonumber
35✔
60
local unit = Cmt(P"%"^-1 * R("az")^-4, isaunit)
35✔
61
bits.measurement = Ct(Cg(bits.number, "amount") * bits.ws * Cg(unit, "unit"))
35✔
62
local amount = bits.measurement + bits.number / inferpoints
35✔
63
local length = Cg(amount, "length")
35✔
64
local stretch = bits.ws * P"plus" * bits.ws * Cg(amount, "stretch")
35✔
65
local shrink = bits.ws * P"minus" * bits.ws * Cg(amount, "shrink")
35✔
66
bits.length = Ct(length * stretch^-1 * shrink^-1)
35✔
67
bits.utf8char = utf8char
35✔
68

69
local pairsep = S",;"
35✔
70
local quote = P'"'
35✔
71
local escaped_quote = B(P"\\") * quote
35✔
72
local unescapeQuote = function (str) local a = str:gsub('\\"', '"'); return a end
36✔
73
local quotedValueString = quote * C((1 - quote + escaped_quote)^0 / unescapeQuote) * quote
35✔
74
local valueString = (1-pairsep-quote-S"]")^0 / pl.stringx.strip
70✔
75
local value = quotedValueString + valueString + P""
35✔
76
local ID = C(bits.letter * (bits.letter + bits.digit)^0)
35✔
77
bits.silidentifier = (ID + S":-")^1
35✔
78
local pair = Cg(bits.ws * C(bits.silidentifier) * bits.ws * "=" * bits.ws * C(value) * bits.ws) * pairsep^-1 / unwrapper
35✔
79
bits.parameters = Cf(Ct"" * pair^0, rawset)
35✔
80

81
local wrapper = function (a) return type(a)=="table" and a or {} end
35✔
82
local useparams = (P"[" * bits.parameters * P"]")^-1 / wrapper
35✔
83
local modpart = C((1 - P"." - P"/" - P"[")^1)
35✔
84
local module = C(modpart * (P"." * modpart)^0)
35✔
85
bits.cliuse = Ct(Cg(module, "module") * Cg(useparams^-1, "options"))
35✔
86
-- stylua: ignore end
87

88
return bits
35✔
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