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

sile-typesetter / sile / 9304049654

30 May 2024 02:12PM UTC coverage: 60.021% (-14.7%) from 74.707%
9304049654

push

github

web-flow
Merge 1a26b4f22 into a1fd105f8

6743 of 12900 new or added lines in 186 files covered. (52.27%)

347 existing lines in 49 files now uncovered.

10311 of 17179 relevant lines covered (60.02%)

3307.34 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")
208✔
2

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

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

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

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

24
-- UTF-8 characters
25
-- decode a two-byte UTF-8 sequence
26
local function f2 (s)
NEW
27
   local c1, c2 = string.byte(s, 1, 2)
×
NEW
28
   return c1 * 64 + c2 - 12416
×
29
end
30
-- decode a three-byte UTF-8 sequence
31
local function f3 (s)
NEW
32
   local c1, c2, c3 = string.byte(s, 1, 3)
×
NEW
33
   return (c1 * 64 + c2) * 64 + c3 - 925824
×
34
end
35
-- decode a four-byte UTF-8 sequence
36
local function f4 (s)
NEW
37
   local c1, c2, c3, c4 = string.byte(s, 1, 4)
×
NEW
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
208✔
43
local utf8char = lpeg.R("\0\127") / string.byte
208✔
44
   + lpeg.R("\194\223") * cont / f2
208✔
45
   + lpeg.R("\224\239") * cont * cont / f3
208✔
46
   + lpeg.R("\240\244") * cont * cont * cont / f4
208✔
47

48
local bits = {}
208✔
49

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

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

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

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