-
Notifications
You must be signed in to change notification settings - Fork 83
/
bnf.satyh
58 lines (47 loc) · 1.73 KB
/
bnf.satyh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@require: math
module BNF : sig
direct +BNF : [math; (math list) list] block-cmd
direct \BNF : [math; (math list) list] inline-cmd
direct \BNFs : [(math * (math list) list) list] inline-cmd
end = struct
let insert-bars mlst =
Math.join ${\mid} mlst
let tabular-of-math ctx mnontm mlstlst =
let sz = get-font-size ctx in
let vpad = sz *' 0.25 in
let padsL = (0pt, sz *' 0.5, vpad, vpad) in
let padsR = (0pt, 0pt, vpad, vpad) in
mlstlst |> List.fold-lefti (fun i acc mlst -> (
let c0 =
if i == 0 then
NormalCell(padsL, embed-math ctx ${#mnontm \mathrel{: : =}})
else
NormalCell(padsL, inline-fil ++ embed-math ctx ${\mid})
in
let ib = embed-math ctx (insert-bars mlst) ++ inline-fil in
[c0; NormalCell(padsR, ib)] :: acc
)) [] |> List.reverse
let-block ctx +BNF mnontm mlstlst =
let celllstlst = tabular-of-math ctx mnontm mlstlst in
let ib = tabular celllstlst (fun _ _ -> []) in
let vp = get-font-size ctx *' 1. in
line-break true true (ctx |> set-paragraph-margin vp vp)
(inline-fil ++ ib ++ inline-fil)
let-inline ctx \BNF mnontm mlstlst =
inline-fil ++
embed-block-breakable ctx (read-block ctx '<+BNF(mnontm)(mlstlst);>)
let-inline ctx \BNFs lst =
let cllall =
lst |> List.fold-left (fun cllacc (mnontm, mlstlst) -> (
let cll = tabular-of-math ctx mnontm mlstlst in
List.append cllacc cll
)) []
in
let ib = tabular cllall (fun _ _ -> []) in
let vp = get-font-size ctx *' 1.5 in
let bb =
line-break true true (ctx |> set-paragraph-margin vp vp)
(inline-fil ++ ib ++ inline-fil)
in
inline-fil ++ embed-block-breakable ctx bb
end