Skip to content

Commit b3dc85c

Browse files
authored
feat(graindoc): Support deprecations on module docblocks (#1498)
chore(stdlib): Deprecate Stack & Queue modules chore(stdlib): Regenerate markdown docs for Stack & Queue modules
1 parent 2284fb5 commit b3dc85c

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

compiler/graindoc/graindoc.re

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,37 @@ let generate_docs =
8787
let module_name = ref(None);
8888
switch (module_comment) {
8989
| Some((_, desc, attrs)) =>
90+
let deprecations =
91+
attrs
92+
|> List.filter(Comments.Attribute.is_deprecated)
93+
|> List.map((attr: Comments.Attribute.t) => {
94+
switch (attr) {
95+
| Deprecated({attr_desc}) => attr_desc
96+
| _ =>
97+
failwith(
98+
"Unreachable: Non-`deprecated` attribute can't exist here.",
99+
)
100+
}
101+
});
102+
90103
// TODO(#787): Should we fail if more than one `@module` attribute?
91104
let module_attr = attrs |> List.find(Comments.Attribute.is_module);
92105
switch (module_attr) {
93106
| Module({attr_name, attr_desc}) =>
94107
module_name := Some(attr_name);
95108
Buffer.add_string(buf, Markdown.frontmatter([("title", attr_name)]));
109+
if (List.length(deprecations) > 0) {
110+
List.iter(
111+
msg =>
112+
Buffer.add_string(
113+
buf,
114+
Markdown.blockquote(
115+
Markdown.bold("Deprecated:") ++ " " ++ msg,
116+
),
117+
),
118+
deprecations,
119+
);
120+
};
96121
Buffer.add_string(buf, Markdown.paragraph(attr_desc));
97122
switch (desc) {
98123
// Guard isn't be needed because we turn an empty string into None during extraction

stdlib/queue.gr

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* @module Queue: An immutable queue implementation. A queue is a FIFO (first-in-first-out) data structure where new values are added to the end and retrieved or removed from the beginning.
33
* @example import Queue from "queue"
44
* @since v0.2.0
5+
*
6+
* @deprecated This module will be renamed to ImmutableQueue in the v0.6.0 release of Grain.
57
*/
68
import List from "list"
79

@@ -20,7 +22,7 @@ record Queue<a> {
2022

2123
/**
2224
* An empty queue.
23-
*
25+
*
2426
* @since v0.5.4
2527
*/
2628
export let empty = {
@@ -30,11 +32,11 @@ export let empty = {
3032

3133
/**
3234
* Creates an empty queue.
33-
*
35+
*
3436
* @returns An empty queue
35-
*
37+
*
3638
* @deprecated This will be removed in the v0.6.0 release of Grain.
37-
*
39+
*
3840
* @since v0.2.0
3941
*/
4042
export let make = () => {
@@ -43,7 +45,7 @@ export let make = () => {
4345

4446
/**
4547
* Checks if the given queue contains any values.
46-
*
48+
*
4749
* @param queue: The queue to check
4850
* @returns `true` if the given queue is empty or `false` otherwise
4951
*
@@ -58,7 +60,7 @@ export let isEmpty = queue => {
5860

5961
/**
6062
* Returns the value at the beginning of the queue. It is not removed from the queue.
61-
*
63+
*
6264
* @param queue: The queue to inspect
6365
* @returns `Some(value)` containing the value at the beginning of the queue, or `None` if the queue is empty
6466
*
@@ -76,7 +78,7 @@ export let peek = queue => {
7678

7779
/**
7880
* Adds a value to the end of the queue.
79-
*
81+
*
8082
* @param value: The value to append
8183
* @param queue: The queue to update
8284
* @returns An updated queue
@@ -95,7 +97,7 @@ export let push = (value, queue) => {
9597

9698
/**
9799
* Dequeues the next value in the queue.
98-
*
100+
*
99101
* @param queue: The queue to change
100102
* @returns An updated queue
101103
*
@@ -119,7 +121,7 @@ export let pop = queue => {
119121

120122
/**
121123
* Get the number of values in a queue.
122-
*
124+
*
123125
* @param queue: The queue to inspect
124126
* @returns The number of values in the queue
125127
*

stdlib/queue.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Queue
33
---
44

5+
> **Deprecated:** This module will be renamed to ImmutableQueue in the v0.6.0 release of Grain.
6+
57
An immutable queue implementation. A queue is a FIFO (first-in-first-out) data structure where new values are added to the end and retrieved or removed from the beginning.
68

79
<details disabled>

stdlib/stack.gr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* @module Stack: An immutable stack implementation. A stack is a LIFO (last-in-first-out) data structure where new values are added, retrieved, and removed from the end.
33
* @example import Stack from "stack"
4+
*
5+
* @deprecated This module will be renamed to ImmutableStack in the v0.6.0 release of Grain.
46
*/
57

68
import List from "list"
@@ -22,7 +24,7 @@ record Stack<a> {
2224

2325
/**
2426
* An empty stack.
25-
*
27+
*
2628
* @since v0.5.4
2729
*/
2830
export let empty = {
@@ -34,7 +36,7 @@ export let empty = {
3436
* Creates a new stack.
3537
*
3638
* @returns An empty stack
37-
*
39+
*
3840
* @deprecated This will be removed in the v0.6.0 release of Grain.
3941
*/
4042
export let make = () => {

stdlib/stack.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Stack
33
---
44

5+
> **Deprecated:** This module will be renamed to ImmutableStack in the v0.6.0 release of Grain.
6+
57
An immutable stack implementation. A stack is a LIFO (last-in-first-out) data structure where new values are added, retrieved, and removed from the end.
68

79
```grain

0 commit comments

Comments
 (0)