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

sile-typesetter / sile / 9400953783

06 Jun 2024 12:32PM UTC coverage: 62.819% (-11.3%) from 74.124%
9400953783

push

github

alerque
Merge branch 'develop'

1752 of 2644 new or added lines in 109 files covered. (66.26%)

2019 existing lines in 84 files now uncovered.

10830 of 17240 relevant lines covered (62.82%)

3306.33 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")
198✔
2

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

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

48
local bits = {}
198✔
49

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

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

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

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

© 2025 Coveralls, Inc