prism 1.8.2 → 1.9.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.
data/sig/prism.rbs CHANGED
@@ -14,119 +14,128 @@ module Prism
14
14
 
15
15
  def self.parse: (
16
16
  String source,
17
+ ?command_line: String,
17
18
  ?encoding: Encoding | false,
18
19
  ?filepath: String,
19
20
  ?freeze: bool,
20
21
  ?frozen_string_literal: bool,
21
22
  ?line: Integer,
22
23
  ?main_script: bool,
23
- ?offset: Integer,
24
+ ?partial_script: bool,
24
25
  ?scopes: Array[Array[Symbol]],
25
- ?verbose: bool
26
+ ?version: String
26
27
  ) -> ParseResult
27
28
 
28
29
  def self.profile: (
29
30
  String source,
31
+ ?command_line: String,
30
32
  ?encoding: Encoding | false,
31
33
  ?filepath: String,
32
34
  ?freeze: bool,
33
35
  ?frozen_string_literal: bool,
34
36
  ?line: Integer,
35
37
  ?main_script: bool,
36
- ?offset: Integer,
38
+ ?partial_script: bool,
37
39
  ?scopes: Array[Array[Symbol]],
38
- ?verbose: bool
40
+ ?version: String
39
41
  ) -> nil
40
42
 
41
43
  def self.lex: (
42
44
  String source,
45
+ ?command_line: String,
43
46
  ?encoding: Encoding | false,
44
47
  ?filepath: String,
45
48
  ?freeze: bool,
46
49
  ?frozen_string_literal: bool,
47
50
  ?line: Integer,
48
51
  ?main_script: bool,
49
- ?offset: Integer,
52
+ ?partial_script: bool,
50
53
  ?scopes: Array[Array[Symbol]],
51
- ?verbose: bool
54
+ ?version: String
52
55
  ) -> LexResult
53
56
 
54
57
  def self.lex_compat: (
55
58
  String source,
59
+ ?command_line: String,
56
60
  ?encoding: Encoding | false,
57
61
  ?filepath: String,
58
62
  ?freeze: bool,
59
63
  ?frozen_string_literal: bool,
60
64
  ?line: Integer,
61
65
  ?main_script: bool,
62
- ?offset: Integer,
66
+ ?partial_script: bool,
63
67
  ?scopes: Array[Array[Symbol]],
64
- ?verbose: bool
68
+ ?version: String
65
69
  ) -> LexCompat::Result
66
70
 
67
71
  def self.parse_lex: (
68
72
  String source,
73
+ ?command_line: String,
69
74
  ?encoding: Encoding | false,
70
75
  ?filepath: String,
71
76
  ?freeze: bool,
72
77
  ?frozen_string_literal: bool,
73
78
  ?line: Integer,
74
79
  ?main_script: bool,
75
- ?offset: Integer,
80
+ ?partial_script: bool,
76
81
  ?scopes: Array[Array[Symbol]],
77
- ?verbose: bool
82
+ ?version: String
78
83
  ) -> ParseLexResult
79
84
 
80
85
  def self.dump: (
81
86
  String source,
87
+ ?command_line: String,
82
88
  ?encoding: Encoding | false,
83
89
  ?filepath: String,
84
90
  ?freeze: bool,
85
91
  ?frozen_string_literal: bool,
86
92
  ?line: Integer,
87
93
  ?main_script: bool,
88
- ?offset: Integer,
94
+ ?partial_script: bool,
89
95
  ?scopes: Array[Array[Symbol]],
90
- ?verbose: bool
96
+ ?version: String
91
97
  ) -> String
92
98
 
93
99
  def self.parse_comments: (
94
100
  String source,
101
+ ?command_line: String,
95
102
  ?encoding: Encoding | false,
96
103
  ?filepath: String,
97
104
  ?freeze: bool,
98
105
  ?frozen_string_literal: bool,
99
106
  ?line: Integer,
100
107
  ?main_script: bool,
101
- ?offset: Integer,
108
+ ?partial_script: bool,
102
109
  ?scopes: Array[Array[Symbol]],
103
- ?verbose: bool
110
+ ?version: String
104
111
  ) -> Array[comment]
