Ruby 4.1.0dev (2026-04-04 revision 3b6245536cf55da9e8bfcdb03c845fe9ef931d7f)
Macros | Typedefs | Functions | Variables
options.h File Reference

(3b6245536cf55da9e8bfcdb03c845fe9ef931d7f)

The options that can be passed to parsing. More...

#include "prism/compiler/exported.h"
#include "prism/compiler/nodiscard.h"
#include "prism/compiler/nonnull.h"
#include "prism/stringy.h"
#include <stdbool.h>
#include <stddef.h>
Include dependency graph for options.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED   ((int8_t) -1)
 String literals should not be frozen.
 
#define PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET   ((int8_t) 0)
 String literals may be frozen or mutable depending on the implementation default.
 
#define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED   ((int8_t) 1)
 String literals should be made frozen.
 

Typedefs

typedef struct pm_options_scope_t pm_options_scope_t
 A scope of locals surrounding the code that is being parsed.
 
typedef struct pm_options_t pm_options_t
 The options that can be passed to the parser.
 
typedef 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 by the runtime.
 

Functions

PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_options_tpm_options_new (void)
 Allocate a new 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 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 const pm_string_tpm_options_filepath (const pm_options_t *options) PRISM_NONNULL(1)
 Get the filepath 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_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_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_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_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 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 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 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_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_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 bool pm_options_freeze (const pm_options_t *options) PRISM_NONNULL(1)
 Get the freeze option on the given options struct.
 
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_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.
 
PRISM_EXPORTED_FUNCTION const pm_options_scope_tpm_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 pm_options_scope_tpm_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 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 const pm_string_tpm_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.
 
PRISM_EXPORTED_FUNCTION pm_string_tpm_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_scope_forwarding_set (pm_options_scope_t *scope, uint8_t forwarding) PRISM_NONNULL(1)
 Set the forwarding option on the given scope struct.
 

Variables

static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE = 0x0
 The default value for parameters.
 
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS = 0x1
 When the scope is forwarding with the * parameter.
 
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS = 0x2
 When the scope is forwarding with the ** parameter.
 
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_BLOCK = 0x4
 When the scope is forwarding with the & parameter.
 
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_ALL = 0x8
 When the scope is forwarding with the ... parameter.
 
static const uint8_t PM_OPTIONS_COMMAND_LINE_A = 0x1
 A bit representing whether or not the command line -a option was set.
 
static const uint8_t PM_OPTIONS_COMMAND_LINE_E = 0x2
 A bit representing whether or not the command line -e option was set.
 
static const uint8_t PM_OPTIONS_COMMAND_LINE_L = 0x4
 A bit representing whether or not the command line -l option was set.
 
static const uint8_t PM_OPTIONS_COMMAND_LINE_N = 0x8
 A bit representing whether or not the command line -n option was set.
 
static const uint8_t PM_OPTIONS_COMMAND_LINE_P = 0x10
 A bit representing whether or not the command line -p option was set.
 
static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20
 A bit representing whether or not the command line -x option was set.
 

Detailed Description

The options that can be passed to parsing.

Definition in file options.h.

Macro Definition Documentation

◆ PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED

#define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED   ((int8_t) -1)

String literals should not be frozen.

Definition at line 31 of file options.h.

◆ PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED

#define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED   ((int8_t) 1)

String literals should be made frozen.

Definition at line 42 of file options.h.

◆ PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET

#define PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET   ((int8_t) 0)

String literals may be frozen or mutable depending on the implementation default.

Definition at line 37 of file options.h.

Typedef Documentation

◆ pm_options_scope_t

A scope of locals surrounding the code that is being parsed.

Definition at line 21 of file options.h.

◆ pm_options_shebang_callback_t

typedef 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 by the runtime.

Parameters
optionsThe options struct that may be updated by this callback. Certain fields will be checked for changes, specifically encoding, command_line, and frozen_string_literal.
sourceThe source of the shebang comment.
lengthThe length of the source.
shebang_callback_dataAny additional data that should be passed along to the callback.

Definition at line 71 of file options.h.

◆ pm_options_t

typedef struct pm_options_t pm_options_t

The options that can be passed to the parser.

Definition at line 26 of file options.h.

Function Documentation

◆ pm_options_command_line_set()

PRISM_EXPORTED_FUNCTION void pm_options_command_line_set ( pm_options_t options,
uint8_t  command_line 
)

Sets the command line option on the given options struct.

Parameters
optionsThe options struct to set the command line option on.
command_lineThe command_line value to set.

Definition at line 116 of file options.c.

◆ pm_options_encoding_locked_set()

PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set ( pm_options_t options,
bool  encoding_locked 
)

Set the encoding_locked option on the given options struct.

Parameters
optionsThe options struct to set the encoding_locked value on.
encoding_lockedThe encoding_locked value to set.

Definition at line 92 of file options.c.

◆ pm_options_encoding_set()

PRISM_EXPORTED_FUNCTION void pm_options_encoding_set ( pm_options_t options,
const char *  encoding 
)

