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

sile-typesetter / sile / 11637450455

01 Nov 2024 10:51PM UTC coverage: 65.274% (+7.6%) from 57.636%
11637450455

push

github

web-flow
Merge 9d9e4ff40 into 5dffc31aa

132 of 201 new or added lines in 5 files covered. (65.67%)

207 existing lines in 13 files now uncovered.

11917 of 18257 relevant lines covered (65.27%)

4285.37 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")
243✔
2

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

6
local function isaunit (_, _, unit)
7
   -- TODO: fix race condition so we can validate units
8
   local factory = rawget(SILE.types, "unit")
43,685✔
9
   if not SILE or not factory then
43,685✔
10
      return true
2,420✔
11
   end
12
   return factory[unit] and true or false
41,265✔
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 = { ... }
1,149✔
21
   return tbl[1], tbl[#tbl]
1,149✔
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
243✔
43
local utf8char = lpeg.R("\0\127") / string.byte
243✔
44
   + lpeg.R("\194\223") * cont / f2
243✔
45
   + lpeg.R("\224\239") * cont * cont / f3
243✔
46
   + lpeg.R("\240\244") * cont * cont * cont / f4
243✔
47

48
local bits = {}
243✔
49

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

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

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

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