105
112
 
106
113
  def self.parse_success?: (
107
114
  String source,
115
+ ?command_line: String,
108
116
  ?encoding: Encoding | false,
109
117
  ?filepath: String,
110
118
  ?freeze: bool,
111
119
  ?frozen_string_literal: bool,
112
120
  ?line: Integer,
113
121
  ?main_script: bool,
114
- ?offset: Integer,
122
+ ?partial_script: bool,
115
123
  ?scopes: Array[Array[Symbol]],
116
- ?verbose: bool
124
+ ?version: String
117
125
  ) -> bool
118
126
 
119
127
  def self.parse_failure?: (
120
128
  String source,
129
+ ?command_line: String,
121
130
  ?encoding: Encoding | false,
122
131
  ?filepath: String,
123
132
  ?freeze: bool,
124
133
  ?frozen_string_literal: bool,
125
134
  ?line: Integer,
126
135
  ?main_script: bool,
127
- ?offset: Integer,
136
+ ?partial_script: bool,
128
137
  ?scopes: Array[Array[Symbol]],
129
- ?verbose: bool
138
+ ?version: String
130
139
  ) -> bool
131
140
 
132
141
  def self.load: (
@@ -135,106 +144,110 @@ module Prism
135
144
  ?bool freeze
136
145
  ) -> ParseResult
137
146
 
138
- def self.lex_ripper: (
139
- String source
140
- ) -> Array[[[Integer, Integer], Symbol, String, untyped]]
141
-
142
147
  # Methods taking a path to a Ruby file:
143
148
 
144
149
  def self.parse_file: (
145
150
  String filepath,
151
+ ?command_line: String,
146
152
  ?encoding: Encoding | false,
147
153
  ?freeze: bool,
148
154
  ?frozen_string_literal: bool,
149
155
  ?line: Integer,
150
156
  ?main_script: bool,
151
- ?offset: Integer,
157
+ ?partial_script: bool,
152
158
  ?scopes: Array[Array[Symbol]],
153
- ?verbose: bool
159
+ ?version: String
154
160
  ) -> ParseResult
155
161
 
156
162
  def self.profile_file: (
157
163
  String filepath,
164
+ ?command_line: String,
158
165
  ?encoding: Encoding | false,
159
166
  ?freeze: bool,
160
167
  ?frozen_string_literal: bool,
161
168
  ?line: Integer,
162
169
  ?main_script: bool,
163
- ?offset: Integer,
170
+ ?partial_script: bool,
164
171
  ?scopes: Array[Array[Symbol]],
165
- ?verbose: bool
172
+ ?version: String
166
173
  ) -> nil
167
174
 
168
175
  def self.lex_file: (
169
176
  String filepath,
177
+ ?command_line: String,
170
178
  ?encoding: Encoding | false,
171
179
  ?freeze: bool,
172
180
  ?frozen_string_literal: bool,
173
181
  ?line: Integer,
174
182
  ?main_script: bool,
175
- ?offset: Integer,
183
+ ?partial_script: bool,
176
184
  ?scopes: Array[Array[Symbol]],
177
- ?verbose: bool
185
+ ?version: String
178
186
  ) -> LexResult
179
187
 
180
188
  def self.parse_lex_file: (
181
189
  String filepath,
190
+ ?command_line: String,
182
191
  ?encoding: Encoding | false,
183
192
  ?freeze: bool,
184
193
  ?frozen_string_literal: bool,
185
194
  ?line: Integer,
186
195
  ?main_script: bool,
187
- ?offset: Integer,
196
+ ?partial_script: bool,
188
197
  ?scopes: Array[Array[Symbol]],
189
- ?verbose: bool
198
+ ?version: String
190
199
  ) -> ParseLexResult