Set the encoding option on the given options struct.

Parameters
optionsThe options struct to set the encoding on.
encodingThe encoding to set.

Definition at line 84 of file options.c.

◆ pm_options_filepath()

PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_filepath ( const pm_options_t options)

Get the filepath option on the given options struct.

Parameters
optionsThe options struct to get the filepath from.
Returns
The filepath.

Definition at line 68 of file options.c.

◆ pm_options_filepath_set()

PRISM_EXPORTED_FUNCTION void pm_options_filepath_set ( pm_options_t options,
const char *  filepath 
)

Set the filepath option on the given options struct.

Parameters
optionsThe options struct to set the filepath on.
filepathThe filepath to set.

Definition at line 76 of file options.c.

◆ pm_options_free()

PRISM_EXPORTED_FUNCTION void pm_options_free ( pm_options_t options)

Free both the held memory of the given options struct and the struct itself.

Parameters
optionsThe options struct to free.

Definition at line 50 of file options.c.

◆ pm_options_freeze()

PRISM_EXPORTED_FUNCTION bool pm_options_freeze ( const pm_options_t options)

Get the freeze option on the given options struct.

Parameters
optionsThe options struct to get the freeze value from.
Returns
The freeze value.

Definition at line 234 of file options.c.

◆ pm_options_freeze_set()

PRISM_EXPORTED_FUNCTION void pm_options_freeze_set ( pm_options_t options,
bool  freeze 
)

Set the freeze option on the given options struct.

Parameters
optionsThe options struct to set the freeze value on.
freezeThe freeze value to set.

Definition at line 242 of file options.c.

◆ pm_options_frozen_string_literal_set()

PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set ( pm_options_t options,
bool  frozen_string_literal 
)

Set the frozen string literal option on the given options struct.

Parameters
optionsThe options struct to set the frozen string literal value on.
frozen_string_literalThe frozen string literal value to set.

Definition at line 108 of file options.c.

◆ pm_options_line_set()

PRISM_EXPORTED_FUNCTION void pm_options_line_set ( pm_options_t options,
int32_t  line 
)

Set the line option on the given options struct.

Parameters
optionsThe options struct to set the line on.
lineThe line to set.

Definition at line 100 of file options.c.

◆ pm_options_main_script_set()

PRISM_EXPORTED_FUNCTION void pm_options_main_script_set ( pm_options_t options,
bool  main_script 
)

Set the main script option on the given options struct.

Parameters
optionsThe options struct to set the main script value on.
main_scriptThe main script value to set.

Definition at line 218 of file options.c.

◆ pm_options_new()

Allocate a new options struct.

If the options struct cannot be allocated, this function aborts the process.

Returns
A new options struct with default values. It is the responsibility of the caller to free this struct using pm_options_free().

If the options struct cannot be allocated, this function aborts the process.

Definition at line 17 of file options.c.

◆ pm_options_partial_script_set()

PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set ( pm_options_t options,
bool  partial_script 
)

Set the partial script option on the given options struct.

Parameters
optionsThe options struct to set the partial script value on.
partial_scriptThe partial script value to set.

Definition at line 226 of file options.c.

◆ pm_options_scope()

PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope ( const pm_options_t options,
size_t  index 
)

Return a constant pointer to the scope at the given index within the given options.

Parameters
optionsThe options struct to get the scope from.
indexThe index of the scope to get.
Returns
A constant pointer to the scope at the given index.

Definition at line 269 of file options.c.

◆ pm_options_scope_forwarding_set()

PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set ( pm_options_scope_t scope,
uint8_t  forwarding 
)

Set the forwarding option on the given scope struct.

Parameters
scopeThe scope struct to set the forwarding on.
forwardingThe forwarding value to set.

Definition at line 316 of file options.c.

◆ pm_options_scope_init()

PRISM_EXPORTED_FUNCTION void pm_options_scope_init ( pm_options_scope_t scope,
size_t  locals_count 
)

Create a new options scope struct.

This will hold a set of locals that are in scope surrounding the code that is being parsed. If the scope was unable to allocate its locals, this function will abort the process.

Parameters
scopeThe scope struct to initialize.
locals_countThe number of locals to allocate.

This will hold a set of locals that are in scope surrounding the code that is being parsed.

Definition at line 287 of file options.c.

◆ pm_options_scope_local()

PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local ( const pm_options_scope_t scope,
size_t  index 
)

Return a constant pointer to the local at the given index within the given scope.

Parameters
scopeThe scope struct to get the local from.
indexThe index of the local to get.
Returns
A constant pointer to the local at the given index.

Definition at line 299 of file options.c.

◆ pm_options_scope_local_mut()

PRISM_EXPORTED_FUNCTION pm_string_t * pm_options_scope_local_mut ( pm_options_scope_t scope,
size_t  index 
)

Return a mutable pointer to the local at the given index within the given scope.

Parameters
scopeThe scope struct to get the local from.
indexThe index of the local to get.
Returns
A mutable pointer to the local at the given index.

Definition at line 308 of file options.c.

◆ pm_options_scope_mut()

