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

sile-typesetter / sile / 9428909082

08 Jun 2024 12:56PM UTC coverage: 65.855% (-2.4%) from 68.206%
9428909082

push

github

alerque
chore(release): 0.15.1

11379 of 17279 relevant lines covered (65.85%)

3672.09 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")
127✔
2

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

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

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

19
local function unwrapper (...)
20
   local tbl = { ... }
559✔
21
   return tbl[1], tbl[#tbl]
559✔
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
127✔
43
local utf8char = lpeg.R("\0\127") / string.byte
127✔
44
   + lpeg.R("\194\223") * cont / f2
127✔
45
   + lpeg.R("\224\239") * cont * cont / f3
127✔
46
   + lpeg.R("\240\244") * cont * cont * cont / f4
127✔
47

48
local bits = {}
127✔
49

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

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

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

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

© 2024 Coveralls, Inc