Skip to content

Commit 6c3e742

Browse files
author
Guillaume Petiot
authored
Support odoc-parser.2.0.0 (#2123)
1 parent 1cb060b commit 6c3e742

12 files changed

+183
-7
lines changed

Diff for: CHANGES.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
## (unreleased)
2+
3+
### New features
4+
5+
- Support `odoc-parser.2.0.0` (#2123, @gpetiot)
6+
* Breaking change: incompatible with earlier versions of `odoc-parser`
7+
* New inline math elements `{m ...}` available in doc-comments
8+
* New block math elements `{math ...}` available in doc-comments
9+
110
## 0.23.0 (2022-07-07)
211

312
### Removed
413

514
- `bench` binary is not distributed anymore to avoid name collisions (#2104, @gpetiot)
615

7-
### Deprecated
8-
916
### Bug fixes
1017

1118
- Preserve comments around object open/close flag (#2097, @trefis, @gpetiot)
@@ -19,8 +26,6 @@
1926
- JaneStreet profile: set `max-indent = 2` (#2099, @gpetiot)
2027
- JaneStreet profile: align pattern-matching bar `|` under keyword instead of parenthesis (#2102, @gpetiot)
2128

22-
### New features
23-
2429
## 0.22.4 (2022-05-26)
2530

2631
### Removed

Diff for: dune-project

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
ocp-indent
6565
(odoc-parser
6666
(and
67-
(>= 1.0.0)
68-
(< 2.0.0)))
67+
(>= 2.0.0)
68+
(< 3.0.0)))
6969
(re
7070
(>= 1.7.2))
7171
stdio

Diff for: lib/Docstring.ml

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ let rec odoc_inline_element fmt = function
7575
in
7676
fpf fmt "Word(%a)" str txt
7777
| `Code_span txt -> fpf fmt "Code_span(%a)" str txt
78+
| `Math_span txt -> fpf fmt "Math_span(%a)" str txt
7879
| `Raw_markup (Some lang, txt) -> fpf fmt "Raw_markup(%s,%a)" lang str txt
7980
| `Raw_markup (None, txt) -> fpf fmt "Raw_markup(%a)" str txt
8081
| `Styled (style, elems) ->
@@ -97,6 +98,7 @@ let rec odoc_nestable_block_element c fmt = function
9798
option (pair (ign_loc str) (option (ign_loc str)))
9899
in
99100
fpf fmt "Code_block(%a, %a)" fmt_metadata metadata str txt
101+
| `Math_block txt -> fpf fmt "Math_block(%a)" str txt
100102
| `Verbatim txt -> fpf fmt "Verbatim(%a)" str txt
101103
| `Modules mods -> fpf fmt "Modules(%a)" (list odoc_reference) mods
102104
| `List (ord, _syntax, items) ->

Diff for: lib/Fmt_odoc.ml

+19
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ let fmt_code_block conf s1 s2 =
103103

104104
let fmt_code_span s = hovbox 0 (wrap "[" "]" (str (escape_brackets s)))
105105

106+
let fmt_math_span s = hovbox 2 (wrap "{m " "}" (str s))
107+
108+
let fmt_math_block s =
109+
let lines =
110+
List.drop_while ~f:String.is_empty
111+
@@ List.rev
112+
@@ List.drop_while ~f:String.is_empty
113+
@@ List.rev_map ~f:String.strip
114+
@@ String.split_lines s
115+
in
116+
let fmt ~first ~last:_ line =
117+
if first then str line
118+
else if String.is_empty line then str "\n"
119+
else fmt "@;<1000 0>" $ str line
120+
in
121+
hvbox 2 (wrap "{math@;" "@;<0 -2>}" (list_fl lines fmt))
122+
106123
let fmt_reference = ign_loc ~f:str_normalized
107124

108125
(* Decide between using light and heavy syntax for lists *)
@@ -161,6 +178,7 @@ let rec fmt_inline_elements elements =
161178
| `Space _ :: t -> fmt "@ " $ aux t
162179
| `Word w :: t -> str_normalized w $ aux t
163180
| `Code_span s :: t -> fmt_code_span s $ aux t
181+
| `Math_span s :: t -> fmt_math_span s $ aux t
164182
| `Raw_markup (lang, s) :: t ->
165183
let lang =
166184
match lang with
@@ -193,6 +211,7 @@ let rec fmt_inline_elements elements =
193211
and fmt_nestable_block_element c = function
194212
| `Paragraph elems -> fmt_inline_elements elems
195213
| `Code_block (s1, s2) -> fmt_code_block c s1 s2
214+
| `Math_block s -> fmt_math_block s
196215
| `Verbatim s -> fmt_verbatim_block s
197216
| `Modules mods ->
198217
hovbox 0

Diff for: ocamlformat.opam

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ depends: [
2424
"ocaml-version" {>= "3.3.0"}
2525
"ocamlformat-rpc-lib" {with-test & post & = version}
2626
"ocp-indent"
27-
"odoc-parser" {>= "1.0.0" & < "2.0.0"}
27+
"odoc-parser" {>= "2.0.0" & < "3.0.0"}
2828
"re" {>= "1.7.2"}
2929
"stdio"
3030
"uuseg" {>= "10.0.0"}

Diff for: test/passing/tests/doc_comments-no-parse-docstrings.mli.err

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ Warning: tests/doc_comments.mli:547 exceeds the margin
2020
Warning: tests/doc_comments.mli:549 exceeds the margin
2121
Warning: tests/doc_comments.mli:551 exceeds the margin
2222
Warning: tests/doc_comments.mli:575 exceeds the margin
23+
Warning: tests/doc_comments.mli:585 exceeds the margin
24+
Warning: tests/doc_comments.mli:613 exceeds the margin

Diff for: test/passing/tests/doc_comments-no-parse-docstrings.mli.ref

+40
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,43 @@ type x =
580580
(**a*)
581581

582582
(**b*)
583+
584+
(** Inline math: {m \infty}
585+
586+
Inline math elements can wrap as well {m \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty} or {m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}.
587+
588+
Block math:
589+
590+
{math \infty}
591+
592+
{math
593+
\infty
594+
}
595+
596+
{math
597+
598+
\pi
599+
600+
}
601+
602+
{math
603+
604+
\infty
605+
606+
\pi
607+
608+
\pi
609+
610+
\pi
611+
612+
}
613+
614+
{math {m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}}
615+
616+
{math
617+
% \f is defined as #1f(#2) using the macro
618+
\f\relax{x} = \int_{-\infty}^\infty
619+
\f\hat\xi\,e^{2 \pi i \xi x}
620+
\,d\xi
621+
}
622+
*)

Diff for: test/passing/tests/doc_comments-no-wrap.mli.err

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ Warning: tests/doc_comments.mli:424 exceeds the margin
1414
Warning: tests/doc_comments.mli:437 exceeds the margin
1515
Warning: tests/doc_comments.mli:494 exceeds the margin
1616
Warning: tests/doc_comments.mli:524 exceeds the margin
17+
Warning: tests/doc_comments.mli:594 exceeds the margin
18+
Warning: tests/doc_comments.mli:596 exceeds the margin
19+
Warning: tests/doc_comments.mli:613 exceeds the margin

Diff for: test/passing/tests/doc_comments-no-wrap.mli.ref

+31
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,34 @@ type x =
588588
(**a*)
589589

590590
(**b*)
591+
592+
(** Inline math: {m \infty}
593+
594+
Inline math elements can wrap as well
595+
{m \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty}
596+
or
597+
{m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}.
598+
599+
Block math:
600+
601+
{math \infty}
602+
{math \infty}
603+
{math \pi}
604+
{math
605+
\infty
606+
607+
\pi
608+
609+
\pi
610+
611+
\pi
612+
}
613+
{math
614+
{m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}
615+
}
616+
{math
617+
% \f is defined as #1f(#2) using the macro
618+
\f\relax{x} = \int_{-\infty}^\infty
619+
\f\hat\xi\,e^{2 \pi i \xi x}
620+
\,d\xi
621+
} *)

Diff for: test/passing/tests/doc_comments.mli

+40
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,43 @@ type x =
588588
{@sh[ echo "this""is""only""a""single"(echo word)(echo also) ]} *)
589589

590590
(**a*)(**b*)
591+
592+
(** Inline math: {m \infty}
593+
594+
Inline math elements can wrap as well {m \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty} or {m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}.
595+
596+
Block math:
597+
598+
{math \infty}
599+
600+
{math
601+
\infty
602+
}
603+
604+
{math
605+
606+
\pi
607+
608+
}
609+
610+
{math
611+
612+
\infty
613+
614+
\pi
615+
616+
\pi
617+
618+
\pi
619+
620+
}
621+
622+
{math {m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}}
623+
624+
{math
625+
% \f is defined as #1f(#2) using the macro
626+
\f\relax{x} = \int_{-\infty}^\infty
627+
\f\hat\xi\,e^{2 \pi i \xi x}
628+
\,d\xi
629+
}
630+
*)

Diff for: test/passing/tests/doc_comments.mli.err

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ Warning: tests/doc_comments.mli:424 exceeds the margin
1414
Warning: tests/doc_comments.mli:437 exceeds the margin
1515
Warning: tests/doc_comments.mli:494 exceeds the margin
1616
Warning: tests/doc_comments.mli:524 exceeds the margin
17+
Warning: tests/doc_comments.mli:588 exceeds the margin
18+
Warning: tests/doc_comments.mli:590 exceeds the margin
19+
Warning: tests/doc_comments.mli:607 exceeds the margin

Diff for: test/passing/tests/doc_comments.mli.ref

+31
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,34 @@ type x =
582582
(**a*)
583583

584584
(**b*)
585+
586+
(** Inline math: {m \infty}
587+
588+
Inline math elements can wrap as well
589+
{m \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty \infty}
590+
or
591+
{m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}.
592+
593+
Block math:
594+
595+
{math \infty}
596+
{math \infty}
597+
{math \pi}
598+
{math
599+
\infty
600+
601+
\pi
602+
603+
\pi
604+
605+
\pi
606+
}
607+
{math
608+
{m \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi}
609+
}
610+
{math
611+
% \f is defined as #1f(#2) using the macro
612+
\f\relax{x} = \int_{-\infty}^\infty
613+
\f\hat\xi\,e^{2 \pi i \xi x}
614+
\,d\xi
615+
} *)

0 commit comments

Comments
 (0)