Ruby 4.1.0dev (2026-04-01 revision 9c827a49ccefc0b945b25a479cdd9ba0a156a21c)
source.h
1#ifndef PRISM_INTERNAL_SOURCE_H
2#define PRISM_INTERNAL_SOURCE_H
3
4#include "prism/source.h"
5#include "prism/buffer.h"
6
7#include <stdbool.h>
8
9/*
10 * The type of source, which determines cleanup behavior.
11 */
12typedef enum {
13 /* Wraps existing constant memory, no cleanup. */
14 PM_SOURCE_CONSTANT,
15
16 /* Wraps existing shared memory (non-owning slice), no cleanup. */
17 PM_SOURCE_SHARED,
18
19 /* Owns a heap-allocated buffer, freed on cleanup. */
20 PM_SOURCE_OWNED,
21
22 /* Memory-mapped file, unmapped on cleanup. */
23 PM_SOURCE_MAPPED,
24
25 /* Stream source backed by a pm_buffer_t. */
26 PM_SOURCE_STREAM
27} pm_source_type_t;
28
29/*
30 * The internal representation of a source.
31 */
33 /* A pointer to the start of the source data. */
34 const uint8_t *source;
35
36 /* The length of the source data in bytes. */
37 size_t length;
38
39 /* The type of the source. */
40 pm_source_type_t type;
41
42 /* Stream-specific data, only used for PM_SOURCE_STREAM sources. */
43 struct {
44 /* The buffer that holds the accumulated stream data. */
45 pm_buffer_t *buffer;
46
47 /* The stream object to read from. */
48 void *stream;
49
50 /* The function to use to read from the stream. */
52
53 /* The function to use to check if the stream is at EOF. */
55
56 /* Whether the stream has reached EOF. */
57 bool eof;
58 } stream;
59};
60
61/*
62 * Read from a stream into the source's internal buffer. This is used by
63 * pm_parse_stream to incrementally read the source.
64 */
65bool pm_source_stream_read(pm_source_t *source);
66
67/*
68 * Returns whether the stream source has reached EOF.
69 */
70bool pm_source_stream_eof(const pm_source_t *source);
71
72#endif
A wrapper around a contiguous block of allocated memory.
An opaque type representing the source code being parsed, regardless of origin (constant memory,...
int() pm_source_stream_feof_t(void *stream)
This function is used to check whether a stream is at EOF.
Definition source.h:34
char *() pm_source_stream_fgets_t(char *string, int size, void *stream)
This function is used to retrieve a line of input from a stream.
Definition source.h:28
C99 shim for <stdbool.h>