1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
use crate::error::DiagnosticMessage;
impl DiagnosticMessage {
pub fn render(&self) -> String {
if self.is_fraction_after_numeric() {
return "unexpected fraction part after numeric literal".to_string();
}
if self.is_no_digits_after_dot() {
return "no .<digit> floating literal anymore; put 0 before dot".to_string();
}
if self.is_unknown_type_of_percent_string() {
return "unknown type of %string".to_string();
}
if self.is_numeric_literal_without_digits() {
return "numeric literal without digits".to_string();
}
if self.is_unterminated_list() {
return "unterminated list meets end of file".to_string();
}
if self.is_unterminated_regexp() {
return "unterminated regexp meets end of file".to_string();
}
if self.is_unterminated_string() {
return "unterminated string meets end of file".to_string();
}
if self.is_unterminated_quoted_string() {
return "unterminated quoted string meets end of file".to_string();
}
if self.is_invalid_unicode_escape() {
return "invalid Unicode escape".to_string();
}
if self.is_too_large_unicode_codepoint() {
return "invalid Unicode codepoint (too large)".to_string();
}
if self.is_invalid_unicode_codepoint() {
return "invalid Unicode codepoint".to_string();
}
if self.is_multiple_codepoint_at_single_char() {
return "Multiple codepoints at single character literal".to_string();
}
if self.is_invalid_escape_character() {
return "Invalid escape character syntax".to_string();
}
if self.is_invalid_hex_escape() {
return "invalid hex escape".to_string();
}
if let Some(unterminated_heredoc) = self.as_unterminated_heredoc() {
return format!(
"can't find string \"{}\" anywhere before EOF",
unterminated_heredoc.get_heredoc_id().as_str()
);
}
if self.is_unterminated_heredoc_id() {
return "unterminated here document identifier".to_string();
}
if self.is_slash_r_at_middle_of_line() {
return "encountered \\r in middle of line, treated as a mere space".to_string();
}
if self.is_d_star_interpreted_as_arg_prefix() {
return "`**' interpreted as argument prefix".to_string();
}
if self.is_star_interpreted_as_arg_prefix() {
return "`*' interpreted as argument prefix".to_string();
}
if self.is_ampersand_interpreted_as_arg_prefix() {
return "`&' interpreted as argument prefix".to_string();
}
if self.is_triple_dot_at_eol() {
return "... at EOL, should be parenthesized?".to_string();
}
if self.is_parentheses_iterpreted_as_arglist() {
return "parentheses after method name is interpreted as an argument list, not a decomposed argument"
.to_string();
}
if let Some(ambiguous_first_argument) = self.as_ambiguous_first_argument() {
return format!(
"ambiguous first argument; put parentheses or a space even after `{}' operator",
*ambiguous_first_argument.get_operator() as char
);
}
if let Some(ambiguous_operator) = self.as_ambiguous_operator() {
return format!(
"`{}' after local variable or literal is interpreted as binary operator even though it seems like {}",
ambiguous_operator.get_operator().as_str(),
ambiguous_operator.get_interpreted_as().as_str(),
);
}
if let Some(invalid_character_syntax) = self.as_invalid_character_syntax() {
return format!(
"invalid character syntax; use {}",
invalid_character_syntax.get_suggestion().as_str()
);
}
if self.is_invalid_octal_digit() {
return "Invalid octal digit".to_string();
}
if let Some(trailing_char_in_number) = self.as_trailing_char_in_number() {
return format!(
"trailing `{}' in number",
*trailing_char_in_number.get_c() as char
);
}
if self.is_embedded_document_meets_eof() {
return "embedded document meets end of file".to_string();
}
if let Some(invalid_char) = self.as_invalid_char() {
return format!(
"Invalid char `{}' in expression",
*invalid_char.get_c() as char
);
}
if self.is_incomplete_character_syntax() {
return "incomplete character syntax".to_string();
}
if self.is_gvar_without_id() {
return "`$' without identifiers is not allowed as a global variable name".to_string();
}
if let Some(invalid_gvar_name) = self.as_invalid_gvar_name() {
return format!(
"`${}' is not allowed as a global variable name",
*invalid_gvar_name.get_c() as char
);
}
if self.is_ivar_without_id() {
return "`@' without identifiers is not allowed as an instance variable name"
.to_string();
}
if let Some(invalid_ivar_name) = self.as_invalid_ivar_name() {
return format!(
"`@{}' is not allowed as an instance variable name",
*invalid_ivar_name.get_c() as char
);
}
if self.is_cvar_without_id() {
return "`@@' without identifiers is not allowed as a class variable name".to_string();
}
if let Some(invalid_cvar_name) = self.as_invalid_cvar_name() {
return format!(
"`@@{}' is not allowed as a class variable name",
*invalid_cvar_name.get_c() as char
);
}
if let Some(unknown_regex_options) = self.as_unknown_regex_options() {
return format!(
"unknown regexp options - {}",
unknown_regex_options.get_options().as_str()
);
}
if let Some(ambiguous_ternary_operator) = self.as_ambiguous_ternary_operator() {
return format!(
"`?' just followed by `{}' is interpreted as a conditional operator, put a space after `?'",
ambiguous_ternary_operator.get_condition().as_str()
);
}
if self.is_ambiguous_regexp() {
return "ambiguity between regexp and two divisions: wrap regexp in parentheses or add a space after `/' operator"
.to_string();
}
if self.is_unterminated_unicode_escape() {
return "unterminated Unicode escape".to_string();
}
if let Some(encoding_error) = self.as_encoding_error() {
return format!("encoding error: {}", encoding_error.get_error().as_str());
}
if self.is_invalid_multibyte_char() {
return "invalid multibyte char (UTF-8)".to_string();
}
if self.is_else_without_rescue() {
return "else without rescue is useless".to_string();
}
if self.is_begin_not_at_top_level() {
return "BEGIN is permitted only at toplevel".to_string();
}
if self.is_alias_nth_ref() {
return "can't make alias for the number variables".to_string();
}
if self.is_csend_inside_masgn() {
return "&. inside multiple assignment destination".to_string();
}
if self.is_class_or_module_name_must_be_constant() {
return "class/module name must be CONSTANT".to_string();
}
if self.is_endless_setter_definition() {
return "setter method cannot be defined in an endless method definition".to_string();
}
if let Some(unexpected_token) = self.as_unexpected_token() {
return format!("unexpected {}", unexpected_token.get_token_name().as_str());
}
if self.is_class_definition_in_method_body() {
return "class definition in method body".to_string();
}
if self.is_module_definition_in_method_body() {
return "module definition in method body".to_string();
}
if self.is_invalid_return_in_class_or_module_body() {
return "Invalid return in class/module body".to_string();
}
if self.is_const_argument() {
return "formal argument cannot be a constant".to_string();
}
if self.is_ivar_argument() {
return "formal argument cannot be an instance variable".to_string();
}
if self.is_gvar_argument() {
return "formal argument cannot be a global variable".to_string();
}
if self.is_cvar_argument() {
return "formal argument cannot be a class variable".to_string();
}
if let Some(no_such_local_variable) = self.as_no_such_local_variable() {
return format!(
"{}: no such local variable",
no_such_local_variable.get_var_name().as_str()
);
}
if self.is_ordinary_param_defined() {
return "ordinary parameter is defined".to_string();
}
if self.is_numparam_used() {
return "numbered parameter is already used".to_string();
}
if let Some(tok_at_eol_without_expression) = self.as_tok_at_eol_without_expression() {
return format!(
"`{}' at the end of line without an expression",
tok_at_eol_without_expression.get_token_name().as_str()
);
}
if self.is_end_in_method() {
return "END in method; use at_exit".to_string();
}
if let Some(comparison_after_comparison) = self.as_comparison_after_comparison() {
return format!(
"comparison '{}' after comparison",
comparison_after_comparison.get_comparison().as_str()
);
}
if let Some(circular_argument_reference) = self.as_circular_argument_reference() {
return format!(
"circular argument reference - {}",
circular_argument_reference.get_arg_name().as_str()
);
}
if self.is_dynamic_constant_assignment() {
return "dynamic constant assignment".to_string();
}
if self.is_cant_assign_to_self() {
return "Can't change the value of self".to_string();
}
if self.is_cant_assign_to_nil() {
return "Can't assign to nil".to_string();
}
if self.is_cant_assign_to_true() {
return "Can't assign to true".to_string();
}
if self.is_cant_assign_to_false() {
return "Can't assign to false".to_string();
}
if self.is_cant_assign_to_file() {
return "Can't assign to __FILE__".to_string();
}
if self.is_cant_assign_to_line() {
return "Can't assign to __LINE__".to_string();
}
if self.is_cant_assign_to_encoding() {
return "Can't assign to __ENCODING__".to_string();
}
if let Some(cant_assign_to_numparam) = self.as_cant_assign_to_numparam() {
return format!(
"Can't assign to numbered parameter {}",
cant_assign_to_numparam.get_numparam().as_str()
);
}
if let Some(cant_set_variable) = self.as_cant_set_variable() {
return format!(
"Can't set variable {}",
cant_set_variable.get_var_name().as_str()
);
}
if self.is_block_given_to_yield() {
return "block given to yield".to_string();
}
if self.is_block_and_block_arg_given() {
return "both block arg and actual block given".to_string();
}
if self.is_symbol_literal_with_interpolation() {
return "symbol literal with interpolation is not allowed".to_string();
}
if let Some(reserved_for_numparam) = self.as_reserved_for_numparam() {
return format!(
"{} is reserved for numbered parameter",
reserved_for_numparam.get_numparam().as_str()
);
}
if self.is_key_must_be_valid_as_local_variable() {
return "key must be valid as local variables".to_string();
}
if self.is_duplicate_variable_name() {
return "duplicated variable name".to_string();
}
if self.is_duplicate_key_name() {
return "duplicated key name".to_string();
}
if self.is_singleton_literal() {
return "can't define singleton method for literals".to_string();
}
if let Some(nth_ref_is_too_big) = self.as_nth_ref_is_too_big() {
return format!(
"`{}' is too big for a number variable, always nil",
nth_ref_is_too_big.get_nth_ref().as_str()
);
}
if self.is_duplicated_argument_name() {
return "duplicated argument name".to_string();
}
if let Some(regex_error) = self.as_regex_error() {
return regex_error.get_error().as_str().to_string();
}
if let Some(invalid_symbol) = self.as_invalid_symbol() {
return format!(
"invalid symbol in encoding {}",
invalid_symbol.get_symbol().as_str()
);
}
if self.is_void_value_expression() {
return "void value expression".to_string();
}
unreachable!("Unknown type of diagnostic message")
}
}