prism 0.24.0 → 0.29.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 +132 -1
- data/Makefile +25 -18
- data/README.md +45 -6
- data/config.yml +828 -25
- data/docs/build_system.md +31 -0
- data/docs/configuration.md +4 -0
- data/docs/cruby_compilation.md +1 -1
- data/docs/parser_translation.md +14 -9
- data/docs/releasing.md +7 -9
- 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 +1037 -936
- data/ext/prism/api_pack.c +9 -0
- data/ext/prism/extconf.rb +62 -18
- data/ext/prism/extension.c +351 -71
- data/ext/prism/extension.h +5 -4
- data/include/prism/ast.h +539 -101
- data/include/prism/defines.h +106 -2
- data/include/prism/diagnostic.h +168 -74
- data/include/prism/encoding.h +22 -4
- data/include/prism/node.h +93 -0
- data/include/prism/options.h +84 -9
- data/include/prism/pack.h +11 -0
- data/include/prism/parser.h +213 -54
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/static_literals.h +120 -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 +5 -3
- data/lib/prism/dispatcher.rb +29 -0
- data/lib/prism/dot_visitor.rb +141 -54
- data/lib/prism/dsl.rb +48 -36
- data/lib/prism/ffi.rb +82 -17
- data/lib/prism/inspect_visitor.rb +2156 -0
- data/lib/prism/lex_compat.rb +34 -15
- data/lib/prism/mutation_compiler.rb +13 -2
- data/lib/prism/node.rb +4453 -4459
- data/lib/prism/node_ext.rb +249 -30
- data/lib/prism/pack.rb +4 -0
- data/lib/prism/parse_result/comments.rb +35 -18
- data/lib/prism/parse_result/newlines.rb +2 -2
- data/lib/prism/parse_result.rb +218 -43
- data/lib/prism/pattern.rb +28 -10
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/reflection.rb +411 -0
- data/lib/prism/serialize.rb +480 -112
- data/lib/prism/translation/parser/compiler.rb +376 -88
- data/lib/prism/translation/parser/lexer.rb +103 -22
- data/lib/prism/translation/parser/rubocop.rb +41 -13
- data/lib/prism/translation/parser.rb +123 -11
- 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 +3216 -462
- data/lib/prism/translation/ruby_parser.rb +111 -56
- data/lib/prism/translation.rb +3 -1
- data/lib/prism/visitor.rb +10 -0
- data/lib/prism.rb +12 -20
- data/prism.gemspec +46 -14
- data/rbi/prism/compiler.rbi +12 -0
- data/rbi/prism/inspect_visitor.rbi +12 -0
- data/rbi/prism/node.rbi +8712 -0
- data/rbi/prism/node_ext.rbi +107 -0
- data/rbi/prism/parse_result.rbi +358 -0
- data/rbi/prism/reflection.rbi +58 -0
- data/rbi/prism/translation/parser.rbi +11 -0
- data/rbi/prism/translation/parser33.rbi +6 -0
- data/rbi/prism/translation/parser34.rbi +6 -0
- data/rbi/prism/translation/ripper.rbi +15 -0
- data/rbi/prism/visitor.rbi +470 -0
- data/rbi/prism.rbi +38 -7748
- 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/inspect_visitor.rbs +22 -0
- data/sig/prism/lex_compat.rbs +10 -0
- data/sig/prism/mutation_compiler.rbs +158 -0
- data/sig/prism/node.rbs +3558 -0
- data/sig/prism/node_ext.rbs +82 -0
- data/sig/prism/pack.rbs +43 -0
- data/sig/prism/parse_result.rbs +160 -0
- data/sig/prism/pattern.rbs +13 -0
- data/sig/prism/reflection.rbs +50 -0
- data/sig/prism/serialize.rbs +6 -0
- data/sig/prism/visitor.rbs +168 -0
- data/sig/prism.rbs +188 -4767
- data/src/diagnostic.c +636 -230
- data/src/encoding.c +211 -108
- data/src/node.c +7555 -451
- data/src/options.c +66 -31
- data/src/pack.c +33 -17
- data/src/prettyprint.c +1383 -1431
- data/src/prism.c +4734 -1310
- data/src/regexp.c +17 -2
- data/src/serialize.c +68 -46
- data/src/static_literals.c +638 -0
- data/src/token_type.c +10 -9
- 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 +642 -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 +41 -9
- data/docs/ripper.md +0 -36
- data/include/prism/util/pm_state_stack.h +0 -42
- data/lib/prism/node_inspector.rb +0 -68
- data/rbi/prism_static.rbi +0 -207
- data/sig/prism_static.rbs +0 -201
- data/src/util/pm_state_stack.c +0 -25
data/include/prism/defines.h
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
#define PRISM_DEFINES_H
|
11
11
|
|
12
12
|
#include <ctype.h>
|
13
|
+
#include <limits.h>
|
14
|
+
#include <math.h>
|
13
15
|
#include <stdarg.h>
|
14
16
|
#include <stddef.h>
|
15
17
|
#include <stdint.h>
|
@@ -21,7 +23,6 @@
|
|
21
23
|
* some platforms they aren't included unless this is already defined.
|
22
24
|
*/
|
23
25
|
#define __STDC_FORMAT_MACROS
|
24
|
-
|
25
26
|
#include <inttypes.h>
|
26
27
|
|
27
28
|
/**
|
@@ -48,7 +49,11 @@
|
|
48
49
|
* compiler-agnostic way.
|
49
50
|
*/
|
50
51
|
#if defined(__GNUC__)
|
51
|
-
#
|
52
|
+
# if defined(__MINGW_PRINTF_FORMAT)
|
53
|
+
# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, argument_index)))
|
54
|
+
# else
|
55
|
+
# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index)))
|
56
|
+
# endif
|
52
57
|
#elif defined(__clang__)
|
53
58
|
# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index)))
|
54
59
|
#else
|
@@ -99,4 +104,103 @@
|
|
99
104
|
# define PM_STATIC_ASSERT(line, condition, message) typedef char PM_CONCATENATE(static_assert_, line)[(condition) ? 1 : -1]
|
100
105
|
#endif
|
101
106
|
|
107
|
+
/**
|
108
|
+
* In general, libc for embedded systems does not support memory-mapped files.
|
109
|
+
* If the target platform is POSIX or Windows, we can map a file in memory and
|
110
|
+
* read it in a more efficient manner.
|
111
|
+
*/
|
112
|
+
#ifdef _WIN32
|
113
|
+
# define PRISM_HAS_MMAP
|
114
|
+
#else
|
115
|
+
# include <unistd.h>
|
116
|
+
# ifdef _POSIX_MAPPED_FILES
|
117
|
+
# define PRISM_HAS_MMAP
|
118
|
+
# endif
|
119
|
+
#endif
|
120
|
+
|
121
|
+
/**
|
122
|
+
* isinf on Windows is defined as accepting a float, but on POSIX systems it
|
123
|
+
* accepts a float, a double, or a long double. We want to mirror this behavior
|
124
|
+
* on windows.
|
125
|
+
*/
|
126
|
+
#ifdef _WIN32
|
127
|
+
# include <float.h>
|
128
|
+
# undef isinf
|
129
|
+
# define isinf(x) (sizeof(x) == sizeof(float) ? !_finitef(x) : !_finite(x))
|
130
|
+
#endif
|
131
|
+
|
132
|
+
/**
|
133
|
+
* If you build prism with a custom allocator, configure it with
|
134
|
+
* "-D PRISM_XALLOCATOR" to use your own allocator that defines xmalloc,
|
135
|
+
* xrealloc, xcalloc, and xfree.
|
136
|
+
*
|
137
|
+
* For example, your `prism_xallocator.h` file could look like this:
|
138
|
+
*
|
139
|
+
* ```
|
140
|
+
* #ifndef PRISM_XALLOCATOR_H
|
141
|
+
* #define PRISM_XALLOCATOR_H
|
142
|
+
* #define xmalloc my_malloc
|
143
|
+
* #define xrealloc my_realloc
|
144
|
+
* #define xcalloc my_calloc
|
145
|
+
* #define xfree my_free
|
146
|
+
* #endif
|
147
|
+
* ```
|
148
|
+
*/
|
149
|
+
#ifdef PRISM_XALLOCATOR
|
150
|
+
#include "prism_xallocator.h"
|
151
|
+
#else
|
152
|
+
#ifndef xmalloc
|
153
|
+
/**
|
154
|
+
* The malloc function that should be used. This can be overridden with
|
155
|
+
* the PRISM_XALLOCATOR define.
|
156
|
+
*/
|
157
|
+
#define xmalloc malloc
|
158
|
+
#endif
|
159
|
+
|
160
|
+
#ifndef xrealloc
|
161
|
+
/**
|
162
|
+
* The realloc function that should be used. This can be overridden with
|
163
|
+
* the PRISM_XALLOCATOR define.
|
164
|
+
*/
|
165
|
+
#define xrealloc realloc
|
166
|
+
#endif
|
167
|
+
|
168
|
+
#ifndef xcalloc
|
169
|
+
/**
|
170
|
+
* The calloc function that should be used. This can be overridden with
|
171
|
+
* the PRISM_XALLOCATOR define.
|
172
|
+
*/
|
173
|
+
#define xcalloc calloc
|
174
|
+
#endif
|
175
|
+
|
176
|
+
#ifndef xfree
|
177
|
+
/**
|
178
|
+
* The free function that should be used. This can be overridden with the
|
179
|
+
* PRISM_XALLOCATOR define.
|
180
|
+
*/
|
181
|
+
#define xfree free
|
182
|
+
#endif
|
183
|
+
#endif
|
184
|
+
|
185
|
+
/**
|
186
|
+
* If PRISM_BUILD_MINIMAL is defined, then we're going to define every possible
|
187
|
+
* switch that will turn off certain features of prism.
|
188
|
+
*/
|
189
|
+
#ifdef PRISM_BUILD_MINIMAL
|
190
|
+
/** Exclude the serialization API. */
|
191
|
+
#define PRISM_EXCLUDE_SERIALIZATION
|
192
|
+
|
193
|
+
/** Exclude the JSON serialization API. */
|
194
|
+
#define PRISM_EXCLUDE_JSON
|
195
|
+
|
196
|
+
/** Exclude the Array#pack parser API. */
|
197
|
+
#define PRISM_EXCLUDE_PACK
|
198
|
+
|
199
|
+
/** Exclude the prettyprint API. */
|
200
|
+
#define PRISM_EXCLUDE_PRETTYPRINT
|
201
|
+
|
202
|
+
/** Exclude the full set of encodings, using the minimal only. */
|
203
|
+
#define PRISM_ENCODING_EXCLUDE_FULL
|
204
|
+
#endif
|
205
|
+
|
102
206
|
#endif
|
data/include/prism/diagnostic.h
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
/******************************************************************************/
|
2
|
+
/* This file is generated by the templates/template.rb script and should not */
|
3
|
+
/* be modified manually. See */
|
4
|
+
/* templates/include/prism/diagnostic.h.erb */
|
5
|
+
/* if you are looking to modify the */
|
6
|
+
/* template */
|
7
|
+
/******************************************************************************/
|
8
|
+
|
1
9
|
/**
|
2
10
|
* @file diagnostic.h
|
3
11
|
*
|
@@ -14,83 +22,33 @@
|
|
14
22
|
#include <stdlib.h>
|
15
23
|
#include <assert.h>
|
16
24
|
|
17
|
-
/**
|
18
|
-
* The levels of errors generated during parsing.
|
19
|
-
*/
|
20
|
-
typedef enum {
|
21
|
-
/** For errors that cannot be recovered from. */
|
22
|
-
PM_ERROR_LEVEL_FATAL = 0,
|
23
|
-
|
24
|
-
/** For errors that should raise an argument error. */
|
25
|
-
PM_ERROR_LEVEL_ARGUMENT = 1
|
26
|
-
} pm_error_level_t;
|
27
|
-
|
28
|
-
/**
|
29
|
-
* The levels of warnings generated during parsing.
|
30
|
-
*/
|
31
|
-
typedef enum {
|
32
|
-
/** For warnings which should be emitted if $VERBOSE != nil. */
|
33
|
-
PM_WARNING_LEVEL_DEFAULT = 0,
|
34
|
-
|
35
|
-
/** For warnings which should be emitted if $VERBOSE == true. */
|
36
|
-
PM_WARNING_LEVEL_VERBOSE = 1
|
37
|
-
} pm_warning_level_t;
|
38
|
-
|
39
|
-
/**
|
40
|
-
* This struct represents a diagnostic generated during parsing.
|
41
|
-
*
|
42
|
-
* @extends pm_list_node_t
|
43
|
-
*/
|
44
|
-
typedef struct {
|
45
|
-
/** The embedded base node. */
|
46
|
-
pm_list_node_t node;
|
47
|
-
|
48
|
-
/** The location of the diagnostic in the source. */
|
49
|
-
pm_location_t location;
|
50
|
-
|
51
|
-
/** The message associated with the diagnostic. */
|
52
|
-
const char *message;
|
53
|
-
|
54
|
-
/**
|
55
|
-
* Whether or not the memory related to the message of this diagnostic is
|
56
|
-
* owned by this diagnostic. If it is, it needs to be freed when the
|
57
|
-
* diagnostic is freed.
|
58
|
-
*/
|
59
|
-
bool owned;
|
60
|
-
|
61
|
-
/**
|
62
|
-
* The level of the diagnostic, see `pm_error_level_t` and
|
63
|
-
* `pm_warning_level_t` for possible values.
|
64
|
-
*/
|
65
|
-
uint8_t level;
|
66
|
-
} pm_diagnostic_t;
|
67
|
-
|
68
25
|
/**
|
69
26
|
* The diagnostic IDs of all of the diagnostics, used to communicate the types
|
70
27
|
* of errors between the parser and the user.
|
71
28
|
*/
|
72
29
|
typedef enum {
|
73
|
-
//
|
74
|
-
// an example of how this is used, see parse_expression_prefix.
|
75
|
-
PM_ERR_CANNOT_PARSE_EXPRESSION,
|
76
|
-
|
77
|
-
// These are the error codes.
|
30
|
+
// These are the error diagnostics.
|
78
31
|
PM_ERR_ALIAS_ARGUMENT,
|
32
|
+
PM_ERR_ALIAS_ARGUMENT_NUMBERED_REFERENCE,
|
79
33
|
PM_ERR_AMPAMPEQ_MULTI_ASSIGN,
|
80
34
|
PM_ERR_ARGUMENT_AFTER_BLOCK,
|
81
35
|
PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES,
|
82
36
|
PM_ERR_ARGUMENT_BARE_HASH,
|
83
37
|
PM_ERR_ARGUMENT_BLOCK_FORWARDING,
|
84
38
|
PM_ERR_ARGUMENT_BLOCK_MULTI,
|
39
|
+
PM_ERR_ARGUMENT_CONFLICT_AMPERSAND,
|
40
|
+
PM_ERR_ARGUMENT_CONFLICT_STAR,
|
41
|
+
PM_ERR_ARGUMENT_CONFLICT_STAR_STAR,
|
85
42
|
PM_ERR_ARGUMENT_FORMAL_CLASS,
|
86
43
|
PM_ERR_ARGUMENT_FORMAL_CONSTANT,
|
87
44
|
PM_ERR_ARGUMENT_FORMAL_GLOBAL,
|
88
45
|
PM_ERR_ARGUMENT_FORMAL_IVAR,
|
89
46
|
PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
|
90
47
|
PM_ERR_ARGUMENT_IN,
|
91
|
-
|
48
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND,
|
92
49
|
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
|
93
50
|
PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
|
51
|
+
PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR,
|
94
52
|
PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT,
|
95
53
|
PM_ERR_ARGUMENT_SPLAT_AFTER_SPLAT,
|
96
54
|
PM_ERR_ARGUMENT_TERM_PAREN,
|
@@ -109,6 +67,7 @@ typedef enum {
|
|
109
67
|
PM_ERR_BLOCK_PARAM_PIPE_TERM,
|
110
68
|
PM_ERR_BLOCK_TERM_BRACE,
|
111
69
|
PM_ERR_BLOCK_TERM_END,
|
70
|
+
PM_ERR_CANNOT_PARSE_EXPRESSION,
|
112
71
|
PM_ERR_CANNOT_PARSE_STRING_PART,
|
113
72
|
PM_ERR_CASE_EXPRESSION_AFTER_CASE,
|
114
73
|
PM_ERR_CASE_EXPRESSION_AFTER_WHEN,
|
@@ -120,6 +79,7 @@ typedef enum {
|
|
120
79
|
PM_ERR_CLASS_SUPERCLASS,
|
121
80
|
PM_ERR_CLASS_TERM,
|
122
81
|
PM_ERR_CLASS_UNEXPECTED_END,
|
82
|
+
PM_ERR_CLASS_VARIABLE_BARE,
|
123
83
|
PM_ERR_CONDITIONAL_ELSIF_PREDICATE,
|
124
84
|
PM_ERR_CONDITIONAL_IF_PREDICATE,
|
125
85
|
PM_ERR_CONDITIONAL_PREDICATE_TERM,
|
@@ -132,7 +92,6 @@ typedef enum {
|
|
132
92
|
PM_ERR_DEF_ENDLESS,
|
133
93
|
PM_ERR_DEF_ENDLESS_SETTER,
|
134
94
|
PM_ERR_DEF_NAME,
|
135
|
-
PM_ERR_DEF_NAME_AFTER_RECEIVER,
|
136
95
|
PM_ERR_DEF_PARAMS_TERM,
|
137
96
|
PM_ERR_DEF_PARAMS_TERM_PAREN,
|
138
97
|
PM_ERR_DEF_RECEIVER,
|
@@ -157,18 +116,20 @@ typedef enum {
|
|
157
116
|
PM_ERR_EXPECT_ARGUMENT,
|
158
117
|
PM_ERR_EXPECT_EOL_AFTER_STATEMENT,
|
159
118
|
PM_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ,
|
160
|
-
PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ,
|
161
119
|
PM_ERR_EXPECT_EXPRESSION_AFTER_COMMA,
|
162
120
|
PM_ERR_EXPECT_EXPRESSION_AFTER_EQUAL,
|
163
121
|
PM_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS,
|
164
122
|
PM_ERR_EXPECT_EXPRESSION_AFTER_LPAREN,
|
165
|
-
PM_ERR_EXPECT_EXPRESSION_AFTER_QUESTION,
|
166
123
|
PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR,
|
124
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ,
|
125
|
+
PM_ERR_EXPECT_EXPRESSION_AFTER_QUESTION,
|
167
126
|
PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT,
|
168
127
|
PM_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH,
|
169
128
|
PM_ERR_EXPECT_EXPRESSION_AFTER_STAR,
|
170
129
|
PM_ERR_EXPECT_IDENT_REQ_PARAMETER,
|
130
|
+
PM_ERR_EXPECT_IN_DELIMITER,
|
171
131
|
PM_ERR_EXPECT_LPAREN_REQ_PARAMETER,
|
132
|
+
PM_ERR_EXPECT_MESSAGE,
|
172
133
|
PM_ERR_EXPECT_RBRACKET,
|
173
134
|
PM_ERR_EXPECT_RPAREN,
|
174
135
|
PM_ERR_EXPECT_RPAREN_AFTER_MULTI,
|
@@ -176,32 +137,61 @@ typedef enum {
|
|
176
137
|
PM_ERR_EXPECT_STRING_CONTENT,
|
177
138
|
PM_ERR_EXPECT_WHEN_DELIMITER,
|
178
139
|
PM_ERR_EXPRESSION_BARE_HASH,
|
140
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE,
|
141
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_ENCODING,
|
142
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_FALSE,
|
143
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_FILE,
|
144
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_LINE,
|
145
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_NIL,
|
146
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_SELF,
|
147
|
+
PM_ERR_EXPRESSION_NOT_WRITABLE_TRUE,
|
148
|
+
PM_ERR_FLOAT_PARSE,
|
179
149
|
PM_ERR_FOR_COLLECTION,
|
180
150
|
PM_ERR_FOR_IN,
|
181
151
|
PM_ERR_FOR_INDEX,
|
182
152
|
PM_ERR_FOR_TERM,
|
153
|
+
PM_ERR_GLOBAL_VARIABLE_BARE,
|
183
154
|
PM_ERR_HASH_EXPRESSION_AFTER_LABEL,
|
184
155
|
PM_ERR_HASH_KEY,
|
185
156
|
PM_ERR_HASH_ROCKET,
|
186
157
|
PM_ERR_HASH_TERM,
|
187
158
|
PM_ERR_HASH_VALUE,
|
159
|
+
PM_ERR_HEREDOC_IDENTIFIER,
|
188
160
|
PM_ERR_HEREDOC_TERM,
|
189
161
|
PM_ERR_INCOMPLETE_QUESTION_MARK,
|
190
162
|
PM_ERR_INCOMPLETE_VARIABLE_CLASS,
|
163
|
+
PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3,
|
191
164
|
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE,
|
165
|
+
PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3,
|
166
|
+
PM_ERR_INSTANCE_VARIABLE_BARE,
|
167
|
+
PM_ERR_INVALID_BLOCK_EXIT,
|
168
|
+
PM_ERR_INVALID_CHARACTER,
|
192
169
|
PM_ERR_INVALID_ENCODING_MAGIC_COMMENT,
|
170
|
+
PM_ERR_INVALID_ESCAPE_CHARACTER,
|
193
171
|
PM_ERR_INVALID_FLOAT_EXPONENT,
|
172
|
+
PM_ERR_INVALID_LOCAL_VARIABLE_READ,
|
173
|
+
PM_ERR_INVALID_LOCAL_VARIABLE_WRITE,
|
174
|
+
PM_ERR_INVALID_MULTIBYTE_CHAR,
|
175
|
+
PM_ERR_INVALID_MULTIBYTE_CHARACTER,
|
176
|
+
PM_ERR_INVALID_MULTIBYTE_ESCAPE,
|
194
177
|
PM_ERR_INVALID_NUMBER_BINARY,
|
195
178
|
PM_ERR_INVALID_NUMBER_DECIMAL,
|
179
|
+
PM_ERR_INVALID_NUMBER_FRACTION,
|
196
180
|
PM_ERR_INVALID_NUMBER_HEXADECIMAL,
|
197
181
|
PM_ERR_INVALID_NUMBER_OCTAL,
|
198
|
-
|
199
|
-
|
200
|
-
PM_ERR_INVALID_MULTIBYTE_CHARACTER,
|
201
|
-
PM_ERR_INVALID_PRINTABLE_CHARACTER,
|
182
|
+
PM_ERR_INVALID_NUMBER_UNDERSCORE_INNER,
|
183
|
+
PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING,
|
202
184
|
PM_ERR_INVALID_PERCENT,
|
185
|
+
PM_ERR_INVALID_PRINTABLE_CHARACTER,
|
186
|
+
PM_ERR_INVALID_RETRY_AFTER_ELSE,
|
187
|
+
PM_ERR_INVALID_RETRY_AFTER_ENSURE,
|
188
|
+
PM_ERR_INVALID_RETRY_WITHOUT_RESCUE,
|
189
|
+
PM_ERR_INVALID_SYMBOL,
|
203
190
|
PM_ERR_INVALID_VARIABLE_GLOBAL,
|
204
|
-
|
191
|
+
PM_ERR_INVALID_VARIABLE_GLOBAL_3_3,
|
192
|
+
PM_ERR_INVALID_YIELD,
|
193
|
+
PM_ERR_IT_NOT_ALLOWED_NUMBERED,
|
194
|
+
PM_ERR_IT_NOT_ALLOWED_ORDINARY,
|
205
195
|
PM_ERR_LAMBDA_OPEN,
|
206
196
|
PM_ERR_LAMBDA_TERM_BRACE,
|
207
197
|
PM_ERR_LAMBDA_TERM_END,
|
@@ -220,10 +210,11 @@ typedef enum {
|
|
220
210
|
PM_ERR_MODULE_TERM,
|
221
211
|
PM_ERR_MULTI_ASSIGN_MULTI_SPLATS,
|
222
212
|
PM_ERR_MULTI_ASSIGN_UNEXPECTED_REST,
|
223
|
-
PM_ERR_NOT_EXPRESSION,
|
224
213
|
PM_ERR_NO_LOCAL_VARIABLE,
|
214
|
+
PM_ERR_NOT_EXPRESSION,
|
225
215
|
PM_ERR_NUMBER_LITERAL_UNDERSCORE,
|
226
|
-
|
216
|
+
PM_ERR_NUMBERED_PARAMETER_IT,
|
217
|
+
PM_ERR_NUMBERED_PARAMETER_ORDINARY,
|
227
218
|
PM_ERR_NUMBERED_PARAMETER_OUTER_SCOPE,
|
228
219
|
PM_ERR_OPERATOR_MULTI_ASSIGN,
|
229
220
|
PM_ERR_OPERATOR_WRITE_ARGUMENTS,
|
@@ -231,8 +222,9 @@ typedef enum {
|
|
231
222
|
PM_ERR_PARAMETER_ASSOC_SPLAT_MULTI,
|
232
223
|
PM_ERR_PARAMETER_BLOCK_MULTI,
|
233
224
|
PM_ERR_PARAMETER_CIRCULAR,
|
225
|
+
PM_ERR_PARAMETER_FORWARDING_AFTER_REST,
|
234
226
|
PM_ERR_PARAMETER_METHOD_NAME,
|
235
|
-
|
227
|
+
PM_ERR_PARAMETER_NAME_DUPLICATED,
|
236
228
|
PM_ERR_PARAMETER_NO_DEFAULT,
|
237
229
|
PM_ERR_PARAMETER_NO_DEFAULT_KW,
|
238
230
|
PM_ERR_PARAMETER_NUMBERED_RESERVED,
|
@@ -241,9 +233,11 @@ typedef enum {
|
|
241
233
|
PM_ERR_PARAMETER_STAR,
|
242
234
|
PM_ERR_PARAMETER_UNEXPECTED_FWD,
|
243
235
|
PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
|
236
|
+
PM_ERR_PARAMETER_UNEXPECTED_NO_KW,
|
237
|
+
PM_ERR_PATTERN_CAPTURE_DUPLICATE,
|
244
238
|
PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
|
245
|
-
PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
|
246
239
|
PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
|
240
|
+
PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
|
247
241
|
PM_ERR_PATTERN_EXPRESSION_AFTER_IN,
|
248
242
|
PM_ERR_PATTERN_EXPRESSION_AFTER_KEY,
|
249
243
|
PM_ERR_PATTERN_EXPRESSION_AFTER_PAREN,
|
@@ -251,8 +245,12 @@ typedef enum {
|
|
251
245
|
PM_ERR_PATTERN_EXPRESSION_AFTER_PIPE,
|
252
246
|
PM_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
|
253
247
|
PM_ERR_PATTERN_EXPRESSION_AFTER_REST,
|
248
|
+
PM_ERR_PATTERN_HASH_IMPLICIT,
|
254
249
|
PM_ERR_PATTERN_HASH_KEY,
|
250
|
+
PM_ERR_PATTERN_HASH_KEY_DUPLICATE,
|
251
|
+
PM_ERR_PATTERN_HASH_KEY_INTERPOLATED,
|
255
252
|
PM_ERR_PATTERN_HASH_KEY_LABEL,
|
253
|
+
PM_ERR_PATTERN_HASH_KEY_LOCALS,
|
256
254
|
PM_ERR_PATTERN_IDENT_AFTER_HROCKET,
|
257
255
|
PM_ERR_PATTERN_LABEL_AFTER_COMMA,
|
258
256
|
PM_ERR_PATTERN_REST,
|
@@ -260,12 +258,19 @@ typedef enum {
|
|
260
258
|
PM_ERR_PATTERN_TERM_BRACKET,
|
261
259
|
PM_ERR_PATTERN_TERM_PAREN,
|
262
260
|
PM_ERR_PIPEPIPEEQ_MULTI_ASSIGN,
|
261
|
+
PM_ERR_REGEXP_ENCODING_OPTION_MISMATCH,
|
262
|
+
PM_ERR_REGEXP_INCOMPAT_CHAR_ENCODING,
|
263
|
+
PM_ERR_REGEXP_INVALID_UNICODE_RANGE,
|
264
|
+
PM_ERR_REGEXP_NON_ESCAPED_MBC,
|
263
265
|
PM_ERR_REGEXP_TERM,
|
266
|
+
PM_ERR_REGEXP_UNKNOWN_OPTIONS,
|
267
|
+
PM_ERR_REGEXP_UTF8_CHAR_NON_UTF8_REGEXP,
|
264
268
|
PM_ERR_RESCUE_EXPRESSION,
|
265
269
|
PM_ERR_RESCUE_MODIFIER_VALUE,
|
266
270
|
PM_ERR_RESCUE_TERM,
|
267
271
|
PM_ERR_RESCUE_VARIABLE,
|
268
272
|
PM_ERR_RETURN_INVALID,
|
273
|
+
PM_ERR_SCRIPT_NOT_FOUND,
|
269
274
|
PM_ERR_SINGLETON_FOR_LITERALS,
|
270
275
|
PM_ERR_STATEMENT_ALIAS,
|
271
276
|
PM_ERR_STATEMENT_POSTEXE_END,
|
@@ -282,9 +287,13 @@ typedef enum {
|
|
282
287
|
PM_ERR_TERNARY_EXPRESSION_FALSE,
|
283
288
|
PM_ERR_TERNARY_EXPRESSION_TRUE,
|
284
289
|
PM_ERR_UNARY_RECEIVER,
|
290
|
+
PM_ERR_UNDEF_ARGUMENT,
|
291
|
+
PM_ERR_UNEXPECTED_BLOCK_ARGUMENT,
|
292
|
+
PM_ERR_UNEXPECTED_INDEX_BLOCK,
|
293
|
+
PM_ERR_UNEXPECTED_INDEX_KEYWORDS,
|
294
|
+
PM_ERR_UNEXPECTED_SAFE_NAVIGATION,
|
285
295
|
PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT,
|
286
296
|
PM_ERR_UNEXPECTED_TOKEN_IGNORE,
|
287
|
-
PM_ERR_UNDEF_ARGUMENT,
|
288
297
|
PM_ERR_UNTIL_TERM,
|
289
298
|
PM_ERR_VOID_EXPRESSION,
|
290
299
|
PM_ERR_WHILE_TERM,
|
@@ -293,17 +302,102 @@ typedef enum {
|
|
293
302
|
PM_ERR_WRITE_TARGET_UNEXPECTED,
|
294
303
|
PM_ERR_XSTRING_TERM,
|
295
304
|
|
296
|
-
// These are the warning
|
305
|
+
// These are the warning diagnostics.
|
297
306
|
PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS,
|
298
307
|
PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
|
308
|
+
PM_WARN_AMBIGUOUS_PREFIX_AMPERSAND,
|
299
309
|
PM_WARN_AMBIGUOUS_PREFIX_STAR,
|
310
|
+
PM_WARN_AMBIGUOUS_PREFIX_STAR_STAR,
|
300
311
|
PM_WARN_AMBIGUOUS_SLASH,
|
312
|
+
PM_WARN_COMPARISON_AFTER_COMPARISON,
|
313
|
+
PM_WARN_DOT_DOT_DOT_EOL,
|
314
|
+
PM_WARN_EQUAL_IN_CONDITIONAL,
|
315
|
+
PM_WARN_EQUAL_IN_CONDITIONAL_3_3,
|
301
316
|
PM_WARN_END_IN_METHOD,
|
302
|
-
|
303
|
-
|
304
|
-
|
317
|
+
PM_WARN_DUPLICATED_HASH_KEY,
|
318
|
+
PM_WARN_DUPLICATED_WHEN_CLAUSE,
|
319
|
+
PM_WARN_FLOAT_OUT_OF_RANGE,
|
320
|
+
PM_WARN_IGNORED_FROZEN_STRING_LITERAL,
|
321
|
+
PM_WARN_INTEGER_IN_FLIP_FLOP,
|
322
|
+
PM_WARN_INVALID_CHARACTER,
|
323
|
+
PM_WARN_INVALID_NUMBERED_REFERENCE,
|
324
|
+
PM_WARN_INVALID_SHAREABLE_CONSTANT_VALUE,
|
325
|
+
PM_WARN_KEYWORD_EOL,
|
326
|
+
PM_WARN_LITERAL_IN_CONDITION_DEFAULT,
|
327
|
+
PM_WARN_LITERAL_IN_CONDITION_VERBOSE,
|
328
|
+
PM_WARN_SHAREABLE_CONSTANT_VALUE_LINE,
|
329
|
+
PM_WARN_SHEBANG_CARRIAGE_RETURN,
|
330
|
+
PM_WARN_UNEXPECTED_CARRIAGE_RETURN,
|
331
|
+
PM_WARN_UNREACHABLE_STATEMENT,
|
332
|
+
PM_WARN_UNUSED_LOCAL_VARIABLE,
|
333
|
+
PM_WARN_VOID_STATEMENT,
|
305
334
|
} pm_diagnostic_id_t;
|
306
335
|
|
336
|
+
/**
|
337
|
+
* This struct represents a diagnostic generated during parsing.
|
338
|
+
*
|
339
|
+
* @extends pm_list_node_t
|
340
|
+
*/
|
341
|
+
typedef struct {
|
342
|
+
/** The embedded base node. */
|
343
|
+
pm_list_node_t node;
|
344
|
+
|
345
|
+
/** The location of the diagnostic in the source. */
|
346
|
+
pm_location_t location;
|
347
|
+
|
348
|
+
/** The ID of the diagnostic. */
|
349
|
+
pm_diagnostic_id_t diag_id;
|
350
|
+
|
351
|
+
/** The message associated with the diagnostic. */
|
352
|
+
const char *message;
|
353
|
+
|
354
|
+
/**
|
355
|
+
* Whether or not the memory related to the message of this diagnostic is
|
356
|
+
* owned by this diagnostic. If it is, it needs to be freed when the
|
357
|
+
* diagnostic is freed.
|
358
|
+
*/
|
359
|
+
bool owned;
|
360
|
+
|
361
|
+
/**
|
362
|
+
* The level of the diagnostic, see `pm_error_level_t` and
|
363
|
+
* `pm_warning_level_t` for possible values.
|
364
|
+
*/
|
365
|
+
uint8_t level;
|
366
|
+
} pm_diagnostic_t;
|
367
|
+
|
368
|
+
/**
|
369
|
+
* The levels of errors generated during parsing.
|
370
|
+
*/
|
371
|
+
typedef enum {
|
372
|
+
/** For errors that should raise a syntax error. */
|
373
|
+
PM_ERROR_LEVEL_SYNTAX = 0,
|
374
|
+
|
375
|
+
/** For errors that should raise an argument error. */
|
376
|
+
PM_ERROR_LEVEL_ARGUMENT = 1,
|
377
|
+
|
378
|
+
/** For errors that should raise a load error. */
|
379
|
+
PM_ERROR_LEVEL_LOAD = 2
|
380
|
+
} pm_error_level_t;
|
381
|
+
|
382
|
+
/**
|
383
|
+
* The levels of warnings generated during parsing.
|
384
|
+
*/
|
385
|
+
typedef enum {
|
386
|
+
/** For warnings which should be emitted if $VERBOSE != nil. */
|
387
|
+
PM_WARNING_LEVEL_DEFAULT = 0,
|
388
|
+
|
389
|
+
/** For warnings which should be emitted if $VERBOSE == true. */
|
390
|
+
PM_WARNING_LEVEL_VERBOSE = 1
|
391
|
+
} pm_warning_level_t;
|
392
|
+
|
393
|
+
/**
|
394
|
+
* Get the human-readable name of the given diagnostic ID.
|
395
|
+
*
|
396
|
+
* @param diag_id The diagnostic ID.
|
397
|
+
* @return The human-readable name of the diagnostic ID.
|
398
|
+
*/
|
399
|
+
const char * pm_diagnostic_id_human(pm_diagnostic_id_t diag_id);
|
400
|
+
|
307
401
|
/**
|
308
402
|
* Append a diagnostic to the given list of diagnostics that is using shared
|
309
403
|
* memory for its message.
|
data/include/prism/encoding.h
CHANGED
@@ -135,7 +135,14 @@ extern const uint8_t pm_encoding_unicode_table[256];
|
|
135
135
|
*/
|
136
136
|
typedef enum {
|
137
137
|
PM_ENCODING_UTF_8 = 0,
|
138
|
+
PM_ENCODING_US_ASCII,
|
138
139
|
PM_ENCODING_ASCII_8BIT,
|
140
|
+
PM_ENCODING_EUC_JP,
|
141
|
+
PM_ENCODING_WINDOWS_31J,
|
142
|
+
|
143
|
+
// We optionally support excluding the full set of encodings to only support the
|
144
|
+
// minimum necessary to process Ruby code without encoding comments.
|
145
|
+
#ifndef PRISM_ENCODING_EXCLUDE_FULL
|
139
146
|
PM_ENCODING_BIG5,
|
140
147
|
PM_ENCODING_BIG5_HKSCS,
|
141
148
|
PM_ENCODING_BIG5_UAO,
|
@@ -148,7 +155,6 @@ typedef enum {
|
|
148
155
|
PM_ENCODING_CP950,
|
149
156
|
PM_ENCODING_CP951,
|
150
157
|
PM_ENCODING_EMACS_MULE,
|
151
|
-
PM_ENCODING_EUC_JP,
|
152
158
|
PM_ENCODING_EUC_JP_MS,
|
153
159
|
PM_ENCODING_EUC_JIS_2004,
|
154
160
|
PM_ENCODING_EUC_KR,
|
@@ -208,7 +214,6 @@ typedef enum {
|
|
208
214
|
PM_ENCODING_STATELESS_ISO_2022_JP,
|
209
215
|
PM_ENCODING_STATELESS_ISO_2022_JP_KDDI,
|
210
216
|
PM_ENCODING_TIS_620,
|
211
|
-
PM_ENCODING_US_ASCII,
|
212
217
|
PM_ENCODING_UTF8_MAC,
|
213
218
|
PM_ENCODING_UTF8_DOCOMO,
|
214
219
|
PM_ENCODING_UTF8_KDDI,
|
@@ -222,8 +227,9 @@ typedef enum {
|
|
222
227
|
PM_ENCODING_WINDOWS_1256,
|
223
228
|
PM_ENCODING_WINDOWS_1257,
|
224
229
|
PM_ENCODING_WINDOWS_1258,
|
225
|
-
PM_ENCODING_WINDOWS_31J,
|
226
230
|
PM_ENCODING_WINDOWS_874,
|
231
|
+
#endif
|
232
|
+
|
227
233
|
PM_ENCODING_MAXIMUM
|
228
234
|
} pm_encoding_type_t;
|
229
235
|
|
@@ -248,10 +254,22 @@ extern const pm_encoding_t pm_encodings[PM_ENCODING_MAXIMUM];
|
|
248
254
|
/**
|
249
255
|
* This is the ASCII-8BIT encoding. We need a reference to it so that pm_strpbrk
|
250
256
|
* can compare against it because invalid multibyte characters are not a thing
|
251
|
-
* in this encoding.
|
257
|
+
* in this encoding. It is also needed for handling Regexp encoding flags.
|
252
258
|
*/
|
253
259
|
#define PM_ENCODING_ASCII_8BIT_ENTRY (&pm_encodings[PM_ENCODING_ASCII_8BIT])
|
254
260
|
|
261
|
+
/**
|
262
|
+
* This is the EUC-JP encoding. We need a reference to it to quickly process
|
263
|
+
* regular expression modifiers.
|
264
|
+
*/
|
265
|
+
#define PM_ENCODING_EUC_JP_ENTRY (&pm_encodings[PM_ENCODING_EUC_JP])
|
266
|
+
|
267
|
+
/**
|
268
|
+
* This is the Windows-31J encoding. We need a reference to it to quickly
|
269
|
+
* process regular expression modifiers.
|
270
|
+
*/
|
271
|
+
#define PM_ENCODING_WINDOWS_31J_ENTRY (&pm_encodings[PM_ENCODING_WINDOWS_31J])
|
272
|
+
|
255
273
|
/**
|
256
274
|
* Parse the given name of an encoding and return a pointer to the corresponding
|
257
275
|
* encoding struct if one can be found, otherwise return NULL.
|