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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

89.09
/core/parserbits.lua
1
local lpeg = require("lpeg")
181✔
2

3
local R, S, P, B = lpeg.R, lpeg.S, lpeg.P, lpeg.B
181✔
4
local C, Cf, Cg, Ct, Cmt = lpeg.C, lpeg.Cf, lpeg.Cg, lpeg.Ct, lpeg.Cmt
181✔
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
64,378✔
9
      return true
1,629✔
10
   end
11
   return SILE.units[unit] and true or false
62,749✔
12
end
13

14
local function inferpoints (number)
15
   return { amount = number, unit = "pt" }
3✔
16
end
17

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

23
-- UTF-8 characters
24
-- decode a two-byte UTF-8 sequence
25
local function f2 (s)
NEW
26
   local c1, c2 = string.byte(s, 1, 2)
×
NEW
27
   return c1 * 64 + c2 - 12416
×
28
end
29
-- decode a three-byte UTF-8 sequence
30
local function f3 (s)
NEW
31
   local c1, c2, c3 = string.byte(s, 1, 3)
×
NEW
32
   return (c1 * 64 + c2) * 64 + c3 - 925824
×
33
end
34
-- decode a four-byte UTF-8 sequence
35
local function f4 (s)
NEW
36
   local c1, c2, c3, c4 = string.byte(s, 1, 4)
×
NEW
37
   return ((c1 * 64 + c2) * 64 + c3) * 64 + c4 - 63447168
×
38
end
39

40
-- stylua: ignore start
41
local cont = lpeg.R("\128\191")   -- continuation byte
181✔
42
local utf8char = lpeg.R("\0\127") / string.byte
181✔
43
  + lpeg.R("\194\223") * cont / f2
181✔
44
  + lpeg.R("\224\239") * cont * cont / f3
181✔
45
  + lpeg.R("\240\244") * cont * cont * cont / f4
181✔
46

47
local bits = {}
181✔
48

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

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

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

86
return bits
181✔
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