191
200
 
192
201
  def self.dump_file: (
193
202
  String filepath,
203
+ ?command_line: String,
194
204
  ?encoding: Encoding | false,
195
205
  ?freeze: bool,
196
206
  ?frozen_string_literal: bool,
197
207
  ?line: Integer,
198
208
  ?main_script: bool,
199
- ?offset: Integer,
209
+ ?partial_script: bool,
200
210
  ?scopes: Array[Array[Symbol]],
201
- ?verbose: bool
211
+ ?version: String
202
212
  ) -> String
203
213
 
204
214
  def self.parse_file_comments: (
205
215
  String filepath,
216
+ ?command_line: String,
206
217
  ?encoding: Encoding | false,
207
218
  ?freeze: bool,
208
219
  ?frozen_string_literal: bool,
209
220
  ?line: Integer,
210
221
  ?main_script: bool,
211
- ?offset: Integer,
222
+ ?partial_script: bool,
212
223
  ?scopes: Array[Array[Symbol]],
213
- ?verbose: bool
224
+ ?version: String
214
225
  ) -> Array[comment]
215
226
 
216
227
  def self.parse_file_success?: (
217
228
  String filepath,
229
+ ?command_line: String,
218
230
  ?encoding: Encoding | false,
219
231
  ?freeze: bool,
220
232
  ?frozen_string_literal: bool,
221
233
  ?line: Integer,
222
234
  ?main_script: bool,
223
- ?offset: Integer,
235
+ ?partial_script: bool,
224
236
  ?scopes: Array[Array[Symbol]],
225
- ?verbose: bool
237
+ ?version: String
226
238
  ) -> bool
227
239
 
228
240
  def self.parse_file_failure?: (
229
241
  String filepath,
242
+ ?command_line: String,
230
243
  ?encoding: Encoding | false,
231
244
  ?freeze: bool,
232
245
  ?frozen_string_literal: bool,
233
246
  ?line: Integer,
234
247
  ?main_script: bool,
235
- ?offset: Integer,
248
+ ?partial_script: bool,
236
249
  ?scopes: Array[Array[Symbol]],
237
- ?verbose: bool
250
+ ?version: String
238
251
  ) -> bool
239
252
 
240
253
  interface _Stream
@@ -243,15 +256,16 @@ module Prism
243
256
 
244
257
  def self.parse_stream: (
245
258
  _Stream stream,
259
+ ?command_line: String,
246
260
  ?encoding: Encoding | false,
247
261
  ?filepath: String,
248
262
  ?freeze: bool,
249
263
  ?frozen_string_literal: bool,
250
264
  ?line: Integer,
251
265
  ?main_script: bool,
252
- ?offset: Integer,
266
+ ?partial_script: bool,
253
267
  ?scopes: Array[Array[Symbol]],
254
- ?verbose: bool
268
+ ?version: String
255
269
  ) -> ParseResult
256
270
 
257
271
  def self.scope: (?locals: Array[Symbol], ?forwarding: Array[Symbol]) -> Scope
data/src/diagnostic.c CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  #include "prism/diagnostic.h"
12
12
 
13
- #define PM_DIAGNOSTIC_ID_MAX 326
13
+ #define PM_DIAGNOSTIC_ID_MAX 324
14
14
 
15
15
  /** This struct holds the data for each diagnostic. */
