prism 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +50 -1
- data/Makefile +5 -2
- data/README.md +45 -6
- data/config.yml +499 -4
- data/docs/build_system.md +31 -0
- data/docs/configuration.md +2 -0
- data/docs/cruby_compilation.md +1 -1
- data/docs/parser_translation.md +14 -9
- data/docs/releasing.md +2 -2
- data/docs/ripper_translation.md +50 -0
- data/docs/ruby_api.md +1 -0
- data/docs/serialization.md +26 -5
- data/ext/prism/api_node.c +911 -815
- data/ext/prism/api_pack.c +9 -0
- data/ext/prism/extconf.rb +27 -11
- data/ext/prism/extension.c +313 -66
- data/ext/prism/extension.h +5 -4
- data/include/prism/ast.h +213 -64
- data/include/prism/defines.h +106 -2
- data/include/prism/diagnostic.h +134 -71
- data/include/prism/encoding.h +22 -4
- data/include/prism/node.h +93 -0
- data/include/prism/options.h +82 -7
- data/include/prism/pack.h +11 -0
- data/include/prism/parser.h +198 -53
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/static_literals.h +118 -0
- data/include/prism/util/pm_buffer.h +65 -2
- data/include/prism/util/pm_constant_pool.h +18 -1
- data/include/prism/util/pm_integer.h +119 -0
- data/include/prism/util/pm_list.h +1 -1
- data/include/prism/util/pm_newline_list.h +8 -0
- data/include/prism/util/pm_string.h +26 -2
- data/include/prism/version.h +2 -2
- data/include/prism.h +59 -1
- data/lib/prism/compiler.rb +8 -1
- data/lib/prism/debug.rb +46 -3
- data/lib/prism/desugar_compiler.rb +1 -1
- data/lib/prism/dispatcher.rb +29 -0
- data/lib/prism/dot_visitor.rb +87 -16
- data/lib/prism/dsl.rb +24 -12
- data/lib/prism/ffi.rb +67 -12
- data/lib/prism/lex_compat.rb +17 -15
- data/lib/prism/mutation_compiler.rb +11 -0
- data/lib/prism/node.rb +2096 -2499
- data/lib/prism/node_ext.rb +77 -29
- data/lib/prism/pack.rb +4 -0
- data/lib/prism/parse_result/comments.rb +34 -17
- data/lib/prism/parse_result/newlines.rb +3 -1
- data/lib/prism/parse_result.rb +78 -32
- data/lib/prism/pattern.rb +16 -4
- data/lib/prism/polyfill/string.rb +12 -0
- data/lib/prism/serialize.rb +439 -102
- data/lib/prism/translation/parser/compiler.rb +152 -50
- data/lib/prism/translation/parser/lexer.rb +103 -22
- data/lib/prism/translation/parser/rubocop.rb +41 -13
- data/lib/prism/translation/parser.rb +119 -7
- data/lib/prism/translation/parser33.rb +1 -1
- data/lib/prism/translation/parser34.rb +1 -1
- data/lib/prism/translation/ripper/sexp.rb +125 -0
- data/lib/prism/translation/ripper/shim.rb +5 -0
- data/lib/prism/translation/ripper.rb +3212 -462
- data/lib/prism/translation/ruby_parser.rb +35 -18
- data/lib/prism/translation.rb +3 -1
- data/lib/prism/visitor.rb +10 -0
- data/lib/prism.rb +8 -2
- data/prism.gemspec +33 -4
- data/rbi/prism/compiler.rbi +14 -0
- data/rbi/prism/desugar_compiler.rbi +5 -0
- data/rbi/prism/mutation_compiler.rbi +5 -0
- data/rbi/prism/node.rbi +8221 -0
- data/rbi/prism/node_ext.rbi +102 -0
- data/rbi/prism/parse_result.rbi +304 -0
- data/rbi/prism/translation/parser/compiler.rbi +13 -0
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
- data/rbi/prism/translation/ripper.rbi +25 -0
- data/rbi/prism/translation/ruby_parser.rbi +11 -0
- data/rbi/prism/visitor.rbi +470 -0
- data/rbi/prism.rbi +39 -7749
- data/sig/prism/compiler.rbs +9 -0
- data/sig/prism/dispatcher.rbs +16 -0
- data/sig/prism/dot_visitor.rbs +6 -0
- data/sig/prism/dsl.rbs +462 -0
- data/sig/prism/mutation_compiler.rbs +158 -0
- data/sig/prism/node.rbs +3529 -0
- data/sig/prism/node_ext.rbs +78 -0
- data/sig/prism/pack.rbs +43 -0
- data/sig/prism/parse_result.rbs +127 -0
- data/sig/prism/pattern.rbs +13 -0
- data/sig/prism/serialize.rbs +7 -0
- data/sig/prism/visitor.rbs +168 -0
- data/sig/prism.rbs +188 -4767
- data/src/diagnostic.c +575 -230
- data/src/encoding.c +211 -108
- data/src/node.c +7526 -447
- data/src/options.c +36 -12
- data/src/pack.c +33 -17
- data/src/prettyprint.c +1294 -1385
- data/src/prism.c +3628 -1099
- data/src/regexp.c +17 -2
- data/src/serialize.c +47 -28
- data/src/static_literals.c +552 -0
- data/src/token_type.c +1 -0
- data/src/util/pm_buffer.c +147 -20
- data/src/util/pm_char.c +4 -4
- data/src/util/pm_constant_pool.c +35 -11
- data/src/util/pm_integer.c +629 -0
- data/src/util/pm_list.c +1 -1
- data/src/util/pm_newline_list.c +14 -5
- data/src/util/pm_string.c +134 -5
- data/src/util/pm_string_list.c +2 -2
- metadata +35 -6
- data/docs/ripper.md +0 -36
- data/rbi/prism_static.rbi +0 -207
- data/sig/prism_static.rbs +0 -201
data/src/options.c
CHANGED
@@ -29,7 +29,15 @@ pm_options_line_set(pm_options_t *options, int32_t line) {
|
|
29
29
|
*/
|
30
30
|
PRISM_EXPORTED_FUNCTION void
|
31
31
|
pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal) {
|
32
|
-
options->frozen_string_literal = frozen_string_literal;
|
32
|
+
options->frozen_string_literal = frozen_string_literal ? PM_OPTIONS_FROZEN_STRING_LITERAL_ENABLED : PM_OPTIONS_FROZEN_STRING_LITERAL_DISABLED;
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Sets the command line option on the given options struct.
|
37
|
+
*/
|
38
|
+
PRISM_EXPORTED_FUNCTION void
|
39
|
+
pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
40
|
+
options->command_line = command_line;
|
33
41
|
}
|
34
42
|
|
35
43
|
/**
|
@@ -64,14 +72,22 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
|
|
64
72
|
return false;
|
65
73
|
}
|
66
74
|
|
75
|
+
// For some reason, GCC analyzer thinks we're leaking allocated scopes and
|
76
|
+
// locals here, even though we definitely aren't. This is a false positive.
|
77
|
+
// Ideally we wouldn't need to suppress this.
|
78
|
+
#if defined(__GNUC__) && (__GNUC__ >= 10)
|
79
|
+
#pragma GCC diagnostic push
|
80
|
+
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
|
81
|
+
#endif
|
82
|
+
|
67
83
|
/**
|
68
84
|
* Allocate and zero out the scopes array on the given options struct.
|
69
85
|
*/
|
70
|
-
PRISM_EXPORTED_FUNCTION
|
86
|
+
PRISM_EXPORTED_FUNCTION bool
|
71
87
|
pm_options_scopes_init(pm_options_t *options, size_t scopes_count) {
|
72
88
|
options->scopes_count = scopes_count;
|
73
|
-
options->scopes =
|
74
|
-
|
89
|
+
options->scopes = xcalloc(scopes_count, sizeof(pm_options_scope_t));
|
90
|
+
return options->scopes != NULL;
|
75
91
|
}
|
76
92
|
|
77
93
|
/**
|
@@ -86,11 +102,11 @@ pm_options_scope_get(const pm_options_t *options, size_t index) {
|
|
86
102
|
* Create a new options scope struct. This will hold a set of locals that are in
|
87
103
|
* scope surrounding the code that is being parsed.
|
88
104
|
*/
|
89
|
-
PRISM_EXPORTED_FUNCTION
|
105
|
+
PRISM_EXPORTED_FUNCTION bool
|
90
106
|
pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count) {
|
91
107
|
scope->locals_count = locals_count;
|
92
|
-
scope->locals =
|
93
|
-
|
108
|
+
scope->locals = xcalloc(locals_count, sizeof(pm_string_t));
|
109
|
+
return scope->locals != NULL;
|
94
110
|
}
|
95
111
|
|
96
112
|
/**
|
@@ -116,10 +132,10 @@ pm_options_free(pm_options_t *options) {
|
|
116
132
|
pm_string_free(&scope->locals[local_index]);
|
117
133
|
}
|
118
134
|
|
119
|
-
|
135
|
+
xfree(scope->locals);
|
120
136
|
}
|
121
137
|
|
122
|
-
|
138
|
+
xfree(options->scopes);
|
123
139
|
}
|
124
140
|
|
125
141
|
/**
|
@@ -185,21 +201,25 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
185
201
|
data += encoding_length;
|
186
202
|
}
|
187
203
|
|
188
|
-
options->frozen_string_literal = *data++;
|
204
|
+
options->frozen_string_literal = (int8_t) *data++;
|
205
|
+
options->command_line = (uint8_t) *data++;
|
189
206
|
options->version = (pm_options_version_t) *data++;
|
190
207
|
|
191
208
|
uint32_t scopes_count = pm_options_read_u32(data);
|
192
209
|
data += 4;
|
193
210
|
|
194
211
|
if (scopes_count > 0) {
|
195
|
-
pm_options_scopes_init(options, scopes_count);
|
212
|
+
if (!pm_options_scopes_init(options, scopes_count)) return;
|
196
213
|
|
197
214
|
for (size_t scope_index = 0; scope_index < scopes_count; scope_index++) {
|
198
215
|
uint32_t locals_count = pm_options_read_u32(data);
|
199
216
|
data += 4;
|
200
217
|
|
201
218
|
pm_options_scope_t *scope = &options->scopes[scope_index];
|
202
|
-
pm_options_scope_init(scope, locals_count)
|
219
|
+
if (!pm_options_scope_init(scope, locals_count)) {
|
220
|
+
pm_options_free(options);
|
221
|
+
return;
|
222
|
+
}
|
203
223
|
|
204
224
|
for (size_t local_index = 0; local_index < locals_count; local_index++) {
|
205
225
|
uint32_t local_length = pm_options_read_u32(data);
|
@@ -211,3 +231,7 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
211
231
|
}
|
212
232
|
}
|
213
233
|
}
|
234
|
+
|
235
|
+
#if defined(__GNUC__) && (__GNUC__ >= 10)
|
236
|
+
#pragma GCC diagnostic pop
|
237
|
+
#endif
|
data/src/pack.c
CHANGED
@@ -1,16 +1,43 @@
|
|
1
1
|
#include "prism/pack.h"
|
2
2
|
|
3
|
+
// We optionally support parsing String#pack templates. For systems that don't
|
4
|
+
// want or need this functionality, it can be turned off with the
|
5
|
+
// PRISM_EXCLUDE_PACK define.
|
6
|
+
#ifdef PRISM_EXCLUDE_PACK
|
7
|
+
|
8
|
+
void pm_pack_parse(void) {}
|
9
|
+
|
10
|
+
#else
|
11
|
+
|
3
12
|
#include <stdbool.h>
|
4
13
|
#include <errno.h>
|
5
14
|
|
6
15
|
static uintmax_t
|
7
|
-
strtoumaxc(const char **format)
|
16
|
+
strtoumaxc(const char **format) {
|
17
|
+
uintmax_t value = 0;
|
18
|
+
while (**format >= '0' && **format <= '9') {
|
19
|
+
if (value > UINTMAX_MAX / 10) {
|
20
|
+
errno = ERANGE;
|
21
|
+
}
|
22
|
+
value = value * 10 + ((uintmax_t) (**format - '0'));
|
23
|
+
(*format)++;
|
24
|
+
}
|
25
|
+
return value;
|
26
|
+
}
|
8
27
|
|
9
28
|
PRISM_EXPORTED_FUNCTION pm_pack_result
|
10
|
-
pm_pack_parse(
|
11
|
-
|
12
|
-
|
13
|
-
|
29
|
+
pm_pack_parse(
|
30
|
+
pm_pack_variant variant,
|
31
|
+
const char **format,
|
32
|
+
const char *format_end,
|
33
|
+
pm_pack_type *type,
|
34
|
+
pm_pack_signed *signed_type,
|
35
|
+
pm_pack_endian *endian,
|
36
|
+
pm_pack_size *size,
|
37
|
+
pm_pack_length_type *length_type,
|
38
|
+
uint64_t *length,
|
39
|
+
pm_pack_encoding *encoding
|
40
|
+
) {
|
14
41
|
if (*encoding == PM_PACK_ENCODING_START) {
|
15
42
|
*encoding = PM_PACK_ENCODING_US_ASCII;
|
16
43
|
}
|
@@ -479,15 +506,4 @@ pm_size_to_native(pm_pack_size size) {
|
|
479
506
|
}
|
480
507
|
}
|
481
508
|
|
482
|
-
|
483
|
-
strtoumaxc(const char **format) {
|
484
|
-
uintmax_t value = 0;
|
485
|
-
while (**format >= '0' && **format <= '9') {
|
486
|
-
if (value > UINTMAX_MAX / 10) {
|
487
|
-
errno = ERANGE;
|
488
|
-
}
|
489
|
-
value = value * 10 + ((uintmax_t) (**format - '0'));
|
490
|
-
(*format)++;
|
491
|
-
}
|
492
|
-
return value;
|
493
|
-
}
|
509
|
+
#endif
|