Ruby
4.1.0dev (2026-10-28 revision 1b06b950bb460d20a9dcecb8b97d363adbf4a358)
prism
internal
comments.h
1
#ifndef PRISM_INTERNAL_COMMENTS_H
2
#define PRISM_INTERNAL_COMMENTS_H
3
4
#include "
prism/comments.h
"
5
#include "
prism/parser.h
"
6
7
#include "prism/internal/list.h"
8
9
#include <stdint.h>
10
11
/* A comment found while parsing. */
12
struct
pm_comment_t
{
13
/* The embedded base node. */
14
pm_list_node_t
node;
15
16
/* The location of the comment in the source. */
17
pm_location_t
location;
18
19
/* The type of the comment. */
20
pm_comment_type_t
type;
21
};
22
23
/*
24
* The result of attaching comments to the nodes that own them. All of the
25
* arrays are allocated in the parser's metadata arena.
26
*/
27
typedef
struct
{
28
/* The comments found while parsing, sorted by start offset. */
29
const
pm_comment_t
**comments;
30
31
/*
32
* Indices into comments, grouped by owning node in order of node id and
33
* sorted by start offset within each group. A node's comments are not
34
* necessarily contiguous in comments, because a child can own a comment
35
* that falls between two comments owned by its parent.
36
*/
37
uint32_t *attachments;
38
39
/* The slice of attachments for each node, indexed by node id. */
40
pm_comment_range_t
*ranges;
41
42
/* The number of entries in ranges. */
43
uint32_t ranges_size;
44
}
pm_comment_attachments_t
;
45
46
/*
47
* Sort the parser's comment list in place by start offset, then assign every
48
* comment to the node that owns it. This is called after parsing when the
49
* attach_comments option is set, before the parser's scratch arena is released,
50
* because the walk allocates from it.
51
*/
52
void
pm_comments_attach(
pm_parser_t
*parser,
const
pm_node_t
*root);
53
54
#endif
comments.h
Types and functions related to comments found during parsing.
pm_comment_type_t
pm_comment_type_t
This is the type of a comment that we've found while parsing.
Definition
comments.h:22
parser.h
The parser used to parse Ruby source.
pm_comment_attachments_t
Definition
comments.h:27
pm_comment_range_t
The comments owned by a node, as a slice of the comment attachments of the parser that produced it.
Definition
comments.h:34
pm_comment_t
Definition
comments.h:12
pm_list_node
Definition
list.h:36
pm_location_t
This struct represents a slice in the source code, defined by an offset and a length.
Definition
ast.h:579
pm_node
This is the base structure that represents a node in the syntax tree.
Definition
ast.h:1090
pm_parser_t
Definition
parser.h:588
Generated by
1.9.8