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

sile-typesetter / sile / 8288578143

14 Mar 2024 09:39PM UTC coverage: 64.155% (-10.6%) from 74.718%
8288578143

Pull #1904

github

alerque
chore(core): Fixup ec6ed657 which didn't shim old pack styles properly
Pull Request #1904: Merge develop into master (commit to next release being breaking)

1648 of 2421 new or added lines in 107 files covered. (68.07%)

1843 existing lines in 77 files now uncovered.

10515 of 16390 relevant lines covered (64.15%)

3306.56 hits per line

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

87.5
/core/parserbits.lua
1
local lpeg = require("lpeg")
184✔
2

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

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

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

17
local function unwrapper (...)
18
  local tbl = {...}
854✔
19
  return tbl[1], tbl[#tbl]
854✔
20
end
21

22
-- UTF-8 characters
23
-- decode a two-byte UTF-8 sequence
24
local function f2 (s)
25
  local c1, c2 = string.byte(s, 1, 2)
×
26
  return c1 * 64 + c2 - 12416
×
27
end
28
-- decode a three-byte UTF-8 sequence
29
local function f3 (s)
30
  local c1, c2, c3 = string.byte(s, 1, 3)
×
31
  return (c1 * 64 + c2) * 64 + c3 - 925824
×
32
end
33
-- decode a four-byte UTF-8 sequence
34
local function f4 (s)
35
  local c1, c2, c3, c4 = string.byte(s, 1, 4)
×
36
  return ((c1 * 64 + c2) * 64 + c3) * 64 + c4 - 63447168
×
37
end
38
local cont = lpeg.R("\128\191")   -- continuation byte
184✔
39
local utf8char = lpeg.R("\0\127") / string.byte
184✔
40
  + lpeg.R("\194\223") * cont / f2
184✔
41
  + lpeg.R("\224\239") * cont * cont / f3
184✔
42
  + lpeg.R("\240\244") * cont * cont * cont / f4
184✔
43

44
local bits = {}
184✔
45

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

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

77
local wrapper = function (a) return type(a)=="table" and a or {} end
184✔
78
local useparams = (P"[" * bits.parameters * P"]")^-1 / wrapper
184✔
79
local modpart = C((1 - P"." - P"/" - P"[")^1)
184✔
80
local module = C(modpart * (P"." * modpart)^0)
184✔
81
bits.cliuse = Ct(Cg(module, "module") * Cg(useparams^-1, "options"))
184✔
82

83
return bits
184✔
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