Prism Ruby parser
Loading...
Searching...
No Matches
options.h
Go to the documentation of this file.
1
6#ifndef PRISM_OPTIONS_H
7#define PRISM_OPTIONS_H
8
9#include "prism/compiler/exported.h"
10#include "prism/compiler/nodiscard.h"
11#include "prism/compiler/nonnull.h"
12
13#include "prism/stringy.h"
14
15#include <stdbool.h>
16#include <stddef.h>
17
22
27
31#define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED ((int8_t) -1)
32
37#define PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET ((int8_t) 0)
38
42#define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED ((int8_t) 1)
43
45static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE = 0x0;
46
48static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS = 0x1;
49
51static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS = 0x2;
52
54static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_BLOCK = 0x4;
55
57static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_ALL = 0x8;
58
71typedef void (*pm_options_shebang_callback_t)(pm_options_t *options, const uint8_t *source, size_t length, void *shebang_callback_data);
72
77static const uint8_t PM_OPTIONS_COMMAND_LINE_A = 0x1;
78
84static const uint8_t PM_OPTIONS_COMMAND_LINE_E = 0x2;
85
90static const uint8_t PM_OPTIONS_COMMAND_LINE_L = 0x4;
91
96static const uint8_t PM_OPTIONS_COMMAND_LINE_N = 0x8;
97
102static const uint8_t PM_OPTIONS_COMMAND_LINE_P = 0x10;
103
108static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20;
109
117PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_options_t * pm_options_new(void);
118
124PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options) PRISM_NONNULL(1);
125
134PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data) PRISM_NONNULL(1);
135
142PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_filepath(const pm_options_t *options) PRISM_NONNULL(1);
143
150PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath) PRISM_NONNULL(1);
151
158PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line) PRISM_NONNULL(1);
159
166PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding) PRISM_NONNULL(1);
167
174PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) PRISM_NONNULL(1);
175
182PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) PRISM_NONNULL(1);
183
190PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line) PRISM_NONNULL(1);
191
202PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length) PRISM_NONNULL(1);
203
210PRISM_EXPORTED_FUNCTION void pm_options_version_set_lowest(pm_options_t *options) PRISM_NONNULL(1);
211
218PRISM_EXPORTED_FUNCTION void pm_options_version_set_highest(pm_options_t *options) PRISM_NONNULL(1);
219
226PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script) PRISM_NONNULL(1);
227
234PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script) PRISM_NONNULL(1);
235
242PRISM_EXPORTED_FUNCTION bool pm_options_freeze(const pm_options_t *options) PRISM_NONNULL(1);
243
250PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool freeze) PRISM_NONNULL(1);
251
259PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count) PRISM_NONNULL(1);
260
269PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope(const pm_options_t *options, size_t index) PRISM_NONNULL(1);
270
279PRISM_EXPORTED_FUNCTION pm_options_scope_t * pm_options_scope_mut(pm_options_t *options, size_t index) PRISM_NONNULL(1);
280
289PRISM_EXPORTED_FUNCTION void pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) PRISM_NONNULL(1);
290
299PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local(const pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1);
300
309PRISM_EXPORTED_FUNCTION pm_string_t * pm_options_scope_local_mut(pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1);
310
317PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding) PRISM_NONNULL(1);
318
319#endif
PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script) PRISM_NONNULL(1)
Set the partial script option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath) PRISM_NONNULL(1)
Set the filepath option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_version_set_lowest(pm_options_t *options) PRISM_NONNULL(1)
Set the version option on the given options struct to the lowest version of Ruby that prism supports.
PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length) PRISM_NONNULL(1)
Set the version option on the given options struct by parsing the given string.
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count) PRISM_NONNULL(1)
Allocate and zero out the scopes array on the given options struct.
struct pm_options_t pm_options_t
The options that can be passed to the parser.
Definition options.h:26
struct pm_options_scope_t pm_options_scope_t
A scope of locals surrounding the code that is being parsed.
Definition options.h:21
PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding) PRISM_NONNULL(1)
Set the forwarding option on the given scope struct.
PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data) PRISM_NONNULL(1)
Set the shebang callback option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_version_set_highest(pm_options_t *options) PRISM_NONNULL(1)
Set the version option on the given options struct to the highest version of Ruby that prism supports...
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) PRISM_NONNULL(1)
Set the encoding_locked option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line) PRISM_NONNULL(1)
Sets the command line option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) PRISM_NONNULL(1)
Create a new options scope struct.
PRISM_EXPORTED_FUNCTION pm_string_t * pm_options_scope_local_mut(pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1)
Return a mutable pointer to the local at the given index within the given scope.
PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool freeze) PRISM_NONNULL(1)
Set the freeze option on the given options struct.
PRISM_EXPORTED_FUNCTION bool pm_options_freeze(const pm_options_t *options) PRISM_NONNULL(1)
Get the freeze option on the given options struct.
PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope(const pm_options_t *options, size_t index) PRISM_NONNULL(1)
Return a constant pointer to the scope at the given index within the given options.
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script) PRISM_NONNULL(1)
Set the main script option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) PRISM_NONNULL(1)
Set the frozen string literal option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line) PRISM_NONNULL(1)
Set the line option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding) PRISM_NONNULL(1)
Set the encoding option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options) PRISM_NONNULL(1)
Free both the held memory of the given options struct and the struct itself.
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_filepath(const pm_options_t *options) PRISM_NONNULL(1)
Get the filepath option on the given options struct.
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_options_t * pm_options_new(void)
Allocate a new options struct.
void(* pm_options_shebang_callback_t)(pm_options_t *options, const uint8_t *source, size_t length, void *shebang_callback_data)
The callback called when additional switches are found in a shebang comment that need to be processed...
Definition options.h:71
PRISM_EXPORTED_FUNCTION pm_options_scope_t * pm_options_scope_mut(pm_options_t *options, size_t index) PRISM_NONNULL(1)
Return a mutable pointer to the scope at the given index within the given options.
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local(const pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1)
Return a constant pointer to the local at the given index within the given scope.
A generic string type that can have various ownership semantics.
A generic string type that can have various ownership semantics.
Definition stringy.h:18