Skip to content

Commit 34914cf

Browse files
3Rafaljonludlam
authored andcommitted
Add @hidden tag
1 parent 370f1cf commit 34914cf

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

src/ast.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type nestable_block_element =
5858
and table = nestable_block_element abstract_table * [ `Light | `Heavy ]
5959

6060
type internal_tag =
61-
[ `Canonical of string with_location | `Inline | `Open | `Closed ]
61+
[ `Canonical of string with_location | `Inline | `Open | `Closed | `Hidden ]
6262
(** Internal tags are used to exercise fine control over the output of odoc. They
6363
are never rendered in the output *)
6464

src/lexer.mll

+2
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ rule token input = parse
468468
| "@closed"
469469
{ emit input (`Tag `Closed) }
470470

471+
| "@hidden"
472+
{ emit input (`Tag `Hidden) }
471473

472474

473475
| '{'

src/syntax.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ let tag_to_words = function
595595
| `Inline -> [ `Word "@inline" ]
596596
| `Open -> [ `Word "@open" ]
597597
| `Closed -> [ `Word "@closed" ]
598+
| `Hidden -> [ `Word "@hidden" ]
598599
| `Param s -> [ `Word "@param"; `Space " "; `Word s ]
599600
| `Raise s -> [ `Word "@raise"; `Space " "; `Word s ]
600601
| `Return -> [ `Word "@return" ]
@@ -843,7 +844,7 @@ let rec block_element_list :
843844
let tag = Loc.at location tag in
844845
consume_block_elements ~parsed_a_tag:true where_in_line
845846
(tag :: acc)
846-
| (`Inline | `Open | `Closed) as tag ->
847+
| (`Inline | `Open | `Closed | `Hidden) as tag ->
847848
let tag = Loc.at location (`Tag tag) in
848849
consume_block_elements ~parsed_a_tag:true `After_text
849850
(tag :: acc)))

src/token.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ type tag =
2020
| `Canonical of string
2121
| `Inline
2222
| `Open
23-
| `Closed ] ]
23+
| `Closed
24+
| `Hidden] ]
2425

2526
type t =
2627
[ (* End of input. *)
@@ -117,6 +118,7 @@ let print : [< t ] -> string = function
117118
| `Tag `Inline -> "'@inline'"
118119
| `Tag `Open -> "'@open'"
119120
| `Tag `Closed -> "'@closed'"
121+
| `Tag `Hidden -> "'@hidden"
120122
| `Raw_markup (None, _) -> "'{%...%}'"
121123
| `Raw_markup (Some target, _) -> "'{%" ^ target ^ ":...%}'"
122124

@@ -177,6 +179,7 @@ let describe : [< t | `Comment ] -> string = function
177179
| `Tag `Inline -> "'@inline'"
178180
| `Tag `Open -> "'@open'"
179181
| `Tag `Closed -> "'@closed'"
182+
| `Tag `Hidden -> "'@hidden"
180183
| `Comment -> "top-level text"
181184

182185
let describe_element = function

test/test.ml

+73
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ module Ast_to_sexp = struct
140140
| `Inline -> Atom "@inline"
141141
| `Open -> Atom "@open"
142142
| `Closed -> Atom "@closed"
143+
| `Hidden -> Atom "@hidden"
143144

144145
let block_element at : Ast.block_element -> sexp = function
145146
| #Ast.nestable_block_element as e -> nestable_block_element at e
@@ -4640,6 +4641,78 @@ let%expect_test _ =
46404641
end in
46414642
()
46424643

4644+
let%expect_test _ =
4645+
let module Hidden = struct
4646+
let basic =
4647+
test "@hidden";
4648+
[%expect {| ((output (((f.ml (1 0) (1 7)) @hidden))) (warnings ())) |}]
4649+
4650+
let prefix =
4651+
test "@hiddenfoo";
4652+
[%expect
4653+
{|
4654+
((output
4655+
(((f.ml (1 0) (1 10))
4656+
(paragraph (((f.ml (1 0) (1 10)) (word @hiddenfoo)))))))
4657+
(warnings
4658+
( "File \"f.ml\", line 1, characters 0-10:\
4659+
\nUnknown tag '@hiddenfoo'."))) |}]
4660+
4661+
let extra_whitespace =
4662+
test "@hidden";
4663+
[%expect {| ((output (((f.ml (1 0) (1 7)) @hidden))) (warnings ())) |}]
4664+
4665+
let followed_by_junk =
4666+
test "@hidden foo";
4667+
[%expect
4668+
{|
4669+
((output
4670+
(((f.ml (1 0) (1 7)) @hidden)
4671+
((f.ml (1 8) (1 11)) (paragraph (((f.ml (1 8) (1 11)) (word foo)))))))
4672+
(warnings
4673+
( "File \"f.ml\", line 1, characters 8-11:\
4674+
\nParagraph is not allowed in the tags section.\
4675+
\nSuggestion: move 'foo' before any tags."
4676+
"File \"f.ml\", line 1, characters 8-11:\
4677+
\nParagraph should begin on its own line."))) |}]
4678+
4679+
let followed_by_paragraph =
4680+
test "@hidden\nfoo";
4681+
[%expect
4682+
{|
4683+
((output
4684+
(((f.ml (1 0) (1 7)) @hidden)
4685+
((f.ml (2 0) (2 3)) (paragraph (((f.ml (2 0) (2 3)) (word foo)))))))
4686+
(warnings
4687+
( "File \"f.ml\", line 2, characters 0-3:\
4688+
\nParagraph is not allowed in the tags section.\
4689+
\nSuggestion: move 'foo' before any tags."))) |}]
4690+
4691+
let followed_by_tag =
4692+
test "@hidden\n@deprecated";
4693+
[%expect
4694+
{|
4695+
((output (((f.ml (1 0) (1 7)) @hidden) ((f.ml (2 0) (2 11)) (@deprecated))))
4696+
(warnings ())) |}]
4697+
4698+
let with_list =
4699+
test "@hidden - foo";
4700+
[%expect
4701+
{|
4702+
((output
4703+
(((f.ml (1 0) (1 7)) @hidden)
4704+
((f.ml (1 8) (1 13))
4705+
(unordered light
4706+
((((f.ml (1 10) (1 13)) (paragraph (((f.ml (1 10) (1 13)) (word foo)))))))))))
4707+
(warnings
4708+
( "File \"f.ml\", line 1, characters 8-9:\
4709+
\n'-' (bulleted list item) should begin on its own line."
4710+
"File \"f.ml\", line 1, characters 8-9:\
4711+
\n'-' (bulleted list item) is not allowed in the tags section.\
4712+
\nSuggestion: move '-' (bulleted list item) before any tags."))) |}]
4713+
end in
4714+
()
4715+
46434716
let%expect_test _ =
46444717
let module Bad_markup = struct
46454718
let left_brace =

0 commit comments

Comments
 (0)