prism 0.29.0 → 1.3.0
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 +115 -1
- data/CONTRIBUTING.md +0 -4
- data/Makefile +1 -1
- data/README.md +4 -0
- data/config.yml +920 -148
- data/docs/build_system.md +8 -11
- data/docs/fuzzing.md +1 -1
- data/docs/parsing_rules.md +4 -1
- data/docs/relocation.md +34 -0
- data/docs/ripper_translation.md +22 -0
- data/docs/serialization.md +3 -0
- data/ext/prism/api_node.c +2863 -2079
- data/ext/prism/extconf.rb +14 -37
- data/ext/prism/extension.c +241 -391
- data/ext/prism/extension.h +2 -2
- data/include/prism/ast.h +2156 -453
- data/include/prism/defines.h +58 -7
- data/include/prism/diagnostic.h +24 -6
- data/include/prism/node.h +0 -21
- data/include/prism/options.h +94 -3
- data/include/prism/parser.h +82 -40
- data/include/prism/regexp.h +18 -8
- data/include/prism/static_literals.h +3 -2
- data/include/prism/util/pm_char.h +1 -2
- data/include/prism/util/pm_constant_pool.h +0 -8
- data/include/prism/util/pm_integer.h +22 -15
- data/include/prism/util/pm_newline_list.h +11 -0
- data/include/prism/util/pm_string.h +28 -12
- data/include/prism/version.h +3 -3
- data/include/prism.h +47 -11
- data/lib/prism/compiler.rb +3 -0
- data/lib/prism/desugar_compiler.rb +111 -74
- data/lib/prism/dispatcher.rb +16 -1
- data/lib/prism/dot_visitor.rb +55 -34
- data/lib/prism/dsl.rb +660 -468
- data/lib/prism/ffi.rb +113 -8
- data/lib/prism/inspect_visitor.rb +296 -64
- data/lib/prism/lex_compat.rb +1 -1
- data/lib/prism/mutation_compiler.rb +11 -6
- data/lib/prism/node.rb +4262 -5023
- data/lib/prism/node_ext.rb +91 -14
- data/lib/prism/parse_result/comments.rb +0 -7
- data/lib/prism/parse_result/errors.rb +65 -0
- data/lib/prism/parse_result/newlines.rb +101 -11
- data/lib/prism/parse_result.rb +183 -6
- data/lib/prism/reflection.rb +12 -10
- data/lib/prism/relocation.rb +504 -0
- data/lib/prism/serialize.rb +496 -609
- data/lib/prism/string_query.rb +30 -0
- data/lib/prism/translation/parser/compiler.rb +185 -155
- data/lib/prism/translation/parser/lexer.rb +26 -4
- data/lib/prism/translation/parser.rb +9 -4
- data/lib/prism/translation/ripper.rb +23 -25
- data/lib/prism/translation/ruby_parser.rb +86 -17
- data/lib/prism/visitor.rb +3 -0
- data/lib/prism.rb +6 -8
- data/prism.gemspec +9 -5
- data/rbi/prism/dsl.rbi +521 -0
- data/rbi/prism/node.rbi +1115 -1120
- data/rbi/prism/parse_result.rbi +29 -0
- data/rbi/prism/string_query.rbi +12 -0
- data/rbi/prism/visitor.rbi +3 -0
- data/rbi/prism.rbi +36 -30
- data/sig/prism/dsl.rbs +190 -303
- data/sig/prism/mutation_compiler.rbs +1 -0
- data/sig/prism/node.rbs +678 -632
- data/sig/prism/parse_result.rbs +22 -0
- data/sig/prism/relocation.rbs +185 -0
- data/sig/prism/string_query.rbs +11 -0
- data/sig/prism/visitor.rbs +1 -0
- data/sig/prism.rbs +103 -64
- data/src/diagnostic.c +64 -28
- data/src/node.c +502 -1739
- data/src/options.c +76 -27
- data/src/prettyprint.c +188 -112
- data/src/prism.c +3376 -2293
- data/src/regexp.c +208 -71
- data/src/serialize.c +182 -50
- data/src/static_literals.c +64 -85
- data/src/token_type.c +4 -4
- data/src/util/pm_char.c +1 -1
- data/src/util/pm_constant_pool.c +0 -8
- data/src/util/pm_integer.c +53 -25
- data/src/util/pm_newline_list.c +29 -0
- data/src/util/pm_string.c +131 -80
- data/src/util/pm_strpbrk.c +32 -6
- metadata +11 -7
- data/include/prism/util/pm_string_list.h +0 -44
- data/lib/prism/debug.rb +0 -249
- data/lib/prism/translation/parser/rubocop.rb +0 -73
- data/src/util/pm_string_list.c +0 -28
data/src/options.c
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
#include "prism/options.h"
|
2
2
|
|
3
|
+
/**
|
4
|
+
* Set the shebang callback option on the given options struct.
|
5
|
+
*/
|
6
|
+
PRISM_EXPORTED_FUNCTION void
|
7
|
+
pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data) {
|
8
|
+
options->shebang_callback = shebang_callback;
|
9
|
+
options->shebang_callback_data = shebang_callback_data;
|
10
|
+
}
|
11
|
+
|
3
12
|
/**
|
4
13
|
* Set the filepath option on the given options struct.
|
5
14
|
*/
|
@@ -16,6 +25,14 @@ pm_options_encoding_set(pm_options_t *options, const char *encoding) {
|
|
16
25
|
pm_string_constant_init(&options->encoding, encoding, strlen(encoding));
|
17
26
|
}
|
18
27
|
|
28
|
+
/**
|
29
|
+
* Set the encoding_locked option on the given options struct.
|
30
|
+
*/
|
31
|
+
PRISM_EXPORTED_FUNCTION void
|
32
|
+
pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked) {
|
33
|
+
options->encoding_locked = encoding_locked;
|
34
|
+
}
|
35
|
+
|
19
36
|
/**
|
20
37
|
* Set the line option on the given options struct.
|
21
38
|
*/
|
@@ -40,6 +57,14 @@ pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
|
40
57
|
options->command_line = command_line;
|
41
58
|
}
|
42
59
|
|
60
|
+
/**
|
61
|
+
* Checks if the given slice represents a number.
|
62
|
+
*/
|
63
|
+
static inline bool
|
64
|
+
is_number(const char *string, size_t length) {
|
65
|
+
return pm_strspn_decimal_digit((const uint8_t *) string, (ptrdiff_t) length) == length;
|
66
|
+
}
|
67
|
+
|
43
68
|
/**
|
44
69
|
* Set the version option on the given options struct by parsing the given
|
45
70
|
* string. If the string contains an invalid option, this returns false.
|
@@ -47,40 +72,61 @@ pm_options_command_line_set(pm_options_t *options, uint8_t command_line) {
|
|
47
72
|
*/
|
48
73
|
PRISM_EXPORTED_FUNCTION bool
|
49
74
|
pm_options_version_set(pm_options_t *options, const char *version, size_t length) {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
return true;
|
55
|
-
}
|
75
|
+
if (version == NULL) {
|
76
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
77
|
+
return true;
|
78
|
+
}
|
56
79
|
|
57
|
-
|
58
|
-
|
59
|
-
|
80
|
+
if (length == 3) {
|
81
|
+
if (strncmp(version, "3.3", 3) == 0) {
|
82
|
+
options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
|
83
|
+
return true;
|
84
|
+
}
|
60
85
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
86
|
+
if (strncmp(version, "3.4", 3) == 0) {
|
87
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
88
|
+
return true;
|
89
|
+
}
|
65
90
|
|
66
|
-
|
67
|
-
|
68
|
-
return true;
|
69
|
-
}
|
91
|
+
return false;
|
92
|
+
}
|
70
93
|
|
71
|
-
|
72
|
-
|
73
|
-
|
94
|
+
if (length >= 4) {
|
95
|
+
if (strncmp(version, "3.3.", 4) == 0 && is_number(version + 4, length - 4)) {
|
96
|
+
options->version = PM_OPTIONS_VERSION_CRUBY_3_3;
|
97
|
+
return true;
|
98
|
+
}
|
74
99
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
100
|
+
if (strncmp(version, "3.4.", 4) == 0 && is_number(version + 4, length - 4)) {
|
101
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
102
|
+
return true;
|
103
|
+
}
|
104
|
+
}
|
79
105
|
|
80
|
-
|
81
|
-
|
82
|
-
|
106
|
+
if (length >= 6) {
|
107
|
+
if (strncmp(version, "latest", 7) == 0) { // 7 to compare the \0 as well
|
108
|
+
options->version = PM_OPTIONS_VERSION_LATEST;
|
109
|
+
return true;
|
110
|
+
}
|
83
111
|
}
|
112
|
+
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Set the main script option on the given options struct.
|
118
|
+
*/
|
119
|
+
PRISM_EXPORTED_FUNCTION void
|
120
|
+
pm_options_main_script_set(pm_options_t *options, bool main_script) {
|
121
|
+
options->main_script = main_script;
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Set the partial script option on the given options struct.
|
126
|
+
*/
|
127
|
+
PRISM_EXPORTED_FUNCTION void
|
128
|
+
pm_options_partial_script_set(pm_options_t *options, bool partial_script) {
|
129
|
+
options->partial_script = partial_script;
|
84
130
|
}
|
85
131
|
|
86
132
|
// For some reason, GCC analyzer thinks we're leaking allocated scopes and
|
@@ -215,6 +261,9 @@ pm_options_read(pm_options_t *options, const char *data) {
|
|
215
261
|
options->frozen_string_literal = (int8_t) *data++;
|
216
262
|
options->command_line = (uint8_t) *data++;
|
217
263
|
options->version = (pm_options_version_t) *data++;
|
264
|
+
options->encoding_locked = ((uint8_t) *data++) > 0;
|
265
|
+
options->main_script = ((uint8_t) *data++) > 0;
|
266
|
+
options->partial_script = ((uint8_t) *data++) > 0;
|
218
267
|
|
219
268
|
uint32_t scopes_count = pm_options_read_u32(data);
|
220
269
|
data += 4;
|