prism 1.9.0 → 2.0.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +88 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.md +1 -1
- data/Makefile +41 -12
- data/README.md +35 -97
- data/config.yml +174 -161
- data/docs/build_system.md +2 -2
- data/docs/configuration.md +5 -4
- data/docs/encoding.md +2 -2
- data/docs/fuzzing.md +4 -11
- data/docs/javascript.md +19 -4
- data/docs/mapping.md +1 -1
- data/docs/releasing.md +77 -5
- data/docs/relocation.md +2 -4
- data/docs/serialization.md +22 -24
- data/docs/testing.md +46 -29
- data/ext/prism/api_node.c +1461 -1401
- data/ext/prism/extconf.rb +3 -4
- data/ext/prism/extension.c +796 -422
- data/ext/prism/extension.h +3 -3
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +2727 -610
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +26 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/bswap.h +46 -0
- data/include/prism/compiler/endianness.h +34 -0
- data/include/prism/compiler/exported.h +24 -0
- data/include/prism/compiler/fallthrough.h +22 -0
- data/include/prism/compiler/filesystem.h +32 -0
- data/include/prism/compiler/flex_array.h +19 -0
- data/include/prism/compiler/force_inline.h +21 -0
- data/include/prism/compiler/format.h +25 -0
- data/include/prism/compiler/inline.h +17 -0
- data/include/prism/compiler/nodiscard.h +22 -0
- data/include/prism/compiler/nonnull.h +18 -0
- data/include/prism/compiler/unused.h +18 -0
- data/include/prism/constant_pool.h +81 -0
- data/include/prism/diagnostic.h +38 -403
- data/include/prism/errors_format.h +53 -0
- data/include/prism/excludes.h +29 -0
- data/include/prism/integer.h +41 -0
- data/include/prism/internal/allocator.h +68 -0
- data/include/prism/internal/allocator_debug.h +88 -0
- data/include/prism/internal/arena.h +108 -0
- data/include/prism/internal/bit.h +42 -0
- data/include/prism/internal/buffer.h +94 -0
- data/include/prism/internal/char.h +145 -0
- data/include/prism/internal/comments.h +53 -0
- data/include/prism/internal/constant_pool.h +152 -0
- data/include/prism/internal/diagnostic.h +389 -0
- data/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/include/prism/internal/integer.h +68 -0
- data/include/prism/internal/isinf.h +16 -0
- data/include/prism/internal/line_offset_list.h +34 -0
- data/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/include/prism/internal/magic_comments.h +23 -0
- data/include/prism/internal/memchr.h +15 -0
- data/include/prism/internal/node.h +38 -0
- data/include/prism/internal/options.h +232 -0
- data/include/prism/internal/parser.h +1004 -0
- data/include/prism/internal/regexp.h +26 -0
- data/include/prism/internal/serialize.h +39 -0
- data/include/prism/internal/source.h +72 -0
- data/include/prism/{static_literals.h → internal/static_literals.h} +26 -47
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/internal/xxh3.h +16 -0
- data/include/prism/json.h +32 -0
- data/include/prism/line_offset_list.h +61 -0
- data/include/prism/magic_comments.h +35 -0
- data/include/prism/node.h +18 -53
- data/include/prism/options.h +146 -280
- data/include/prism/parser.h +356 -867
- data/include/prism/prettyprint.h +6 -9
- data/include/prism/serialize.h +115 -0
- data/include/prism/source.h +155 -0
- data/include/prism/stream.h +28 -0
- data/include/prism/string_query.h +74 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +12 -3
- data/include/prism.h +43 -320
- data/lib/prism/compiler.rb +319 -305
- data/lib/prism/desugar_compiler.rb +105 -34
- data/lib/prism/dispatcher.rb +646 -473
- data/lib/prism/dot_visitor.rb +592 -511
- data/lib/prism/dsl.rb +391 -25
- data/lib/prism/ffi.rb +258 -90
- data/lib/prism/inspect_visitor.rb +357 -325
- data/lib/prism/lex_compat.rb +254 -212
- data/lib/prism/mutation_compiler.rb +313 -305
- data/lib/prism/node.rb +20966 -6992
- data/lib/prism/node_ext.rb +180 -187
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +7 -1
- data/lib/prism/parse_result/newlines.rb +276 -8
- data/lib/prism/parse_result.rb +468 -139
- data/lib/prism/pattern.rb +65 -20
- data/lib/prism/reflection.rb +23 -12
- data/lib/prism/relocation.rb +149 -87
- data/lib/prism/serialize.rb +3460 -539
- data/lib/prism/string_query.rb +24 -1
- data/lib/prism/translation/parser/builder.rb +10 -2
- data/lib/prism/translation/parser/compiler.rb +44 -52
- data/lib/prism/translation/parser/lexer.rb +41 -92
- data/lib/prism/translation/parser.rb +1 -1
- data/lib/prism/translation/parser_current.rb +1 -1
- data/lib/prism/translation/ripper/lexer.rb +8 -10
- data/lib/prism/translation/ripper/sexp.rb +2 -10
- data/lib/prism/translation/ripper/shim.rb +2 -0
- data/lib/prism/translation/ripper.rb +967 -209
- data/lib/prism/translation/ruby_parser.rb +73 -316
- data/lib/prism/translation.rb +2 -0
- data/lib/prism/visitor.rb +632 -5
- data/lib/prism.rb +79 -9
- data/prism.gemspec +128 -62
- data/rbi/generated/prism/compiler.rbi +489 -0
- data/rbi/generated/prism/desugar_compiler.rbi +306 -0
- data/rbi/generated/prism/dispatcher.rbi +1138 -0
- data/rbi/generated/prism/dot_visitor.rbi +618 -0
- data/rbi/generated/prism/dsl.rbi +751 -0
- data/rbi/generated/prism/inspect_visitor.rbi +503 -0
- data/rbi/generated/prism/lex_compat.rbi +162 -0
- data/rbi/generated/prism/mutation_compiler.rbi +464 -0
- data/rbi/generated/prism/node.rbi +14407 -0
- data/rbi/generated/prism/node_ext.rbi +259 -0
- data/rbi/generated/prism/node_find.rbi +79 -0
- data/rbi/generated/prism/parse_result/errors.rbi +21 -0
- data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
- data/rbi/generated/prism/parse_result.rbi +776 -0
- data/rbi/generated/prism/pattern.rbi +134 -0
- data/rbi/generated/prism/reflection.rbi +89 -0
- data/rbi/generated/prism/relocation.rbi +329 -0
- data/rbi/generated/prism/serialize.rbi +184 -0
- data/rbi/generated/prism/string_query.rbi +43 -0
- data/rbi/generated/prism/translation.rbi +7 -0
- data/rbi/generated/prism/visitor.rbi +650 -0
- data/rbi/generated/prism.rbi +86 -0
- data/rbi/prism/translation/parser_versions.rbi +5 -0
- data/rbi/rubyvm/node_find.rbi +14 -0
- data/sig/generated/prism/compiler.rbs +492 -0
- data/sig/generated/prism/desugar_compiler.rbs +305 -0
- data/sig/generated/prism/dispatcher.rbs +1292 -0
- data/sig/generated/prism/dot_visitor.rbs +635 -0
- data/sig/generated/prism/dsl.rbs +928 -0
- data/sig/generated/prism/inspect_visitor.rbs +509 -0
- data/sig/generated/prism/lex_compat.rbs +166 -0
- data/sig/{prism → generated/prism}/mutation_compiler.rbs +309 -4
- data/sig/generated/prism/node.rbs +20896 -0
- data/sig/generated/prism/node_ext.rbs +290 -0
- data/sig/generated/prism/node_find.rbs +90 -0
- data/sig/generated/prism/parse_result/errors.rbs +22 -0
- data/sig/generated/prism/parse_result/newlines.rbs +223 -0
- data/sig/generated/prism/parse_result.rbs +871 -0
- data/sig/generated/prism/pattern.rbs +156 -0
- data/sig/generated/prism/reflection.rbs +101 -0
- data/sig/generated/prism/relocation.rbs +428 -0
- data/sig/generated/prism/serialize.rbs +198 -0
- data/sig/generated/prism/string_query.rbs +43 -0
- data/sig/generated/prism/translation.rbs +8 -0
- data/sig/generated/prism/visitor.rbs +1111 -0
- data/sig/generated/prism.rbs +84 -0
- data/sig/manifest.yaml +2 -0
- data/src/arena.c +117 -0
- data/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/src/{util/pm_char.c → char.c} +28 -57
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +97 -65
- data/src/encoding.c +8 -3
- data/src/errors_format.c +519 -0
- data/src/{util/pm_integer.c → integer.c} +33 -22
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/src/node.c +3504 -7674
- data/src/options.c +162 -49
- data/src/parser.c +367 -0
- data/src/prettyprint.c +421 -354
- data/src/prism.c +8402 -7161
- data/src/regexp.c +961 -45
- data/src/serialize.c +460 -424
- data/src/source.c +518 -0
- data/src/static_literals.c +111 -43
- data/src/string_query.c +180 -0
- data/src/stringy.c +91 -0
- data/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/src/strpbrk.c +447 -0
- data/src/{token_type.c → tokens.c} +39 -18
- data/src/xxh3.c +292 -0
- metadata +128 -63
- data/ext/prism/api_pack.c +0 -276
- data/include/prism/defines.h +0 -260
- data/include/prism/pack.h +0 -163
- data/include/prism/regexp.h +0 -43
- data/include/prism/util/pm_buffer.h +0 -236
- data/include/prism/util/pm_char.h +0 -204
- data/include/prism/util/pm_constant_pool.h +0 -218
- data/include/prism/util/pm_integer.h +0 -130
- data/include/prism/util/pm_memchr.h +0 -29
- data/include/prism/util/pm_newline_list.h +0 -113
- data/include/prism/util/pm_string.h +0 -200
- data/lib/prism/pack.rb +0 -230
- data/lib/prism/parse_result/comments.rb +0 -188
- data/rbi/prism/compiler.rbi +0 -12
- data/rbi/prism/dsl.rbi +0 -524
- data/rbi/prism/inspect_visitor.rbi +0 -12
- data/rbi/prism/node.rbi +0 -8750
- data/rbi/prism/node_ext.rbi +0 -107
- data/rbi/prism/parse_result.rbi +0 -404
- data/rbi/prism/reflection.rbi +0 -58
- data/rbi/prism/string_query.rbi +0 -12
- data/rbi/prism/visitor.rbi +0 -473
- data/rbi/prism.rbi +0 -63
- data/sig/prism/compiler.rbs +0 -9
- data/sig/prism/dispatcher.rbs +0 -19
- data/sig/prism/dot_visitor.rbs +0 -6
- data/sig/prism/dsl.rbs +0 -351
- data/sig/prism/inspect_visitor.rbs +0 -22
- data/sig/prism/lex_compat.rbs +0 -10
- data/sig/prism/node.rbs +0 -4042
- data/sig/prism/node_ext.rbs +0 -149
- data/sig/prism/pack.rbs +0 -43
- data/sig/prism/parse_result/comments.rbs +0 -38
- data/sig/prism/parse_result.rbs +0 -197
- data/sig/prism/pattern.rbs +0 -13
- data/sig/prism/reflection.rbs +0 -50
- data/sig/prism/relocation.rbs +0 -185
- data/sig/prism/serialize.rbs +0 -8
- data/sig/prism/string_query.rbs +0 -11
- data/sig/prism/visitor.rbs +0 -169
- data/sig/prism.rbs +0 -272
- data/src/pack.c +0 -509
- data/src/util/pm_constant_pool.c +0 -342
- data/src/util/pm_list.c +0 -49
- data/src/util/pm_newline_list.c +0 -125
- data/src/util/pm_string.c +0 -381
- data/src/util/pm_strpbrk.c +0 -206
data/include/prism/options.h
CHANGED
|
@@ -6,16 +6,27 @@
|
|
|
6
6
|
#ifndef PRISM_OPTIONS_H
|
|
7
7
|
#define PRISM_OPTIONS_H
|
|
8
8
|
|
|
9
|
-
#include "prism/
|
|
10
|
-
#include "prism/
|
|
11
|
-
#include "prism/
|
|
9
|
+
#include "prism/compiler/exported.h"
|
|
10
|
+
#include "prism/compiler/nodiscard.h"
|
|
11
|
+
#include "prism/compiler/nonnull.h"
|
|
12
|
+
|
|
13
|
+
#include "prism/stringy.h"
|
|
12
14
|
|
|
13
15
|
#include <stdbool.h>
|
|
14
16
|
#include <stddef.h>
|
|
15
|
-
#include <stdint.h>
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* A scope of locals surrounding the code that is being parsed.
|
|
20
|
+
*/
|
|
21
|
+
typedef struct pm_options_scope_t pm_options_scope_t;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The options that can be passed to the parser.
|
|
25
|
+
*/
|
|
26
|
+
typedef struct pm_options_t pm_options_t;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* String literals should not be frozen.
|
|
19
30
|
*/
|
|
20
31
|
#define PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED ((int8_t) -1)
|
|
21
32
|
|
|
@@ -26,42 +37,25 @@
|
|
|
26
37
|
#define PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET ((int8_t) 0)
|
|
27
38
|
|
|
28
39
|
/**
|
|
29
|
-
* String literals should be made
|
|
40
|
+
* String literals should be made frozen.
|
|
30
41
|
*/
|
|
31
42
|
#define PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED ((int8_t) 1)
|
|
32
43
|
|
|
33
|
-
/**
|
|
34
|
-
* A scope of locals surrounding the code that is being parsed.
|
|
35
|
-
*/
|
|
36
|
-
typedef struct pm_options_scope {
|
|
37
|
-
/** The number of locals in the scope. */
|
|
38
|
-
size_t locals_count;
|
|
39
|
-
|
|
40
|
-
/** The names of the locals in the scope. */
|
|
41
|
-
pm_string_t *locals;
|
|
42
|
-
|
|
43
|
-
/** Flags for the set of forwarding parameters in this scope. */
|
|
44
|
-
uint8_t forwarding;
|
|
45
|
-
} pm_options_scope_t;
|
|
46
|
-
|
|
47
44
|
/** The default value for parameters. */
|
|
48
45
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE = 0x0;
|
|
49
46
|
|
|
50
|
-
/** When the scope is
|
|
47
|
+
/** When the scope is forwarding with the * parameter. */
|
|
51
48
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS = 0x1;
|
|
52
49
|
|
|
53
|
-
/** When the scope is
|
|
50
|
+
/** When the scope is forwarding with the ** parameter. */
|
|
54
51
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS = 0x2;
|
|
55
52
|
|
|
56
|
-
/** When the scope is
|
|
53
|
+
/** When the scope is forwarding with the & parameter. */
|
|
57
54
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_BLOCK = 0x4;
|
|
58
55
|
|
|
59
|
-
/** When the scope is
|
|
56
|
+
/** When the scope is forwarding with the ... parameter. */
|
|
60
57
|
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_ALL = 0x8;
|
|
61
58
|
|
|
62
|
-
// Forward declaration needed by the callback typedef.
|
|
63
|
-
struct pm_options;
|
|
64
|
-
|
|
65
59
|
/**
|
|
66
60
|
* The callback called when additional switches are found in a shebang comment
|
|
67
61
|
* that need to be processed by the runtime.
|
|
@@ -74,130 +68,7 @@ struct pm_options;
|
|
|
74
68
|
* @param shebang_callback_data Any additional data that should be passed along
|
|
75
69
|
* to the callback.
|
|
76
70
|
*/
|
|
77
|
-
typedef void (*pm_options_shebang_callback_t)(
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The version of Ruby syntax that we should be parsing with. This is used to
|
|
81
|
-
* allow consumers to specify which behavior they want in case they need to
|
|
82
|
-
* parse in the same way as a specific version of CRuby would have.
|
|
83
|
-
*/
|
|
84
|
-
typedef enum {
|
|
85
|
-
/** If an explicit version is not provided, the current version of prism will be used. */
|
|
86
|
-
PM_OPTIONS_VERSION_UNSET = 0,
|
|
87
|
-
|
|
88
|
-
/** The vendored version of prism in CRuby 3.3.x. */
|
|
89
|
-
PM_OPTIONS_VERSION_CRUBY_3_3 = 1,
|
|
90
|
-
|
|
91
|
-
/** The vendored version of prism in CRuby 3.4.x. */
|
|
92
|
-
PM_OPTIONS_VERSION_CRUBY_3_4 = 2,
|
|
93
|
-
|
|
94
|
-
/** The vendored version of prism in CRuby 4.0.x. */
|
|
95
|
-
PM_OPTIONS_VERSION_CRUBY_3_5 = 3,
|
|
96
|
-
|
|
97
|
-
/** The vendored version of prism in CRuby 4.0.x. */
|
|
98
|
-
PM_OPTIONS_VERSION_CRUBY_4_0 = 3,
|
|
99
|
-
|
|
100
|
-
/** The vendored version of prism in CRuby 4.1.x. */
|
|
101
|
-
PM_OPTIONS_VERSION_CRUBY_4_1 = 4,
|
|
102
|
-
|
|
103
|
-
/** The current version of prism. */
|
|
104
|
-
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_1
|
|
105
|
-
} pm_options_version_t;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* The options that can be passed to the parser.
|
|
109
|
-
*/
|
|
110
|
-
typedef struct pm_options {
|
|
111
|
-
/**
|
|
112
|
-
* The callback to call when additional switches are found in a shebang
|
|
113
|
-
* comment.
|
|
114
|
-
*/
|
|
115
|
-
pm_options_shebang_callback_t shebang_callback;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Any additional data that should be passed along to the shebang callback
|
|
119
|
-
* if one was set.
|
|
120
|
-
*/
|
|
121
|
-
void *shebang_callback_data;
|
|
122
|
-
|
|
123
|
-
/** The name of the file that is currently being parsed. */
|
|
124
|
-
pm_string_t filepath;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* The line within the file that the parse starts on. This value is
|
|
128
|
-
* 1-indexed.
|
|
129
|
-
*/
|
|
130
|
-
int32_t line;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* The name of the encoding that the source file is in. Note that this must
|
|
134
|
-
* correspond to a name that can be found with Encoding.find in Ruby.
|
|
135
|
-
*/
|
|
136
|
-
pm_string_t encoding;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* The number of scopes surrounding the code that is being parsed.
|
|
140
|
-
*/
|
|
141
|
-
size_t scopes_count;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* The scopes surrounding the code that is being parsed. For most parses
|
|
145
|
-
* this will be NULL, but for evals it will be the locals that are in scope
|
|
146
|
-
* surrounding the eval. Scopes are ordered from the outermost scope to the
|
|
147
|
-
* innermost one.
|
|
148
|
-
*/
|
|
149
|
-
pm_options_scope_t *scopes;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The version of prism that we should be parsing with. This is used to
|
|
153
|
-
* allow consumers to specify which behavior they want in case they need to
|
|
154
|
-
* parse exactly as a specific version of CRuby.
|
|
155
|
-
*/
|
|
156
|
-
pm_options_version_t version;
|
|
157
|
-
|
|
158
|
-
/** A bitset of the various options that were set on the command line. */
|
|
159
|
-
uint8_t command_line;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Whether or not the frozen string literal option has been set.
|
|
163
|
-
* May be:
|
|
164
|
-
* - PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED
|
|
165
|
-
* - PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED
|
|
166
|
-
* - PM_OPTIONS_FROZEN_STRING_LITERAL_UNSET
|
|
167
|
-
*/
|
|
168
|
-
int8_t frozen_string_literal;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Whether or not the encoding magic comments should be respected. This is a
|
|
172
|
-
* niche use-case where you want to parse a file with a specific encoding
|
|
173
|
-
* but ignore any encoding magic comments at the top of the file.
|
|
174
|
-
*/
|
|
175
|
-
bool encoding_locked;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* When the file being parsed is the main script, the shebang will be
|
|
179
|
-
* considered for command-line flags (or for implicit -x). The caller needs
|
|
180
|
-
* to pass this information to the parser so that it can behave correctly.
|
|
181
|
-
*/
|
|
182
|
-
bool main_script;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* When the file being parsed is considered a "partial" script, jumps will
|
|
186
|
-
* not be marked as errors if they are not contained within loops/blocks.
|
|
187
|
-
* This is used in the case that you're parsing a script that you know will
|
|
188
|
-
* be embedded inside another script later, but you do not have that context
|
|
189
|
-
* yet. For example, when parsing an ERB template that will be evaluated
|
|
190
|
-
* inside another script.
|
|
191
|
-
*/
|
|
192
|
-
bool partial_script;
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Whether or not the parser should freeze the nodes that it creates. This
|
|
196
|
-
* makes it possible to have a deeply frozen AST that is safe to share
|
|
197
|
-
* between concurrency primitives.
|
|
198
|
-
*/
|
|
199
|
-
bool freeze;
|
|
200
|
-
} pm_options_t;
|
|
71
|
+
typedef void (*pm_options_shebang_callback_t)(pm_options_t *options, const uint8_t *source, size_t length, void *shebang_callback_data);
|
|
201
72
|
|
|
202
73
|
/**
|
|
203
74
|
* A bit representing whether or not the command line -a option was set. -a
|
|
@@ -232,10 +103,26 @@ static const uint8_t PM_OPTIONS_COMMAND_LINE_P = 0x10;
|
|
|
232
103
|
|
|
233
104
|
/**
|
|
234
105
|
* A bit representing whether or not the command line -x option was set. -x
|
|
235
|
-
* searches the input file for a shebang that
|
|
106
|
+
* searches the input file for a shebang that includes "ruby".
|
|
236
107
|
*/
|
|
237
108
|
static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20;
|
|
238
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Allocate a new options struct. If the options struct cannot be allocated,
|
|
112
|
+
* this function aborts the process.
|
|
113
|
+
*
|
|
114
|
+
* @returns A new options struct with default values. It is the responsibility
|
|
115
|
+
* of the caller to free this struct using pm_options_free().
|
|
116
|
+
*/
|
|
117
|
+
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_options_t * pm_options_new(void);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Free both the held memory of the given options struct and the struct itself.
|
|
121
|
+
*
|
|
122
|
+
* @param options The options struct to free.
|
|
123
|
+
*/
|
|
124
|
+
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options) PRISM_NONNULL(1);
|
|
125
|
+
|
|
239
126
|
/**
|
|
240
127
|
* Set the shebang callback option on the given options struct.
|
|
241
128
|
*
|
|
@@ -243,70 +130,64 @@ static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20;
|
|
|
243
130
|
* @param shebang_callback The shebang callback to set.
|
|
244
131
|
* @param shebang_callback_data Any additional data that should be passed along
|
|
245
132
|
* to the callback.
|
|
133
|
+
*/
|
|
134
|
+
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);
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get the filepath option on the given options struct.
|
|
246
138
|
*
|
|
247
|
-
*
|
|
139
|
+
* @param options The options struct to get the filepath from.
|
|
140
|
+
* @returns The filepath.
|
|
248
141
|
*/
|
|
249
|
-
PRISM_EXPORTED_FUNCTION
|
|
142
|
+
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_filepath(const pm_options_t *options) PRISM_NONNULL(1);
|
|
250
143
|
|
|
251
144
|
/**
|
|
252
145
|
* Set the filepath option on the given options struct.
|
|
253
146
|
*
|
|
254
147
|
* @param options The options struct to set the filepath on.
|
|
255
148
|
* @param filepath The filepath to set.
|
|
256
|
-
*
|
|
257
|
-
* \public \memberof pm_options
|
|
258
149
|
*/
|
|
259
|
-
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath);
|
|
150
|
+
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath) PRISM_NONNULL(1);
|
|
260
151
|
|
|
261
152
|
/**
|
|
262
153
|
* Set the line option on the given options struct.
|
|
263
154
|
*
|
|
264
155
|
* @param options The options struct to set the line on.
|
|
265
156
|
* @param line The line to set.
|
|
266
|
-
*
|
|
267
|
-
* \public \memberof pm_options
|
|
268
157
|
*/
|
|
269
|
-
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
|
|
158
|
+
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line) PRISM_NONNULL(1);
|
|
270
159
|
|
|
271
160
|
/**
|
|
272
161
|
* Set the encoding option on the given options struct.
|
|
273
162
|
*
|
|
274
163
|
* @param options The options struct to set the encoding on.
|
|
275
164
|
* @param encoding The encoding to set.
|
|
276
|
-
*
|
|
277
|
-
* \public \memberof pm_options
|
|
278
165
|
*/
|
|
279
|
-
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding);
|
|
166
|
+
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding) PRISM_NONNULL(1);
|
|
280
167
|
|
|
281
168
|
/**
|
|
282
169
|
* Set the encoding_locked option on the given options struct.
|
|
283
170
|
*
|
|
284
171
|
* @param options The options struct to set the encoding_locked value on.
|
|
285
172
|
* @param encoding_locked The encoding_locked value to set.
|
|
286
|
-
*
|
|
287
|
-
* \public \memberof pm_options
|
|
288
173
|
*/
|
|
289
|
-
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked);
|
|
174
|
+
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) PRISM_NONNULL(1);
|
|
290
175
|
|
|
291
176
|
/**
|
|
292
177
|
* Set the frozen string literal option on the given options struct.
|
|
293
178
|
*
|
|
294
179
|
* @param options The options struct to set the frozen string literal value on.
|
|
295
180
|
* @param frozen_string_literal The frozen string literal value to set.
|
|
296
|
-
*
|
|
297
|
-
* \public \memberof pm_options
|
|
298
181
|
*/
|
|
299
|
-
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal);
|
|
182
|
+
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) PRISM_NONNULL(1);
|
|
300
183
|
|
|
301
184
|
/**
|
|
302
185
|
* Sets the command line option on the given options struct.
|
|
303
186
|
*
|
|
304
187
|
* @param options The options struct to set the command line option on.
|
|
305
188
|
* @param command_line The command_line value to set.
|
|
306
|
-
*
|
|
307
|
-
* \public \memberof pm_options
|
|
308
189
|
*/
|
|
309
|
-
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line);
|
|
190
|
+
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line) PRISM_NONNULL(1);
|
|
310
191
|
|
|
311
192
|
/**
|
|
312
193
|
* Set the version option on the given options struct by parsing the given
|
|
@@ -316,173 +197,158 @@ PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options,
|
|
|
316
197
|
* @param options The options struct to set the version on.
|
|
317
198
|
* @param version The version to set.
|
|
318
199
|
* @param length The length of the version string.
|
|
319
|
-
* @
|
|
200
|
+
* @returns Whether or not the version was parsed successfully.
|
|
201
|
+
*/
|
|
202
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length) PRISM_NONNULL(1);
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Set the version option on the given options struct to the lowest version of
|
|
206
|
+
* Ruby that prism supports.
|
|
207
|
+
*
|
|
208
|
+
* @param options The options struct to set the version on.
|
|
209
|
+
*/
|
|
210
|
+
PRISM_EXPORTED_FUNCTION void pm_options_version_set_lowest(pm_options_t *options) PRISM_NONNULL(1);
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Set the version option on the given options struct to the highest version of
|
|
214
|
+
* Ruby that prism supports.
|
|
320
215
|
*
|
|
321
|
-
*
|
|
216
|
+
* @param options The options struct to set the version on.
|
|
322
217
|
*/
|
|
323
|
-
PRISM_EXPORTED_FUNCTION
|
|
218
|
+
PRISM_EXPORTED_FUNCTION void pm_options_version_set_highest(pm_options_t *options) PRISM_NONNULL(1);
|
|
324
219
|
|
|
325
220
|
/**
|
|
326
221
|
* Set the main script option on the given options struct.
|
|
327
222
|
*
|
|
328
223
|
* @param options The options struct to set the main script value on.
|
|
329
224
|
* @param main_script The main script value to set.
|
|
330
|
-
*
|
|
331
|
-
* \public \memberof pm_options
|
|
332
225
|
*/
|
|
333
|
-
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script);
|
|
226
|
+
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script) PRISM_NONNULL(1);
|
|
334
227
|
|
|
335
228
|
/**
|
|
336
229
|
* Set the partial script option on the given options struct.
|
|
337
230
|
*
|
|
338
231
|
* @param options The options struct to set the partial script value on.
|
|
339
232
|
* @param partial_script The partial script value to set.
|
|
233
|
+
*/
|
|
234
|
+
PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script) PRISM_NONNULL(1);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get the freeze option on the given options struct.
|
|
340
238
|
*
|
|
341
|
-
*
|
|
239
|
+
* @param options The options struct to get the freeze value from.
|
|
240
|
+
* @returns The freeze value.
|
|
342
241
|
*/
|
|
343
|
-
PRISM_EXPORTED_FUNCTION
|
|
242
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_freeze(const pm_options_t *options) PRISM_NONNULL(1);
|
|
344
243
|
|
|
345
244
|
/**
|
|
346
245
|
* Set the freeze option on the given options struct.
|
|
347
246
|
*
|
|
348
247
|
* @param options The options struct to set the freeze value on.
|
|
349
248
|
* @param freeze The freeze value to set.
|
|
249
|
+
*/
|
|
250
|
+
PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool freeze) PRISM_NONNULL(1);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Get the attach_comments option on the given options struct.
|
|
254
|
+
*
|
|
255
|
+
* @param options The options struct to get the attach_comments value from.
|
|
256
|
+
* @returns The attach_comments value.
|
|
257
|
+
*/
|
|
258
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_attach_comments(const pm_options_t *options) PRISM_NONNULL(1);
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Set the attach_comments option on the given options struct. When this is
|
|
262
|
+
* set, the parser's comment list is sorted by start offset after parsing and
|
|
263
|
+
* every comment is assigned an owning node. Without it, comments are left in
|
|
264
|
+
* the order they were lexed and no nodes own any comments.
|
|
350
265
|
*
|
|
351
|
-
*
|
|
266
|
+
* @param options The options struct to set the attach_comments value on.
|
|
267
|
+
* @param attach_comments The attach_comments value to set.
|
|
352
268
|
*/
|
|
353
|
-
PRISM_EXPORTED_FUNCTION void
|
|
269
|
+
PRISM_EXPORTED_FUNCTION void pm_options_attach_comments_set(pm_options_t *options, bool attach_comments) PRISM_NONNULL(1);
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Get the raise_error option on the given options struct.
|
|
273
|
+
*
|
|
274
|
+
* @param options The options struct to get the raise_error value from.
|
|
275
|
+
* @returns The raise_error value.
|
|
276
|
+
*/
|
|
277
|
+
PRISM_EXPORTED_FUNCTION uint8_t pm_options_raise_error(const pm_options_t *options) PRISM_NONNULL(1);
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Set the raise_error option on the given options struct.
|
|
281
|
+
*
|
|
282
|
+
* @param options The options struct to set the raise_error value on.
|
|
283
|
+
* @param raise_error The raise_error value to set.
|
|
284
|
+
*/
|
|
285
|
+
PRISM_EXPORTED_FUNCTION void pm_options_raise_error_set(pm_options_t *options, uint8_t raise_error) PRISM_NONNULL(1);
|
|
354
286
|
|
|
355
287
|
/**
|
|
356
288
|
* Allocate and zero out the scopes array on the given options struct.
|
|
357
289
|
*
|
|
358
290
|
* @param options The options struct to initialize the scopes array on.
|
|
359
291
|
* @param scopes_count The number of scopes to allocate.
|
|
360
|
-
* @
|
|
361
|
-
*
|
|
362
|
-
* \public \memberof pm_options
|
|
292
|
+
* @returns Whether or not the scopes array was initialized successfully.
|
|
363
293
|
*/
|
|
364
|
-
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count);
|
|
294
|
+
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count) PRISM_NONNULL(1);
|
|
365
295
|
|
|
366
296
|
/**
|
|
367
|
-
* Return a pointer to the scope at the given index within the given
|
|
297
|
+
* Return a constant pointer to the scope at the given index within the given
|
|
298
|
+
* options.
|
|
368
299
|
*
|
|
369
300
|
* @param options The options struct to get the scope from.
|
|
370
301
|
* @param index The index of the scope to get.
|
|
371
|
-
* @
|
|
302
|
+
* @returns A constant pointer to the scope at the given index.
|
|
303
|
+
*/
|
|
304
|
+
PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope(const pm_options_t *options, size_t index) PRISM_NONNULL(1);
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Return a mutable pointer to the scope at the given index within the given
|
|
308
|
+
* options.
|
|
372
309
|
*
|
|
373
|
-
*
|
|
310
|
+
* @param options The options struct to get the scope from.
|
|
311
|
+
* @param index The index of the scope to get.
|
|
312
|
+
* @returns A mutable pointer to the scope at the given index.
|
|
374
313
|
*/
|
|
375
|
-
PRISM_EXPORTED_FUNCTION
|
|
314
|
+
PRISM_EXPORTED_FUNCTION pm_options_scope_t * pm_options_scope_mut(pm_options_t *options, size_t index) PRISM_NONNULL(1);
|
|
376
315
|
|
|
377
316
|
/**
|
|
378
317
|
* Create a new options scope struct. This will hold a set of locals that are in
|
|
379
|
-
* scope surrounding the code that is being parsed.
|
|
318
|
+
* scope surrounding the code that is being parsed. If the scope was unable to
|
|
319
|
+
* allocate its locals, this function will abort the process.
|
|
380
320
|
*
|
|
381
321
|
* @param scope The scope struct to initialize.
|
|
382
322
|
* @param locals_count The number of locals to allocate.
|
|
383
|
-
* @return Whether or not the scope was initialized successfully.
|
|
384
|
-
*
|
|
385
|
-
* \public \memberof pm_options
|
|
386
323
|
*/
|
|
387
|
-
PRISM_EXPORTED_FUNCTION
|
|
324
|
+
PRISM_EXPORTED_FUNCTION void pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) PRISM_NONNULL(1);
|
|
388
325
|
|
|
389
326
|
/**
|
|
390
|
-
* Return a pointer to the local at the given index within the given
|
|
327
|
+
* Return a constant pointer to the local at the given index within the given
|
|
328
|
+
* scope.
|
|
391
329
|
*
|
|
392
330
|
* @param scope The scope struct to get the local from.
|
|
393
331
|
* @param index The index of the local to get.
|
|
394
|
-
* @
|
|
395
|
-
*
|
|
396
|
-
* \public \memberof pm_options
|
|
397
|
-
*/
|
|
398
|
-
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local_get(const pm_options_scope_t *scope, size_t index);
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Set the forwarding option on the given scope struct.
|
|
402
|
-
*
|
|
403
|
-
* @param scope The scope struct to set the forwarding on.
|
|
404
|
-
* @param forwarding The forwarding value to set.
|
|
405
|
-
*
|
|
406
|
-
* \public \memberof pm_options
|
|
332
|
+
* @returns A constant pointer to the local at the given index.
|
|
407
333
|
*/
|
|
408
|
-
PRISM_EXPORTED_FUNCTION
|
|
334
|
+
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local(const pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1);
|
|
409
335
|
|
|
410
336
|
/**
|
|
411
|
-
*
|
|
337
|
+
* Return a mutable pointer to the local at the given index within the given
|
|
338
|
+
* scope.
|
|
412
339
|
*
|
|
413
|
-
* @param
|
|
414
|
-
*
|
|
415
|
-
*
|
|
340
|
+
* @param scope The scope struct to get the local from.
|
|
341
|
+
* @param index The index of the local to get.
|
|
342
|
+
* @returns A mutable pointer to the local at the given index.
|
|
416
343
|
*/
|
|
417
|
-
PRISM_EXPORTED_FUNCTION
|
|
344
|
+
PRISM_EXPORTED_FUNCTION pm_string_t * pm_options_scope_local_mut(pm_options_scope_t *scope, size_t index) PRISM_NONNULL(1);
|
|
418
345
|
|
|
419
346
|
/**
|
|
420
|
-
*
|
|
421
|
-
* pass options to the parser from an FFI call so that consumers of the library
|
|
422
|
-
* from an FFI perspective don't have to worry about the structure of our
|
|
423
|
-
* options structs. Since the source of these calls will be from Ruby
|
|
424
|
-
* implementation internals we assume it is from a trusted source.
|
|
425
|
-
*
|
|
426
|
-
* `data` is assumed to be a valid pointer pointing to well-formed data. The
|
|
427
|
-
* layout of this data should be the same every time, and is described below:
|
|
428
|
-
*
|
|
429
|
-
* | # bytes | field |
|
|
430
|
-
* | ------- | -------------------------- |
|
|
431
|
-
* | `4` | the length of the filepath |
|
|
432
|
-
* | ... | the filepath bytes |
|
|
433
|
-
* | `4` | the line number |
|
|
434
|
-
* | `4` | the length the encoding |
|
|
435
|
-
* | ... | the encoding bytes |
|
|
436
|
-
* | `1` | frozen string literal |
|
|
437
|
-
* | `1` | -p command line option |
|
|
438
|
-
* | `1` | -n command line option |
|
|
439
|
-
* | `1` | -l command line option |
|
|
440
|
-
* | `1` | -a command line option |
|
|
441
|
-
* | `1` | the version |
|
|
442
|
-
* | `1` | encoding locked |
|
|
443
|
-
* | `1` | main script |
|
|
444
|
-
* | `1` | partial script |
|
|
445
|
-
* | `1` | freeze |
|
|
446
|
-
* | `4` | the number of scopes |
|
|
447
|
-
* | ... | the scopes |
|
|
448
|
-
*
|
|
449
|
-
* The version field is an enum, so it should be one of the following values:
|
|
450
|
-
*
|
|
451
|
-
* | value | version |
|
|
452
|
-
* | ----- | ------------------------- |
|
|
453
|
-
* | `0` | use the latest version of prism |
|
|
454
|
-
* | `1` | use the version of prism that is vendored in CRuby 3.3.0 |
|
|
455
|
-
*
|
|
456
|
-
* Each scope is laid out as follows:
|
|
457
|
-
*
|
|
458
|
-
* | # bytes | field |
|
|
459
|
-
* | ------- | -------------------------- |
|
|
460
|
-
* | `4` | the number of locals |
|
|
461
|
-
* | `1` | the forwarding flags |
|
|
462
|
-
* | ... | the locals |
|
|
463
|
-
*
|
|
464
|
-
* Each local is laid out as follows:
|
|
465
|
-
*
|
|
466
|
-
* | # bytes | field |
|
|
467
|
-
* | ------- | -------------------------- |
|
|
468
|
-
* | `4` | the length of the local |
|
|
469
|
-
* | ... | the local bytes |
|
|
470
|
-
*
|
|
471
|
-
* Some additional things to note about this layout:
|
|
472
|
-
*
|
|
473
|
-
* * The filepath can have a length of 0, in which case we'll consider it an
|
|
474
|
-
* empty string.
|
|
475
|
-
* * The line number should be 0-indexed.
|
|
476
|
-
* * The encoding can have a length of 0, in which case we'll use the default
|
|
477
|
-
* encoding (UTF-8). If it's not 0, it should correspond to a name of an
|
|
478
|
-
* encoding that can be passed to `Encoding.find` in Ruby.
|
|
479
|
-
* * The frozen string literal, encoding locked, main script, and partial script
|
|
480
|
-
* fields are booleans, so their values should be either 0 or 1.
|
|
481
|
-
* * The number of scopes can be 0.
|
|
347
|
+
* Set the forwarding option on the given scope struct.
|
|
482
348
|
*
|
|
483
|
-
* @param
|
|
484
|
-
* @param
|
|
349
|
+
* @param scope The scope struct to set the forwarding on.
|
|
350
|
+
* @param forwarding The forwarding value to set.
|
|
485
351
|
*/
|
|
486
|
-
void
|
|
352
|
+
PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding) PRISM_NONNULL(1);
|
|
487
353
|
|
|
488
354
|
#endif
|