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

sile-typesetter / sile / 6932773445

20 Nov 2023 04:11PM UTC coverage: 60.703% (-1.6%) from 62.266%
6932773445

Pull #1904

github

alerque
feat(utilities): Add Greek alphabetical (non-arithmetic) numbering

Useful in some context such as biblical annotations etc. where greek
characters are used orderly for numbering.
Pull Request #1904: Merge develop into master (commit to next release being breaking)

66 of 193 new or added lines in 19 files covered. (34.2%)

321 existing lines in 26 files now uncovered.

9452 of 15571 relevant lines covered (60.7%)

2104.43 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")
53✔
2

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

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

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

43
local bits = {}
53✔
44

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

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

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

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