16
16
  typedef struct {
@@ -112,8 +112,6 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
112
112
  [PM_ERR_ARGUMENT_FORWARDING_UNBOUND] = { "unexpected `...` in an non-parenthesized call", PM_ERROR_LEVEL_SYNTAX },
113
113
  [PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND] = { "unexpected `&`; no anonymous block parameter", PM_ERROR_LEVEL_SYNTAX },
114
114
  [PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = { "unexpected ... when the parent method is not forwarding", PM_ERROR_LEVEL_SYNTAX },
115
- [PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA] = { "unexpected ... in lambda argument", PM_ERROR_LEVEL_SYNTAX },
116
- [PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK] = { "unexpected ... in block argument", PM_ERROR_LEVEL_SYNTAX },
117
115
  [PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = { "unexpected `*`; no anonymous rest parameter", PM_ERROR_LEVEL_SYNTAX },
118
116
  [PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR] = { "unexpected `**`; no anonymous keyword rest parameter", PM_ERROR_LEVEL_SYNTAX },
119
117
  [PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = { "unexpected `*` splat argument after a `**` keyword splat argument", PM_ERROR_LEVEL_SYNTAX },
@@ -444,8 +442,6 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
444
442
  case PM_ERR_ARGUMENT_FORWARDING_UNBOUND: return "argument_forwarding_unbound";
445
443
  case PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND: return "argument_no_forwarding_ampersand";
446
444
  case PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES: return "argument_no_forwarding_ellipses";
447
- case PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA: return "argument_no_forwarding_ellipses_lambda";
448
- case PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK: return "argument_no_forwarding_ellipses_block";
449
445
  case PM_ERR_ARGUMENT_NO_FORWARDING_STAR: return "argument_no_forwarding_star";
450
446
  case PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR: return "argument_no_forwarding_star_star";
451
447
  case PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT: return "argument_splat_after_assoc_splat";
@@ -761,7 +757,6 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
761
757
  static inline const char *
762
758
  pm_diagnostic_message(pm_diagnostic_id_t diag_id) {
763
759
  assert(diag_id < PM_DIAGNOSTIC_ID_MAX);
764
- PRISM_ASSUME(diag_id < PM_DIAGNOSTIC_ID_MAX);
765
760
 
766
761
  const char *message = diagnostic_messages[diag_id].message;
767
762
  assert(message);
@@ -772,7 +767,6 @@ pm_diagnostic_message(pm_diagnostic_id_t diag_id) {
772
767
  static inline uint8_t
773
768
  pm_diagnostic_level(pm_diagnostic_id_t diag_id) {
774
769
  assert(diag_id < PM_DIAGNOSTIC_ID_MAX);
775
- PRISM_ASSUME(diag_id < PM_DIAGNOSTIC_ID_MAX);
776
770
 
777
771
  return (uint8_t) diagnostic_messages[diag_id].level;
778
772
  }
data/src/prism.c CHANGED
@@ -9979,21 +9979,8 @@ parser_lex(pm_parser_t *parser) {
9979
9979
  following && (
9980
9980
  (peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '&') ||
9981
9981
  (peek_at(parser, following) == '|' && peek_at(parser, following + 1) == '|') ||
9982
- (
9983
- peek_at(parser, following) == 'a' &&
9984
- peek_at(parser, following + 1) == 'n' &&
9985
- peek_at(parser, following + 2) == 'd' &&
9986
- peek_at(parser, next_content + 3) != '!' &&
9987
- peek_at(parser, next_content + 3) != '?' &&
9988
- !char_is_identifier(parser, following + 3, parser->end - (following + 3))
9989
- ) ||
9990
- (
9991
- peek_at(parser, following) == 'o' &&
9992
- peek_at(parser, following + 1) == 'r' &&
9993
- peek_at(parser, next_content + 2) != '!' &&
9994
- peek_at(parser, next_content + 2) != '?' &&
9995
- !char_is_identifier(parser, following + 2, parser->end - (following + 2))
9996
- )
9982
+ (peek_at(parser, following) == 'a' && peek_at(parser, following + 1) == 'n' && peek_at(parser, following + 2) == 'd' && !char_is_identifier(parser, following + 3, parser->end - (following + 3))) ||
9983
+ (peek_at(parser, following) == 'o' && peek_at(parser, following + 1) == 'r' && !char_is_identifier(parser, following + 2, parser->end - (following + 2)))
9997
9984
  )
9998
9985
  ) {
9999
9986
  if (!lexed_comment) parser_lex_ignored_newline(parser);
@@ -10064,8 +10051,6 @@ parser_lex(pm_parser_t *parser) {
10064
10051
  peek_at(parser, next_content) == 'a' &&
10065
10052
  peek_at(parser, next_content + 1) == 'n' &&
10066
10053
  peek_at(parser, next_content + 2) == 'd' &&
10067
- peek_at(parser, next_content + 3) != '!' &&
10068
- peek_at(parser, next_content + 3) != '?' &&
10069
10054
  !char_is_identifier(parser, next_content + 3, parser->end - (next_content + 3))
10070
10055
  ) {
10071
10056
  if (!lexed_comment) parser_lex_ignored_newline(parser);
@@ -10082,8 +10067,6 @@ parser_lex(pm_parser_t *parser) {
10082
10067
  if (
10083
10068
  peek_at(parser, next_content) == 'o' &&
10084
10069
  peek_at(parser, next_content + 1) == 'r' &&
10085
- peek_at(parser, next_content + 2) != '!' &&
10086
- peek_at(parser, next_content + 2) != '?' &&
10087
10070
  !char_is_identifier(parser, next_content + 2, parser->end - (next_content + 2))
10088
10071
  ) {
10089
10072
  if (!lexed_comment) parser_lex_ignored_newline(parser);
@@ -10774,10 +10757,7 @@ parser_lex(pm_parser_t *parser) {
10774
10757
  }
10775
10758
 
10776
10759
  if (lex_state_spcarg_p(parser, space_seen)) {
10777
- // https://bugs.ruby-lang.org/issues/21994
10778
- if (parser->version <= PM_OPTIONS_VERSION_CRUBY_4_0) {
10779
- pm_parser_warn_token(parser, &parser->current, PM_WARN_AMBIGUOUS_SLASH);
10780
- }
10760
+ pm_parser_warn_token(parser, &parser->current, PM_WARN_AMBIGUOUS_SLASH);
10781
10761
  lex_mode_push_regexp(parser, '\0', '/');
10782
10762
  LEX(PM_TOKEN_REGEXP_BEGIN);
10783
10763
  }
@@ -12458,7 +12438,7 @@ expect1_opening(pm_parser_t *parser, pm_token_type_t type, pm_diagnostic_id_t di
12458
12438
 
12459
12439
  pm_parser_err(parser, opening->start, opening->end, diag_id);
12460
12440
 
12461
- parser->previous.start = opening->end;
12441
+ parser->previous.start = parser->previous.end;
12462
12442
  parser->previous.type = PM_TOKEN_MISSING;
12463
12443
  }
12464
12444
 
@@ -13879,7 +13859,6 @@ parse_parameters(
13879
13859
  bool allows_forwarding_parameters,
13880
13860
  bool accepts_blocks_in_defaults,
13881
13861
  bool in_block,
13882
- pm_diagnostic_id_t diag_id_forwarding,
13883
13862
  uint16_t depth
13884
13863
  ) {
13885
13864
  pm_do_loop_stack_push(parser, false);
@@ -13935,7 +13914,7 @@ parse_parameters(
13935
13914
  }
13936
13915
  case PM_TOKEN_UDOT_DOT_DOT: {
13937
13916
  if (!allows_forwarding_parameters) {
13938
- pm_parser_err_current(parser, diag_id_forwarding);
13917
+ pm_parser_err_current(parser, PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES);
13939
13918
  }
13940
13919
 
13941
13920
  bool succeeded = update_parameter_state(parser, &parser->current, &order);
@@ -14615,7 +14594,6 @@ parse_block_parameters(
14615
14594
  false,
14616
14595
  accepts_blocks_in_defaults,
14617
14596
  true,
14618
- is_lambda_literal ? PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA : PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK,
14619
14597
  (uint16_t) (depth + 1)
14620
14598
  );
14621
14599
  if (!is_lambda_literal) {
@@ -18858,17 +18836,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
18858
18836
  if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
18859
18837
  params = NULL;
18860
18838
  } else {
18861
- params = parse_parameters(
18862
- parser,
18863
- PM_BINDING_POWER_DEFINED,
18864
- true,
18865
- false,
18866
- true,
18867
- true,
18868
- false,
18869
- PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
18870
- (uint16_t) (depth + 1)
18871
- );
18839
+ params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, true, false, true, true, false, (uint16_t) (depth + 1));
18872
18840
  }
18873
18841
 
18874
18842
  lex_state_set(parser, PM_LEX_STATE_BEG);
@@ -18893,17 +18861,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
18893
18861
 
18894
18862
  lparen = not_provided(parser);
18895
18863
  rparen = not_provided(parser);
18896
- params = parse_parameters(
18897
- parser,
18898
- PM_BINDING_POWER_DEFINED,
18899
- false,
18900
- false,
18901
- true,
18902
- true,
18903
- false,
18904
- PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
18905
- (uint16_t) (depth + 1)
18906
- );
18864
+ params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, false, false, true, true, false, (uint16_t) (depth + 1));
18907
18865
 
18908
18866
  // Reject `def * = 1` and similar. We have to specifically check
18909
18867
  // for them because they create ambiguity with optional arguments.
@@ -18959,7 +18917,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
18959
18917
  context_push(parser, PM_CONTEXT_RESCUE_MODIFIER);
18960
18918
 
18961
18919
  pm_token_t rescue_keyword = parser->previous;
18962
- pm_node_t *value = parse_expression(parser, PM_BINDING_POWER_MATCH + 1, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
18920
+ pm_node_t *value = parse_expression(parser, pm_binding_powers[PM_TOKEN_KEYWORD_RESCUE_MODIFIER].right, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
18963
18921
  context_pop(parser);
18964
18922
 
18965
18923
  statement = UP(pm_rescue_modifier_node_create(parser, statement, &rescue_keyword, value));
@@ -20256,7 +20214,7 @@ parse_assignment_value(pm_parser_t *parser, pm_binding_power_t previous_binding_
20256
20214
  pm_token_t rescue = parser->current;
20257
20215
  parser_lex(parser);
20258
20216
 
20259
- pm_node_t *right = parse_expression(parser, PM_BINDING_POWER_MATCH + 1, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
20217
+ pm_node_t *right = parse_expression(parser, pm_binding_powers[PM_TOKEN_KEYWORD_RESCUE_MODIFIER].right, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
20260
20218
  context_pop(parser);
20261
20219
 
20262
20220
  return UP(pm_rescue_modifier_node_create(parser, value, &rescue, right));
@@ -20362,7 +20320,7 @@ parse_assignment_values(pm_parser_t *parser, pm_binding_power_t previous_binding
20362
20320
  }
20363
20321
  }
20364
20322
 
20365
- pm_node_t *right = parse_expression(parser, PM_BINDING_POWER_MATCH + 1, accepts_command_call_inner, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
20323
+ pm_node_t *right = parse_expression(parser, pm_binding_powers[PM_TOKEN_KEYWORD_RESCUE_MODIFIER].right, accepts_command_call_inner, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
20366
20324
  context_pop(parser);
20367
20325
 
20368
20326
  return UP(pm_rescue_modifier_node_create(parser, value, &rescue, right));
@@ -21681,6 +21639,12 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
21681
21639
  ) {
21682
21640
  node = parse_expression_infix(parser, node, binding_power, current_binding_powers.right, accepts_command_call, (uint16_t) (depth + 1));
21683
21641
 
21642
+ if (context_terminator(parser->current_context->context, &parser->current)) {
21643
+ // If this token terminates the current context, then we need to
21644
+ // stop parsing the expression, as it has become a statement.
21645
+ return node;
21646
+ }
21647
+
21684
21648
  switch (PM_NODE_TYPE(node)) {
21685
21649
  case PM_MULTI_WRITE_NODE:
21686
21650
  // Multi-write nodes are statements, and cannot be followed by
@@ -21793,17 +21757,6 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
21793
21757
  break;
21794
21758
  }
21795
21759
  }
21796
-
21797
- if (context_terminator(parser->current_context->context, &parser->current)) {
21798
- pm_binding_powers_t next_binding_powers = pm_binding_powers[parser->current.type];
21799
- if (
21800
- !next_binding_powers.binary ||
21801
- binding_power > next_binding_powers.left ||
21802
- (PM_NODE_TYPE_P(node, PM_CALL_NODE) && pm_call_node_command_p((pm_call_node_t *) node))
21803
- ) {
21804
- return node;
21805
- }
21806
- }
21807
21760
  }
21808
21761
 
21809
21762
  return node;
data/src/util/pm_memchr.c CHANGED
@@ -7,7 +7,7 @@
7
7
  * we need to search for a character in a buffer that could be the trailing byte
8
8
  * of a multibyte character.
9
9
  */
10
- const void *
10
+ void *
11
11
  pm_memchr(const void *memory, int character, size_t number, bool encoding_changed, const pm_encoding_t *encoding) {
12
12
  if (encoding_changed && encoding->multibyte && character >= PRISM_MEMCHR_TRAILING_BYTE_MINIMUM) {
13
13
  const uint8_t *source = (const uint8_t *) memory;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prism
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
@@ -80,7 +80,6 @@ files:
80
80
  - lib/prism/ffi.rb
81
81
  - lib/prism/inspect_visitor.rb
82
82
  - lib/prism/lex_compat.rb
83
- - lib/prism/lex_ripper.rb
84
83
  - lib/prism/mutation_compiler.rb
85
84
  - lib/prism/node.rb
86
85
  - lib/prism/node_ext.rb
@@ -107,6 +106,7 @@ files:
107
106
  - lib/prism/translation/parser_current.rb
108
107
  - lib/prism/translation/parser_versions.rb
109
108
  - lib/prism/translation/ripper.rb
109
+ - lib/prism/translation/ripper/filter.rb
110
110
  - lib/prism/translation/ripper/lexer.rb
111
111
  - lib/prism/translation/ripper/sexp.rb
112
112
  - lib/prism/translation/ripper/shim.rb
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
- # :markup: markdown
3
-
4
- require "ripper"
5
-
6
- module Prism
7
- # This is a class that wraps the Ripper lexer to produce almost exactly the
8
- # same tokens.
9
- class LexRipper # :nodoc:
10
- attr_reader :source
11
-
12
- def initialize(source)
13
- @source = source
14
- end
15
-
16
- def result
17
- previous = [] #: [[Integer, Integer], Symbol, String, untyped] | []
18
- results = [] #: Array[[[Integer, Integer], Symbol, String, untyped]]
19
-
20
- lex(source).each do |token|
21
- case token[1]
22
- when :on_sp
23
- # skip
24
- when :on_tstring_content
25
- if previous[1] == :on_tstring_content && (token[2].start_with?("\#$") || token[2].start_with?("\#@"))
26
- previous[2] << token[2]
27
- else
28
- results << token
29
- previous = token
30
- end
31
- when :on_words_sep
32
- if previous[1] == :on_words_sep
33
- previous[2] << token[2]
34
- else
35
- results << token
36
- previous = token
37
- end
38
- else
39
- results << token
40
- previous = token
41
- end
42
- end
43
-
44
- results
45
- end
46
-
47
- private
48
-
49
- if Ripper.method(:lex).parameters.assoc(:keyrest)
50
- def lex(source)
51
- Ripper.lex(source, raise_errors: true)
52
- end
53
- else
54
- def lex(source)
55
- ripper = Ripper::Lexer.new(source)
56
- ripper.lex.tap do |result|
57
- raise SyntaxError, ripper.errors.map(&:message).join(' ;') if ripper.errors.any?
58
- end
59
- end
60
- end
61
- end
62
-
63
- private_constant :LexRipper
64
- end