package forester
A tool for tending mathematical forests
Install
Dune Dependency
Authors
Maintainers
Sources
4.0.1.tar.gz
md5=1781b3d67f7ff4edaeb5cfdedba46b9e
sha512=879a583fd3ddf1cf44039fbe9a1d7280e9cc9cc0340506561dc8c6bb6b792db7c512a682d4d09d6c6b0b3b14940665573c9d94580c9ce0a87ee05822fbe4c229
doc/src/forester.core/Sem.ml.html
Source file Sem.ml
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
open Base open Prelude module MethodTable = Map.Make (String) type node = | Text of string | Transclude of transclusion_opts * addr | Subtree of transclusion_opts * tree | Query of transclusion_opts * t Query.t | Link of {dest : string; title : t option; modifier : [`Sentence_case] option} | Xml_tag of xml_resolved_qname * (xml_resolved_qname * t) list * t | Unresolved of string | Math of math_mode * t | Embed_tex of {preamble : t; source : t} | Img of {path : string} | If_tex of t * t | Prim of Prim.t * t | Object of Symbol.t | Ref of {addr : string} [@@deriving show] and transclusion_opts = {toc : bool; show_heading : bool; show_metadata : bool; title_override : t option; taxon_override : string option; expanded : bool; numbered : bool} [@@deriving show] and t = node Range.located list and env = t Env.t [@@deriving show] and tree = {fm : frontmatter; body : t} [@@deriving show] and frontmatter = {title : t option; taxon : string option; authors : addr list; contributors : addr list; dates : Date.t list; addr : addr option; metas : (string * t) list; tags: string list; physical_parent : addr option; designated_parent : addr option; source_path : string option; number : string option} type obj_method = {body : Syn.t; self : Symbol.t; super : Symbol.t; env : env} type obj = {prototype : Symbol.t option; methods : obj_method MethodTable.t} let is_whitespace node = match Range.(node.value) with | Text txt -> String.trim txt = "" | _ -> false let strip_whitespace = List.filter @@ fun x -> not @@ is_whitespace x let trim_whitespace xs = let rec trim_front xs = match xs with | x :: xs when is_whitespace x -> trim_front xs | xs -> xs and trim_back xs = List.rev @@ trim_front @@ List.rev xs in trim_back @@ trim_front xs let sentence_case nodes = let map_head f = function | [] -> [] | x :: xs -> f x :: xs in let map_located f node = Range.{node with value = f node.value} in nodes |> map_head @@ map_located @@ function | Text str -> Text (String_util.sentence_case str) | Link link -> Link {link with modifier = Some `Sentence_case} | node -> node let apply_modifier = function | Some `Sentence_case -> sentence_case | None -> Fun.id (** Best-effort rendering of a nodes as a string, to use in text-only contexts.*) let string_of_nodes = let rec render nodes = String.concat "" @@ List.filter_map render_node nodes and render_node located = match Range.(located.value) with | Text s -> Some s | Link {title = Some title; _} -> Some (render title) | Link {title = None; dest; _} -> Some dest | Ref {addr} -> Some addr | Xml_tag (_, _, bdy) | Math (_, bdy) -> Some (render bdy) | Embed_tex {source; _} -> Some (render source) | If_tex (_, x) -> Some (render x) | Prim (_, x) -> Some (render x) | Transclude _ | Subtree _ | Query _ | Unresolved _ | Img _ | Object _ -> None in render module Util = struct let peek_title (tree : tree) = match tree.fm.title with | Some ({value = Text txt; _} :: _) -> Some txt | _ -> None let peek_addr (tree : tree) = tree.fm.addr let (tree : tree) = tree.fm.tags let taxon (tree : tree) = tree.fm.taxon let (tree : tree) = tree.fm.authors let basic_comparator = let by_date = Fun.flip @@ Compare.under (fun x -> List.nth_opt x.fm.dates 0) @@ Compare.option Date.compare in let by_title = Compare.under peek_title @@ Compare.option String.compare in let by_addr = Compare.under (fun x -> x.fm.addr) @@ Compare.option String.compare in Compare.cascade by_date @@ Compare.cascade by_title by_addr let sort = List.sort basic_comparator let sort_for_index = let by_has_parent = Compare.under (fun x -> Option.is_some x.fm.designated_parent) @@ Bool.compare in List.sort @@ Compare.cascade by_has_parent basic_comparator end module Query = struct let rec test query (doc : tree) = match query with | Query.Author [Range.{value = Text addr; _}] -> List.mem addr doc.fm.authors | Query.Tag [{value = Text addr; _}] -> List.mem addr doc.fm.tags | Query.Meta (key, value) -> List.mem (key, value) doc.fm.metas | Query.Taxon [{value = Text taxon; _}] -> doc.fm.taxon = Some taxon | Query.Or qs -> qs |> List.exists @@ fun q -> test q doc | Query.And qs -> qs |> List.for_all @@ fun q -> test q doc | Query.Not q -> not @@ test q doc | Query.True -> true | _ -> false end let empty_frontmatter = {addr = None; title = None; taxon = None; dates = []; authors = []; contributors = []; tags = []; metas = []; physical_parent = None; designated_parent = None; source_path = None; number = None} let default_transclusion_opts : transclusion_opts = {title_override = None; taxon_override = None; show_heading = true; show_metadata = true; toc = true; expanded = true; numbered = true}
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>