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

sile-typesetter / sile / 8921272340

02 May 2024 09:00AM UTC coverage: 66.229% (+2.5%) from 63.747%
8921272340

push

github

web-flow
chore(deps): Bump @commitlint/cli from 18.6.1 to 19.3.0 (#2016)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10531 of 15901 relevant lines covered (66.23%)

3880.04 hits per line

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

87.04
/core/parserbits.lua
1
local lpeg = require("lpeg")
85✔
2

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

6
local function isaunit (_, _, unit)
7
  -- TODO: fix race condition so we can validate units
8
  if not SILE or not SILE.units then return true end
25,906✔
9
  return SILE.units[unit] and true or false
25,141✔
10
end
11

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

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

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

43
local bits = {}
85✔
44

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

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

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

81
return bits
85✔
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