Skip to content

Commit a302c28

Browse files
committed
Add support for linking to nested abstract theories.
1 parent 1dcdd91 commit a302c28

3 files changed

Lines changed: 26 additions & 33 deletions

File tree

src/ecDoc.ml

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let c_filename ?(ext : string option) (nms : string list) =
2020
match ext with
2121
| None -> String.concat "!" nms
2222
| Some ext -> String.concat "!" nms ^ ext
23-
23+
2424
(* -------------------------------------------------------------------- *)
2525
let thkind_str (kind : EcLoader.kind) : string =
2626
match kind with
@@ -39,7 +39,27 @@ let itemkind_str_pl (ik : itemkind) : string =
3939
| `Theory -> "Theories"
4040

4141
(* -------------------------------------------------------------------- *)
42+
let rec bot_env_of_qsymbol (q : EcSymbols.qsymbol) (env : EcEnv.env)=
43+
match fst q with
44+
| [] | ["Top"] -> env
45+
| x :: xs ->
46+
let p = EcEnv.Theory.lookup_path ~mode:`All ([], x) env in
47+
let env = EcEnv.Theory.env_of_theory p env in
48+
bot_env_of_qsymbol (xs, snd q) env
4249

50+
let filename_of_path ?(ext : string option) (rth : string) (p : EcPath.path) =
51+
let qs = EcPath.toqsymbol p in
52+
match fst qs with
53+
| [] -> assert false
54+
| ["Top"] -> c_filename ?ext [rth]
55+
| "Top" :: ts ->
56+
let reqrt = (List.hd ts) in
57+
if from_stdlib reqrt then
58+
Filename.concat (stdlib_doc_dp reqrt) (c_filename ?ext ts)
59+
else
60+
(c_filename ?ext (rth :: ts))
61+
| _ -> assert false
62+
4363
(* -------------------------------------------------------------------- *)
4464
let md_pre_format ~kind (s : string) =
4565
match kind with | _ -> pre [txt s]
@@ -50,14 +70,7 @@ let md_href_format (rth : string) (env : EcEnv.env) (hr : Markdown.href) : Html_
5070
let tkind = Str.matched_group 1 hr.href_target in
5171
let tname = Str.matched_group 2 hr.href_target in
5272
let tqs = EcSymbols.qsymbol_of_string tname in
53-
let env =
54-
match fst tqs with
55-
| [] | ["Top"] -> env
56-
| _ ->
57-
let tsupqs = EcSymbols.qsymbol_of_sup tqs in
58-
let tsupp = EcEnv.Theory.lookup_path ~mode:`All tsupqs env in
59-
EcEnv.Theory.env_of_theory tsupp env
60-
in
73+
let env = bot_env_of_qsymbol tqs env in
6174
let ikstr, path =
6275
match tkind with
6376
| "Ty" | "Type" -> itemkind_str_pl `Type, EcEnv.Ty.lookup_path tqs env
@@ -73,22 +86,10 @@ let md_href_format (rth : string) (env : EcEnv.env) (hr : Markdown.href) : Html_
7386
| `Concrete (_, Some _) -> failwith "Linking to sub-modules not supported."
7487
| `Local _ -> failwith "Linking to local/declared modules not supported."
7588
end
76-
| "Th" | "Theory" -> itemkind_str_pl `Theory, EcEnv.Theory.lookup_path ~mode:(`All) tqs env
89+
| "Th" | "Theory" -> itemkind_str_pl `Theory, EcEnv.Theory.lookup_path ~mode:`All tqs env
7790
| _ -> failwith "Invalid item/entity kind."
7891
in
79-
let tqs = EcPath.toqsymbol path in
80-
let fn =
81-
match fst tqs with
82-
| [] -> assert false
83-
| ["Top"] -> c_filename ~ext:".html" [rth]
84-
| "Top" :: ts ->
85-
let reqrt = (List.hd ts) in
86-
if from_stdlib reqrt then
87-
Filename.concat (stdlib_doc_dp reqrt) (c_filename ~ext:".html" ts)
88-
else
89-
(c_filename ~ext:".html" (rth :: ts))
90-
| _ -> assert false
91-
in
92+
let fn = filename_of_path ~ext:".html" rth path in
9293
let il = fn ^ "#" ^ ikstr ^ snd tqs in
9394
a ~a:[a_href (uri_of_string il)] [txt hr.href_desc]
9495
else

src/ecSymbols.ml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ let pp_msymbol fmt x =
9292
let qsymbol_of_string (s : string) : qsymbol =
9393
let sspl = String.split_on_char '.' s in
9494
match List.rev sspl with
95-
| [] -> assert false
95+
| [] -> raise (invalid_arg "EcSymbols.qsymbol_of_string")
9696
| [x] -> ([], x)
9797
| x :: xs -> (List.rev xs, x)
98-
99-
100-
let qsymbol_of_sup (q : qsymbol) : qsymbol =
101-
match List.rev (fst q) with
102-
| [] -> assert false
103-
| [x] -> ([], x)
104-
| x :: xs -> (List.rev xs, x)

src/ecSymbols.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ val pp_msymbol : Format.formatter -> msymbol -> unit
3333

3434
val string_of_qsymbol : qsymbol -> string
3535

36-
val qsymbol_of_string : string -> qsymbol
37-
val qsymbol_of_sup : qsymbol -> qsymbol
36+
val qsymbol_of_string : string -> qsymbol

0 commit comments

Comments
 (0)