PRISM_EXPORTED_FUNCTION pm_options_scope_t * pm_options_scope_mut ( pm_options_t options,
size_t  index 
)

Return a mutable pointer to the scope at the given index within the given options.

Parameters
optionsThe options struct to get the scope from.
indexThe index of the scope to get.
Returns
A mutable pointer to the scope at the given index.

Definition at line 278 of file options.c.

◆ pm_options_scopes_init()

PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init ( pm_options_t options,
size_t  scopes_count 
)

Allocate and zero out the scopes array on the given options struct.

Parameters
optionsThe options struct to initialize the scopes array on.
scopes_countThe number of scopes to allocate.
Returns
Whether or not the scopes array was initialized successfully.

Definition at line 258 of file options.c.

◆ pm_options_shebang_callback_set()

PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set ( pm_options_t options,
pm_options_shebang_callback_t  shebang_callback,
void *  shebang_callback_data 
)

Set the shebang callback option on the given options struct.

Parameters
optionsThe options struct to set the shebang callback on.
shebang_callbackThe shebang callback to set.
shebang_callback_dataAny additional data that should be passed along to the callback.

Definition at line 59 of file options.c.

◆ pm_options_version_set()

PRISM_EXPORTED_FUNCTION bool pm_options_version_set ( pm_options_t options,
const char *  version,
size_t  length 
)

Set the version option on the given options struct by parsing the given string.

If the string contains an invalid option, this returns false. Otherwise, it returns true.

Parameters
optionsThe options struct to set the version on.
versionThe version to set.
lengthThe length of the version string.
Returns
Whether or not the version was parsed successfully.

If the string contains an invalid option, this returns false. Otherwise, it returns true.

Definition at line 134 of file options.c.

◆ pm_options_version_set_highest()

PRISM_EXPORTED_FUNCTION void pm_options_version_set_highest ( pm_options_t options)

Set the version option on the given options struct to the highest version of Ruby that prism supports.

Parameters
optionsThe options struct to set the version on.

Definition at line 210 of file options.c.

◆ pm_options_version_set_lowest()

PRISM_EXPORTED_FUNCTION void pm_options_version_set_lowest ( pm_options_t options)

Set the version option on the given options struct to the lowest version of Ruby that prism supports.

Parameters
optionsThe options struct to set the version on.

Definition at line 201 of file options.c.

Variable Documentation

◆ PM_OPTIONS_COMMAND_LINE_A

const uint8_t PM_OPTIONS_COMMAND_LINE_A = 0x1
static

A bit representing whether or not the command line -a option was set.

-a splits the input line $_ into $F.

Definition at line 77 of file options.h.

◆ PM_OPTIONS_COMMAND_LINE_E

const uint8_t PM_OPTIONS_COMMAND_LINE_E = 0x2
static

A bit representing whether or not the command line -e option was set.

-e allow the user to specify a script to be executed. This is necessary for prism to know because certain warnings are not generated when -e is used.

Definition at line 84 of file options.h.

◆ PM_OPTIONS_COMMAND_LINE_L

const uint8_t PM_OPTIONS_COMMAND_LINE_L = 0x4
static

A bit representing whether or not the command line -l option was set.

-l chomps the input line by default.

Definition at line 90 of file options.h.

◆ PM_OPTIONS_COMMAND_LINE_N

const uint8_t PM_OPTIONS_COMMAND_LINE_N = 0x8
static

A bit representing whether or not the command line -n option was set.

-n wraps the script in a while gets loop.

Definition at line 96 of file options.h.

◆ PM_OPTIONS_COMMAND_LINE_P

const uint8_t PM_OPTIONS_COMMAND_LINE_P = 0x10
static

A bit representing whether or not the command line -p option was set.

-p prints the value of $_ at the end of each loop.

Definition at line 102 of file options.h.

◆ PM_OPTIONS_COMMAND_LINE_X

const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20
static

A bit representing whether or not the command line -x option was set.

-x searches the input file for a shebang that matches the current Ruby engine.

Definition at line 108 of file options.h.

◆ PM_OPTIONS_SCOPE_FORWARDING_ALL

const uint8_t PM_OPTIONS_SCOPE_FORWARDING_ALL = 0x8
static

When the scope is forwarding with the ... parameter.

Definition at line 57 of file options.h.

◆ PM_OPTIONS_SCOPE_FORWARDING_BLOCK

const uint8_t PM_OPTIONS_SCOPE_FORWARDING_BLOCK = 0x4
static

When the scope is forwarding with the & parameter.

Definition at line 54 of file options.h.

◆ PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS

const uint8_t PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS = 0x2
static

When the scope is forwarding with the ** parameter.

Definition at line 51 of file options.h.

◆ PM_OPTIONS_SCOPE_FORWARDING_NONE

const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE = 0x0
static

The default value for parameters.

Definition at line 45 of file options.h.

Referenced by pm_options_scope_init().

◆ PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS

const uint8_t PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS = 0x1
static

When the scope is forwarding with the * parameter.

Definition at line 48 of file options.h.