prism 0.26.0 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/Makefile +3 -2
- data/config.yml +278 -5
- data/ext/prism/api_node.c +70 -72
- data/ext/prism/extconf.rb +23 -4
- data/ext/prism/extension.c +11 -6
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +271 -4
- data/include/prism/diagnostic.h +3 -0
- data/include/prism/version.h +2 -2
- data/lib/prism/ffi.rb +1 -1
- data/lib/prism/lex_compat.rb +18 -1
- data/lib/prism/node.rb +1772 -265
- data/lib/prism/parse_result/newlines.rb +0 -2
- data/lib/prism/parse_result.rb +59 -13
- data/lib/prism/reflection.rb +18 -28
- data/lib/prism/serialize.rb +7 -4
- data/lib/prism/translation/parser/compiler.rb +32 -13
- data/lib/prism/translation/ripper.rb +59 -59
- data/lib/prism/translation/ruby_parser.rb +66 -28
- data/lib/prism.rb +1 -1
- data/prism.gemspec +1 -1
- data/rbi/prism/node.rbi +5 -2
- data/rbi/prism/parse_result.rbi +62 -34
- data/rbi/prism/reflection.rbi +7 -13
- data/rbi/prism.rbi +9 -9
- data/sig/prism/node.rbs +4 -1
- data/sig/prism/parse_result.rbs +30 -10
- data/sig/prism/reflection.rbs +2 -8
- data/sig/prism/serialize.rbs +2 -3
- data/sig/prism.rbs +9 -9
- data/src/diagnostic.c +7 -1
- data/src/prism.c +16 -3
- data/src/util/pm_integer.c +9 -2
- metadata +2 -2
data/sig/prism.rbs
CHANGED
@@ -17,7 +17,7 @@ module Prism
|
|
17
17
|
?frozen_string_literal: bool,
|
18
18
|
?verbose: bool,
|
19
19
|
?scopes: Array[Array[Symbol]]
|
20
|
-
) -> ParseResult
|
20
|
+
) -> ParseResult
|
21
21
|
|
22
22
|
def self.lex: (
|
23
23
|
String source,
|
@@ -28,7 +28,7 @@ module Prism
|
|
28
28
|
?frozen_string_literal: bool,
|
29
29
|
?verbose: bool,
|
30
30
|
?scopes: Array[Array[Symbol]]
|
31
|
-
) ->
|
31
|
+
) -> LexResult
|
32
32
|
|
33
33
|
def self.lex_compat: (
|
34
34
|
String source,
|
@@ -39,7 +39,7 @@ module Prism
|
|
39
39
|
?frozen_string_literal: bool,
|
40
40
|
?verbose: bool,
|
41
41
|
?scopes: Array[Array[Symbol]]
|
42
|
-
) ->
|
42
|
+
) -> LexCompat::Result
|
43
43
|
|
44
44
|
def self.parse_lex: (
|
45
45
|
String source,
|
@@ -50,7 +50,7 @@ module Prism
|
|
50
50
|
?frozen_string_literal: bool,
|
51
51
|
?verbose: bool,
|
52
52
|
?scopes: Array[Array[Symbol]]
|
53
|
-
) ->
|
53
|
+
) -> ParseLexResult
|
54
54
|
|
55
55
|
def self.dump: (
|
56
56
|
String source,
|
@@ -99,7 +99,7 @@ module Prism
|
|
99
99
|
def self.load: (
|
100
100
|
String source,
|
101
101
|
String serialized
|
102
|
-
) -> ParseResult
|
102
|
+
) -> ParseResult
|
103
103
|
|
104
104
|
def self.lex_ripper: (
|
105
105
|
String source
|
@@ -115,7 +115,7 @@ module Prism
|
|
115
115
|
?frozen_string_literal: bool,
|
116
116
|
?verbose: bool,
|
117
117
|
?scopes: Array[Array[Symbol]]
|
118
|
-
) -> ParseResult
|
118
|
+
) -> ParseResult
|
119
119
|
|
120
120
|
def self.lex_file: (
|
121
121
|
String filepath,
|
@@ -125,7 +125,7 @@ module Prism
|
|
125
125
|
?frozen_string_literal: bool,
|
126
126
|
?verbose: bool,
|
127
127
|
?scopes: Array[Array[Symbol]]
|
128
|
-
) ->
|
128
|
+
) -> LexResult
|
129
129
|
|
130
130
|
def self.parse_lex_file: (
|
131
131
|
String filepath,
|
@@ -135,7 +135,7 @@ module Prism
|
|
135
135
|
?frozen_string_literal: bool,
|
136
136
|
?verbose: bool,
|
137
137
|
?scopes: Array[Array[Symbol]]
|
138
|
-
) ->
|
138
|
+
) -> ParseLexResult
|
139
139
|
|
140
140
|
def self.dump_file: (
|
141
141
|
String filepath,
|
@@ -190,5 +190,5 @@ module Prism
|
|
190
190
|
?frozen_string_literal: bool,
|
191
191
|
?verbose: bool,
|
192
192
|
?scopes: Array[Array[Symbol]]
|
193
|
-
) -> ParseResult
|
193
|
+
) -> ParseResult
|
194
194
|
end
|
data/src/diagnostic.c
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
#include "prism/diagnostic.h"
|
10
10
|
|
11
|
-
#define PM_DIAGNOSTIC_ID_MAX
|
11
|
+
#define PM_DIAGNOSTIC_ID_MAX 284
|
12
12
|
|
13
13
|
/** This struct holds the data for each diagnostic. */
|
14
14
|
typedef struct {
|
@@ -224,6 +224,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
224
224
|
[PM_ERR_INSTANCE_VARIABLE_BARE] = { "'@' without identifiers is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
225
225
|
[PM_ERR_INVALID_BLOCK_EXIT] = { "Invalid %s", PM_ERROR_LEVEL_SYNTAX },
|
226
226
|
[PM_ERR_INVALID_FLOAT_EXPONENT] = { "invalid exponent", PM_ERROR_LEVEL_SYNTAX },
|
227
|
+
[PM_ERR_INVALID_LOCAL_VARIABLE_READ] = { "identifier %.*s is not valid to get", PM_ERROR_LEVEL_SYNTAX },
|
228
|
+
[PM_ERR_INVALID_LOCAL_VARIABLE_WRITE] = { "identifier %.*s is not valid to set", PM_ERROR_LEVEL_SYNTAX },
|
227
229
|
[PM_ERR_INVALID_NUMBER_BINARY] = { "invalid binary number", PM_ERROR_LEVEL_SYNTAX },
|
228
230
|
[PM_ERR_INVALID_NUMBER_DECIMAL] = { "invalid decimal number", PM_ERROR_LEVEL_SYNTAX },
|
229
231
|
[PM_ERR_INVALID_NUMBER_HEXADECIMAL] = { "invalid hexadecimal number", PM_ERROR_LEVEL_SYNTAX },
|
@@ -297,6 +299,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
297
299
|
[PM_ERR_PATTERN_HASH_KEY] = { "expected a key in the hash pattern", PM_ERROR_LEVEL_SYNTAX },
|
298
300
|
[PM_ERR_PATTERN_HASH_KEY_DUPLICATE] = { "duplicated key name", PM_ERROR_LEVEL_SYNTAX },
|
299
301
|
[PM_ERR_PATTERN_HASH_KEY_LABEL] = { "expected a label as the key in the hash pattern", PM_ERROR_LEVEL_SYNTAX }, // TODO // THIS // AND // ABOVE // IS WEIRD
|
302
|
+
[PM_ERR_PATTERN_HASH_KEY_LOCALS] = { "key must be valid as local variables", PM_ERROR_LEVEL_SYNTAX },
|
300
303
|
[PM_ERR_PATTERN_IDENT_AFTER_HROCKET] = { "expected an identifier after the `=>` operator", PM_ERROR_LEVEL_SYNTAX },
|
301
304
|
[PM_ERR_PATTERN_LABEL_AFTER_COMMA] = { "expected a label after the `,` in the hash pattern", PM_ERROR_LEVEL_SYNTAX },
|
302
305
|
[PM_ERR_PATTERN_REST] = { "unexpected rest pattern", PM_ERROR_LEVEL_SYNTAX },
|
@@ -515,6 +518,8 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
515
518
|
case PM_ERR_INVALID_CHARACTER: return "invalid_character";
|
516
519
|
case PM_ERR_INVALID_ENCODING_MAGIC_COMMENT: return "invalid_encoding_magic_comment";
|
517
520
|
case PM_ERR_INVALID_FLOAT_EXPONENT: return "invalid_float_exponent";
|
521
|
+
case PM_ERR_INVALID_LOCAL_VARIABLE_READ: return "invalid_local_variable_read";
|
522
|
+
case PM_ERR_INVALID_LOCAL_VARIABLE_WRITE: return "invalid_local_variable_write";
|
518
523
|
case PM_ERR_INVALID_MULTIBYTE_CHAR: return "invalid_multibyte_char";
|
519
524
|
case PM_ERR_INVALID_MULTIBYTE_CHARACTER: return "invalid_multibyte_character";
|
520
525
|
case PM_ERR_INVALID_MULTIBYTE_ESCAPE: return "invalid_multibyte_escape";
|
@@ -587,6 +592,7 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
587
592
|
case PM_ERR_PATTERN_HASH_KEY: return "pattern_hash_key";
|
588
593
|
case PM_ERR_PATTERN_HASH_KEY_DUPLICATE: return "pattern_hash_key_duplicate";
|
589
594
|
case PM_ERR_PATTERN_HASH_KEY_LABEL: return "pattern_hash_key_label";
|
595
|
+
case PM_ERR_PATTERN_HASH_KEY_LOCALS: return "pattern_hash_key_locals";
|
590
596
|
case PM_ERR_PATTERN_IDENT_AFTER_HROCKET: return "pattern_ident_after_hrocket";
|
591
597
|
case PM_ERR_PATTERN_LABEL_AFTER_COMMA: return "pattern_label_after_comma";
|
592
598
|
case PM_ERR_PATTERN_REST: return "pattern_rest";
|
data/src/prism.c
CHANGED
@@ -13234,9 +13234,15 @@ parse_assocs(pm_parser_t *parser, pm_static_literals_t *literals, pm_node_t *nod
|
|
13234
13234
|
pm_token_t constant = { .type = PM_TOKEN_CONSTANT, .start = label.start, .end = label.end - 1 };
|
13235
13235
|
value = (pm_node_t *) pm_constant_read_node_create(parser, &constant);
|
13236
13236
|
} else {
|
13237
|
-
int depth =
|
13237
|
+
int depth = -1;
|
13238
13238
|
pm_token_t identifier = { .type = PM_TOKEN_IDENTIFIER, .start = label.start, .end = label.end - 1 };
|
13239
13239
|
|
13240
|
+
if (identifier.end[-1] == '!' || identifier.end[-1] == '?') {
|
13241
|
+
PM_PARSER_ERR_TOKEN_FORMAT_CONTENT(parser, identifier, PM_ERR_INVALID_LOCAL_VARIABLE_READ);
|
13242
|
+
} else {
|
13243
|
+
depth = pm_parser_local_depth(parser, &identifier);
|
13244
|
+
}
|
13245
|
+
|
13240
13246
|
if (depth == -1) {
|
13241
13247
|
value = (pm_node_t *) pm_call_node_variable_call_create(parser, &identifier);
|
13242
13248
|
} else {
|
@@ -15643,8 +15649,15 @@ parse_pattern_hash_implicit_value(pm_parser_t *parser, pm_constant_id_list_t *ca
|
|
15643
15649
|
const pm_location_t *value_loc = &((pm_symbol_node_t *) key)->value_loc;
|
15644
15650
|
pm_constant_id_t constant_id = pm_parser_constant_id_location(parser, value_loc->start, value_loc->end);
|
15645
15651
|
|
15646
|
-
int depth;
|
15647
|
-
if (
|
15652
|
+
int depth = -1;
|
15653
|
+
if (value_loc->end[-1] == '!' || value_loc->end[-1] == '?') {
|
15654
|
+
pm_parser_err(parser, key->base.location.start, key->base.location.end, PM_ERR_PATTERN_HASH_KEY_LOCALS);
|
15655
|
+
PM_PARSER_ERR_LOCATION_FORMAT(parser, value_loc, PM_ERR_INVALID_LOCAL_VARIABLE_WRITE, (int) (value_loc->end - value_loc->start), (const char *) value_loc->start);
|
15656
|
+
} else {
|
15657
|
+
depth = pm_parser_local_depth_constant_id(parser, constant_id);
|
15658
|
+
}
|
15659
|
+
|
15660
|
+
if (depth == -1) {
|
15648
15661
|
pm_parser_local_add(parser, constant_id, value_loc->start, value_loc->end, 0);
|
15649
15662
|
}
|
15650
15663
|
|
data/src/util/pm_integer.c
CHANGED
@@ -135,12 +135,19 @@ karatsuba_multiply(pm_integer_t *destination, pm_integer_t *left, pm_integer_t *
|
|
135
135
|
}
|
136
136
|
|
137
137
|
if (left_length * 2 <= right_length) {
|
138
|
-
uint32_t *values = (uint32_t*) xcalloc(left_length + right_length, sizeof(uint32_t));
|
138
|
+
uint32_t *values = (uint32_t *) xcalloc(left_length + right_length, sizeof(uint32_t));
|
139
139
|
|
140
140
|
for (size_t start_offset = 0; start_offset < right_length; start_offset += left_length) {
|
141
141
|
size_t end_offset = start_offset + left_length;
|
142
142
|
if (end_offset > right_length) end_offset = right_length;
|
143
143
|
|
144
|
+
pm_integer_t sliced_left = {
|
145
|
+
.value = 0,
|
146
|
+
.length = left_length,
|
147
|
+
.values = left_values,
|
148
|
+
.negative = false
|
149
|
+
};
|
150
|
+
|
144
151
|
pm_integer_t sliced_right = {
|
145
152
|
.value = 0,
|
146
153
|
.length = end_offset - start_offset,
|
@@ -149,7 +156,7 @@ karatsuba_multiply(pm_integer_t *destination, pm_integer_t *left, pm_integer_t *
|
|
149
156
|
};
|
150
157
|
|
151
158
|
pm_integer_t product;
|
152
|
-
karatsuba_multiply(&product,
|
159
|
+
karatsuba_multiply(&product, &sliced_left, &sliced_right, base);
|
153
160
|
|
154
161
|
uint32_t carry = 0;
|
155
162
|
for (size_t index = 0; index < product.length; index++) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|