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

sile-typesetter / sile / 6915746301

18 Nov 2023 07:02PM UTC coverage: 56.433% (-12.3%) from 68.751%
6915746301

push

github

web-flow
Merge 8b3fdc301 into f64e235fa

8729 of 15468 relevant lines covered (56.43%)

932.75 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")
34✔
2

3
local R, S, P, B = lpeg.R, lpeg.S, lpeg.P, lpeg.B
34✔
4
local C, Cf, Cg, Ct, Cmt = lpeg.C, lpeg.Cf, lpeg.Cg, lpeg.Ct, lpeg.Cmt
34✔
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
10,100✔
9
  return SILE.units[unit] and true or false
9,794✔
10
end
11

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

16
local function unwrapper (...)
17
  local tbl = {...}
64✔
18
  return tbl[1], tbl[#tbl]
64✔
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
34✔
38
local utf8char = lpeg.R("\0\127") / string.byte
34✔
39
  + lpeg.R("\194\223") * cont / f2
34✔
40
  + lpeg.R("\224\239") * cont * cont / f3
34✔
41
  + lpeg.R("\240\244") * cont * cont * cont / f4
34✔
42

43
local bits = {}
34✔
44

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

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

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

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