prism 0.24.0 → 0.25.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 +50 -1
- data/Makefile +5 -2
- data/README.md +45 -6
- data/config.yml +499 -4
- data/docs/build_system.md +31 -0
- data/docs/configuration.md +2 -0
- data/docs/cruby_compilation.md +1 -1
- data/docs/parser_translation.md +14 -9
- data/docs/releasing.md +2 -2
- 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 +911 -815
- data/ext/prism/api_pack.c +9 -0
- data/ext/prism/extconf.rb +27 -11
- data/ext/prism/extension.c +313 -66
- data/ext/prism/extension.h +5 -4
- data/include/prism/ast.h +213 -64
- data/include/prism/defines.h +106 -2
- data/include/prism/diagnostic.h +134 -71
- data/include/prism/encoding.h +22 -4
- data/include/prism/node.h +93 -0
- data/include/prism/options.h +82 -7
- data/include/prism/pack.h +11 -0
- data/include/prism/parser.h +198 -53
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/static_literals.h +118 -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 +1 -1
- data/lib/prism/dispatcher.rb +29 -0
- data/lib/prism/dot_visitor.rb +87 -16
- data/lib/prism/dsl.rb +24 -12
- data/lib/prism/ffi.rb +67 -12
- data/lib/prism/lex_compat.rb +17 -15
- data/lib/prism/mutation_compiler.rb +11 -0
- data/lib/prism/node.rb +2096 -2499
- data/lib/prism/node_ext.rb +77 -29
- data/lib/prism/pack.rb +4 -0
- data/lib/prism/parse_result/comments.rb +34 -17
- data/lib/prism/parse_result/newlines.rb +3 -1
- data/lib/prism/parse_result.rb +78 -32
- data/lib/prism/pattern.rb +16 -4
- data/lib/prism/polyfill/string.rb +12 -0
- data/lib/prism/serialize.rb +439 -102
- data/lib/prism/translation/parser/compiler.rb +152 -50
- data/lib/prism/translation/parser/lexer.rb +103 -22
- data/lib/prism/translation/parser/rubocop.rb +41 -13
- data/lib/prism/translation/parser.rb +119 -7
- 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 +3212 -462
- data/lib/prism/translation/ruby_parser.rb +35 -18
- data/lib/prism/translation.rb +3 -1
- data/lib/prism/visitor.rb +10 -0
- data/lib/prism.rb +8 -2
- data/prism.gemspec +33 -4
- data/rbi/prism/compiler.rbi +14 -0
- data/rbi/prism/desugar_compiler.rbi +5 -0
- data/rbi/prism/mutation_compiler.rbi +5 -0
- data/rbi/prism/node.rbi +8221 -0
- data/rbi/prism/node_ext.rbi +102 -0
- data/rbi/prism/parse_result.rbi +304 -0
- data/rbi/prism/translation/parser/compiler.rbi +13 -0
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
- data/rbi/prism/translation/ripper.rbi +25 -0
- data/rbi/prism/translation/ruby_parser.rbi +11 -0
- data/rbi/prism/visitor.rbi +470 -0
- data/rbi/prism.rbi +39 -7749
- 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/mutation_compiler.rbs +158 -0
- data/sig/prism/node.rbs +3529 -0
- data/sig/prism/node_ext.rbs +78 -0
- data/sig/prism/pack.rbs +43 -0
- data/sig/prism/parse_result.rbs +127 -0
- data/sig/prism/pattern.rbs +13 -0
- data/sig/prism/serialize.rbs +7 -0
- data/sig/prism/visitor.rbs +168 -0
- data/sig/prism.rbs +188 -4767
- data/src/diagnostic.c +575 -230
- data/src/encoding.c +211 -108
- data/src/node.c +7526 -447
- data/src/options.c +36 -12
- data/src/pack.c +33 -17
- data/src/prettyprint.c +1294 -1385
- data/src/prism.c +3628 -1099
- data/src/regexp.c +17 -2
- data/src/serialize.c +47 -28
- data/src/static_literals.c +552 -0
- data/src/token_type.c +1 -0
- 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 +629 -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 +35 -6
- data/docs/ripper.md +0 -36
- data/rbi/prism_static.rbi +0 -207
- data/sig/prism_static.rbs +0 -201
@@ -0,0 +1,119 @@
|
|
1
|
+
/**
|
2
|
+
* @file pm_integer.h
|
3
|
+
*
|
4
|
+
* This module provides functions for working with arbitrary-sized integers.
|
5
|
+
*/
|
6
|
+
#ifndef PRISM_NUMBER_H
|
7
|
+
#define PRISM_NUMBER_H
|
8
|
+
|
9
|
+
#include "prism/defines.h"
|
10
|
+
#include "prism/util/pm_buffer.h"
|
11
|
+
|
12
|
+
#include <assert.h>
|
13
|
+
#include <stdbool.h>
|
14
|
+
#include <stdint.h>
|
15
|
+
#include <stdlib.h>
|
16
|
+
|
17
|
+
/**
|
18
|
+
* A structure represents an arbitrary-sized integer.
|
19
|
+
*/
|
20
|
+
typedef struct {
|
21
|
+
/**
|
22
|
+
* Embedded value for small integer. This value is set to 0 if the value
|
23
|
+
* does not fit into uint32_t.
|
24
|
+
*/
|
25
|
+
uint32_t value;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* The number of allocated values. length is set to 0 if the integer fits
|
29
|
+
* into uint32_t.
|
30
|
+
*/
|
31
|
+
size_t length;
|
32
|
+
|
33
|
+
/**
|
34
|
+
* List of 32-bit integers. Set to NULL if the integer fits into uint32_t.
|
35
|
+
*/
|
36
|
+
uint32_t *values;
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Whether or not the integer is negative. It is stored this way so that a
|
40
|
+
* zeroed pm_integer_t is always positive zero.
|
41
|
+
*/
|
42
|
+
bool negative;
|
43
|
+
} pm_integer_t;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* An enum controlling the base of an integer. It is expected that the base is
|
47
|
+
* already known before parsing the integer, even though it could be derived
|
48
|
+
* from the string itself.
|
49
|
+
*/
|
50
|
+
typedef enum {
|
51
|
+
/** The binary base, indicated by a 0b or 0B prefix. */
|
52
|
+
PM_INTEGER_BASE_BINARY,
|
53
|
+
|
54
|
+
/** The octal base, indicated by a 0, 0o, or 0O prefix. */
|
55
|
+
PM_INTEGER_BASE_OCTAL,
|
56
|
+
|
57
|
+
/** The decimal base, indicated by a 0d, 0D, or empty prefix. */
|
58
|
+
PM_INTEGER_BASE_DECIMAL,
|
59
|
+
|
60
|
+
/** The hexadecimal base, indicated by a 0x or 0X prefix. */
|
61
|
+
PM_INTEGER_BASE_HEXADECIMAL,
|
62
|
+
|
63
|
+
/**
|
64
|
+
* An unknown base, in which case pm_integer_parse will derive it based on
|
65
|
+
* the content of the string. This is less efficient and does more
|
66
|
+
* comparisons, so if callers know the base ahead of time, they should use
|
67
|
+
* that instead.
|
68
|
+
*/
|
69
|
+
PM_INTEGER_BASE_UNKNOWN
|
70
|
+
} pm_integer_base_t;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Parse an integer from a string. This assumes that the format of the integer
|
74
|
+
* has already been validated, as internal validation checks are not performed
|
75
|
+
* here.
|
76
|
+
*
|
77
|
+
* @param integer The integer to parse into.
|
78
|
+
* @param base The base of the integer.
|
79
|
+
* @param start The start of the string.
|
80
|
+
* @param end The end of the string.
|
81
|
+
*/
|
82
|
+
PRISM_EXPORTED_FUNCTION void pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end);
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Return the memory size of the integer.
|
86
|
+
*
|
87
|
+
* @param integer The integer to get the memory size of.
|
88
|
+
* @return The size of the memory associated with the integer.
|
89
|
+
*/
|
90
|
+
size_t pm_integer_memsize(const pm_integer_t *integer);
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Compare two integers. This function returns -1 if the left integer is less
|
94
|
+
* than the right integer, 0 if they are equal, and 1 if the left integer is
|
95
|
+
* greater than the right integer.
|
96
|
+
*
|
97
|
+
* @param left The left integer to compare.
|
98
|
+
* @param right The right integer to compare.
|
99
|
+
* @return The result of the comparison.
|
100
|
+
*/
|
101
|
+
int pm_integer_compare(const pm_integer_t *left, const pm_integer_t *right);
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Convert an integer to a decimal string.
|
105
|
+
*
|
106
|
+
* @param buffer The buffer to append the string to.
|
107
|
+
* @param integer The integer to convert to a string.
|
108
|
+
*/
|
109
|
+
PRISM_EXPORTED_FUNCTION void pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer);
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Free the internal memory of an integer. This memory will only be allocated if
|
113
|
+
* the integer exceeds the size of a single node in the linked list.
|
114
|
+
*
|
115
|
+
* @param integer The integer to free.
|
116
|
+
*/
|
117
|
+
PRISM_EXPORTED_FUNCTION void pm_integer_free(pm_integer_t *integer);
|
118
|
+
|
119
|
+
#endif
|
@@ -61,6 +61,14 @@ typedef struct {
|
|
61
61
|
*/
|
62
62
|
bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity);
|
63
63
|
|
64
|
+
/**
|
65
|
+
* Clear out the newlines that have been appended to the list.
|
66
|
+
*
|
67
|
+
* @param list The list to clear.
|
68
|
+
*/
|
69
|
+
void
|
70
|
+
pm_newline_list_clear(pm_newline_list_t *list);
|
71
|
+
|
64
72
|
/**
|
65
73
|
* Append a new offset to the newline list. Returns true if the reallocation of
|
66
74
|
* the offsets succeeds (if one was necessary), otherwise returns false.
|
@@ -17,11 +17,10 @@
|
|
17
17
|
// The following headers are necessary to read files using demand paging.
|
18
18
|
#ifdef _WIN32
|
19
19
|
#include <windows.h>
|
20
|
-
#
|
20
|
+
#elif defined(_POSIX_MAPPED_FILES)
|
21
21
|
#include <fcntl.h>
|
22
22
|
#include <sys/mman.h>
|
23
23
|
#include <sys/stat.h>
|
24
|
-
#include <unistd.h>
|
25
24
|
#endif
|
26
25
|
|
27
26
|
/**
|
@@ -45,8 +44,10 @@ typedef struct {
|
|
45
44
|
/** This string owns its memory, and should be freed using `pm_string_free`. */
|
46
45
|
PM_STRING_OWNED,
|
47
46
|
|
47
|
+
#ifdef PRISM_HAS_MMAP
|
48
48
|
/** This string is a memory-mapped file, and should be freed using `pm_string_free`. */
|
49
49
|
PM_STRING_MAPPED
|
50
|
+
#endif
|
50
51
|
} type;
|
51
52
|
} pm_string_t;
|
52
53
|
|
@@ -108,6 +109,17 @@ void pm_string_constant_init(pm_string_t *string, const char *source, size_t len
|
|
108
109
|
*/
|
109
110
|
PRISM_EXPORTED_FUNCTION bool pm_string_mapped_init(pm_string_t *string, const char *filepath);
|
110
111
|
|
112
|
+
/**
|
113
|
+
* Read the file indicated by the filepath parameter into source and load its
|
114
|
+
* contents and size into the given `pm_string_t`. The given `pm_string_t`
|
115
|
+
* should be freed using `pm_string_free` when it is no longer used.
|
116
|
+
*
|
117
|
+
* @param string The string to initialize.
|
118
|
+
* @param filepath The filepath to read.
|
119
|
+
* @return Whether or not the file was successfully read.
|
120
|
+
*/
|
121
|
+
PRISM_EXPORTED_FUNCTION bool pm_string_file_init(pm_string_t *string, const char *filepath);
|
122
|
+
|
111
123
|
/**
|
112
124
|
* Returns the memory size associated with the string.
|
113
125
|
*
|
@@ -124,6 +136,18 @@ size_t pm_string_memsize(const pm_string_t *string);
|
|
124
136
|
*/
|
125
137
|
void pm_string_ensure_owned(pm_string_t *string);
|
126
138
|
|
139
|
+
/**
|
140
|
+
* Compare the underlying lengths and bytes of two strings. Returns 0 if the
|
141
|
+
* strings are equal, a negative number if the left string is less than the
|
142
|
+
* right string, and a positive number if the left string is greater than the
|
143
|
+
* right string.
|
144
|
+
*
|
145
|
+
* @param left The left string to compare.
|
146
|
+
* @param right The right string to compare.
|
147
|
+
* @return The comparison result.
|
148
|
+
*/
|
149
|
+
int pm_string_compare(const pm_string_t *left, const pm_string_t *right);
|
150
|
+
|
127
151
|
/**
|
128
152
|
* Returns the length associated with the string.
|
129
153
|
*
|
data/include/prism/version.h
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
/**
|
15
15
|
* The minor version of the Prism library as an int.
|
16
16
|
*/
|
17
|
-
#define PRISM_VERSION_MINOR
|
17
|
+
#define PRISM_VERSION_MINOR 25
|
18
18
|
|
19
19
|
/**
|
20
20
|
* The patch version of the Prism library as an int.
|
@@ -24,6 +24,6 @@
|
|
24
24
|
/**
|
25
25
|
* The version of the Prism library as a constant string.
|
26
26
|
*/
|
27
|
-
#define PRISM_VERSION "0.
|
27
|
+
#define PRISM_VERSION "0.25.0"
|
28
28
|
|
29
29
|
#endif
|
data/include/prism.h
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
#include "prism/defines.h"
|
10
10
|
#include "prism/util/pm_buffer.h"
|
11
11
|
#include "prism/util/pm_char.h"
|
12
|
+
#include "prism/util/pm_integer.h"
|
12
13
|
#include "prism/util/pm_memchr.h"
|
13
14
|
#include "prism/util/pm_strncasecmp.h"
|
14
15
|
#include "prism/util/pm_strpbrk.h"
|
@@ -20,10 +21,13 @@
|
|
20
21
|
#include "prism/parser.h"
|
21
22
|
#include "prism/prettyprint.h"
|
22
23
|
#include "prism/regexp.h"
|
24
|
+
#include "prism/static_literals.h"
|
23
25
|
#include "prism/version.h"
|
24
26
|
|
25
27
|
#include <assert.h>
|
26
28
|
#include <errno.h>
|
29
|
+
#include <locale.h>
|
30
|
+
#include <math.h>
|
27
31
|
#include <stdarg.h>
|
28
32
|
#include <stdbool.h>
|
29
33
|
#include <stdint.h>
|
@@ -76,6 +80,41 @@ PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
|
|
76
80
|
*/
|
77
81
|
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser);
|
78
82
|
|
83
|
+
/**
|
84
|
+
* This function is used in pm_parse_stream to retrieve a line of input from a
|
85
|
+
* stream. It closely mirrors that of fgets so that fgets can be used as the
|
86
|
+
* default implementation.
|
87
|
+
*/
|
88
|
+
typedef char * (pm_parse_stream_fgets_t)(char *string, int size, void *stream);
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Parse a stream of Ruby source and return the tree.
|
92
|
+
*
|
93
|
+
* @param parser The parser to use.
|
94
|
+
* @param buffer The buffer to use.
|
95
|
+
* @param stream The stream to parse.
|
96
|
+
* @param fgets The function to use to read from the stream.
|
97
|
+
* @param options The optional options to use when parsing.
|
98
|
+
* @return The AST representing the source.
|
99
|
+
*/
|
100
|
+
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse_stream(pm_parser_t *parser, pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *fgets, const pm_options_t *options);
|
101
|
+
|
102
|
+
// We optionally support serializing to a binary string. For systems that don't
|
103
|
+
// want or need this functionality, it can be turned off with the
|
104
|
+
// PRISM_EXCLUDE_SERIALIZATION define.
|
105
|
+
#ifndef PRISM_EXCLUDE_SERIALIZATION
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Parse and serialize the AST represented by the source that is read out of the
|
109
|
+
* given stream into to the given buffer.
|
110
|
+
*
|
111
|
+
* @param buffer The buffer to serialize to.
|
112
|
+
* @param stream The stream to parse.
|
113
|
+
* @param fgets The function to use to read from the stream.
|
114
|
+
* @param data The optional data to pass to the parser.
|
115
|
+
*/
|
116
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_stream(pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *fgets, const char *data);
|
117
|
+
|
79
118
|
/**
|
80
119
|
* Serialize the given list of comments to the given buffer.
|
81
120
|
*
|
@@ -152,6 +191,8 @@ PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t
|
|
152
191
|
*/
|
153
192
|
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
|
154
193
|
|
194
|
+
#endif
|
195
|
+
|
155
196
|
/**
|
156
197
|
* Parse the source and return true if it parses without errors or warnings.
|
157
198
|
*
|
@@ -182,10 +223,27 @@ const char * pm_token_type_human(pm_token_type_t token_type);
|
|
182
223
|
* Format the errors on the parser into the given buffer.
|
183
224
|
*
|
184
225
|
* @param parser The parser to format the errors for.
|
226
|
+
* @param error_list The list of errors to format.
|
185
227
|
* @param buffer The buffer to format the errors into.
|
186
228
|
* @param colorize Whether or not to colorize the errors with ANSI escape sequences.
|
229
|
+
* @param inline_messages Whether or not to inline the messages with the source.
|
230
|
+
*/
|
231
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_errors_format(const pm_parser_t *parser, const pm_list_t *error_list, pm_buffer_t *buffer, bool colorize, bool inline_messages);
|
232
|
+
|
233
|
+
// We optionally support dumping to JSON. For systems that don't want or need
|
234
|
+
// this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
|
235
|
+
#ifndef PRISM_EXCLUDE_JSON
|
236
|
+
|
237
|
+
/**
|
238
|
+
* Dump JSON to the given buffer.
|
239
|
+
*
|
240
|
+
* @param buffer The buffer to serialize to.
|
241
|
+
* @param parser The parser that parsed the node.
|
242
|
+
* @param node The node to serialize.
|
187
243
|
*/
|
188
|
-
PRISM_EXPORTED_FUNCTION void
|
244
|
+
PRISM_EXPORTED_FUNCTION void pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *node);
|
245
|
+
|
246
|
+
#endif
|
189
247
|
|
190
248
|
/**
|
191
249
|
* @mainpage
|
data/lib/prism/compiler.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
=begin
|
3
4
|
This file is generated by the templates/template.rb script and should not be
|
4
5
|
modified manually. See templates/lib/prism/compiler.rb.erb
|
@@ -23,7 +24,7 @@ module Prism
|
|
23
24
|
# Prism.parse("1 + 2").value.accept(SExpressions.new)
|
24
25
|
# # => [:program, [[[:call, [[:integer], [:arguments, [[:integer]]]]]]]]
|
25
26
|
#
|
26
|
-
class Compiler
|
27
|
+
class Compiler < Visitor
|
27
28
|
# Visit an individual node.
|
28
29
|
def visit(node)
|
29
30
|
node&.accept(self)
|
@@ -300,6 +301,9 @@ module Prism
|
|
300
301
|
# Compile a InterpolatedXStringNode node
|
301
302
|
alias visit_interpolated_x_string_node visit_child_nodes
|
302
303
|
|
304
|
+
# Compile a ItParametersNode node
|
305
|
+
alias visit_it_parameters_node visit_child_nodes
|
306
|
+
|
303
307
|
# Compile a KeywordHashNode node
|
304
308
|
alias visit_keyword_hash_node visit_child_nodes
|
305
309
|
|
@@ -432,6 +436,9 @@ module Prism
|
|
432
436
|
# Compile a SelfNode node
|
433
437
|
alias visit_self_node visit_child_nodes
|
434
438
|
|
439
|
+
# Compile a ShareableConstantNode node
|
440
|
+
alias visit_shareable_constant_node visit_child_nodes
|
441
|
+
|
435
442
|
# Compile a SingletonClassNode node
|
436
443
|
alias visit_singleton_class_node visit_child_nodes
|
437
444
|
|
data/lib/prism/debug.rb
CHANGED
@@ -55,7 +55,7 @@ module Prism
|
|
55
55
|
verbose, $VERBOSE = $VERBOSE, nil
|
56
56
|
|
57
57
|
begin
|
58
|
-
locals = []
|
58
|
+
locals = [] #: Array[Array[Symbol | Integer]]
|
59
59
|
stack = [ISeq.new(RubyVM::InstructionSequence.compile(source).to_a)]
|
60
60
|
|
61
61
|
while (iseq = stack.pop)
|
@@ -96,8 +96,8 @@ module Prism
|
|
96
96
|
# For the given source, parses with prism and returns a list of all of the
|
97
97
|
# sets of local variables that were encountered.
|
98
98
|
def self.prism_locals(source)
|
99
|
-
locals = []
|
100
|
-
stack = [Prism.parse(source).value]
|
99
|
+
locals = [] #: Array[Array[Symbol | Integer]]
|
100
|
+
stack = [Prism.parse(source).value] #: Array[Prism::node]
|
101
101
|
|
102
102
|
while (node = stack.pop)
|
103
103
|
case node
|
@@ -202,5 +202,48 @@ module Prism
|
|
202
202
|
def self.newlines(source)
|
203
203
|
Prism.parse(source).source.offsets
|
204
204
|
end
|
205
|
+
|
206
|
+
# A wrapping around prism's internal encoding data structures. This is used
|
207
|
+
# for reflection and debugging purposes.
|
208
|
+
class Encoding
|
209
|
+
# The name of the encoding, that can be passed to Encoding.find.
|
210
|
+
attr_reader :name
|
211
|
+
|
212
|
+
# Initialize a new encoding with the given name and whether or not it is
|
213
|
+
# a multibyte encoding.
|
214
|
+
def initialize(name, multibyte)
|
215
|
+
@name = name
|
216
|
+
@multibyte = multibyte
|
217
|
+
end
|
218
|
+
|
219
|
+
# Whether or not the encoding is a multibyte encoding.
|
220
|
+
def multibyte?
|
221
|
+
@multibyte
|
222
|
+
end
|
223
|
+
|
224
|
+
# Returns the number of bytes of the first character in the source string,
|
225
|
+
# if it is valid for the encoding. Otherwise, returns 0.
|
226
|
+
def width(source)
|
227
|
+
Encoding._width(name, source)
|
228
|
+
end
|
229
|
+
|
230
|
+
# Returns true if the first character in the source string is a valid
|
231
|
+
# alphanumeric character for the encoding.
|
232
|
+
def alnum?(source)
|
233
|
+
Encoding._alnum?(name, source)
|
234
|
+
end
|
235
|
+
|
236
|
+
# Returns true if the first character in the source string is a valid
|
237
|
+
# alphabetic character for the encoding.
|
238
|
+
def alpha?(source)
|
239
|
+
Encoding._alpha?(name, source)
|
240
|
+
end
|
241
|
+
|
242
|
+
# Returns true if the first character in the source string is a valid
|
243
|
+
# uppercase character for the encoding.
|
244
|
+
def upper?(source)
|
245
|
+
Encoding._upper?(name, source)
|
246
|
+
end
|
247
|
+
end
|
205
248
|
end
|
206
249
|
end
|
@@ -82,7 +82,7 @@ module Prism
|
|
82
82
|
0,
|
83
83
|
read_class.new(source, *arguments, node.name_loc),
|
84
84
|
nil,
|
85
|
-
node.operator_loc.slice.chomp("="),
|
85
|
+
node.operator_loc.slice.chomp("=").to_sym,
|
86
86
|
node.operator_loc.copy(length: node.operator_loc.length - 1),
|
87
87
|
nil,
|
88
88
|
ArgumentsNode.new(source, 0, [node.value], node.value.location),
|
data/lib/prism/dispatcher.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
=begin
|
3
4
|
This file is generated by the templates/template.rb script and should not be
|
4
5
|
modified manually. See templates/lib/prism/dispatcher.rb.erb
|
@@ -761,6 +762,14 @@ module Prism
|
|
761
762
|
listeners[:on_interpolated_x_string_node_leave]&.each { |listener| listener.on_interpolated_x_string_node_leave(node) }
|
762
763
|
end
|
763
764
|
|
765
|
+
# Dispatch enter and leave events for ItParametersNode nodes and continue
|
766
|
+
# walking the tree.
|
767
|
+
def visit_it_parameters_node(node)
|
768
|
+
listeners[:on_it_parameters_node_enter]&.each { |listener| listener.on_it_parameters_node_enter(node) }
|
769
|
+
super
|
770
|
+
listeners[:on_it_parameters_node_leave]&.each { |listener| listener.on_it_parameters_node_leave(node) }
|
771
|
+
end
|
772
|
+
|
764
773
|
# Dispatch enter and leave events for KeywordHashNode nodes and continue
|
765
774
|
# walking the tree.
|
766
775
|
def visit_keyword_hash_node(node)
|
@@ -1113,6 +1122,14 @@ module Prism
|
|
1113
1122
|
listeners[:on_self_node_leave]&.each { |listener| listener.on_self_node_leave(node) }
|
1114
1123
|
end
|
1115
1124
|
|
1125
|
+
# Dispatch enter and leave events for ShareableConstantNode nodes and continue
|
1126
|
+
# walking the tree.
|
1127
|
+
def visit_shareable_constant_node(node)
|
1128
|
+
listeners[:on_shareable_constant_node_enter]&.each { |listener| listener.on_shareable_constant_node_enter(node) }
|
1129
|
+
super
|
1130
|
+
listeners[:on_shareable_constant_node_leave]&.each { |listener| listener.on_shareable_constant_node_leave(node) }
|
1131
|
+
end
|
1132
|
+
|
1116
1133
|
# Dispatch enter and leave events for SingletonClassNode nodes and continue
|
1117
1134
|
# walking the tree.
|
1118
1135
|
def visit_singleton_class_node(node)
|
@@ -1778,6 +1795,12 @@ module Prism
|
|
1778
1795
|
listeners[:on_interpolated_x_string_node_leave]&.each { |listener| listener.on_interpolated_x_string_node_leave(node) }
|
1779
1796
|
end
|
1780
1797
|
|
1798
|
+
# Dispatch enter and leave events for ItParametersNode nodes.
|
1799
|
+
def visit_it_parameters_node(node)
|
1800
|
+
listeners[:on_it_parameters_node_enter]&.each { |listener| listener.on_it_parameters_node_enter(node) }
|
1801
|
+
listeners[:on_it_parameters_node_leave]&.each { |listener| listener.on_it_parameters_node_leave(node) }
|
1802
|
+
end
|
1803
|
+
|
1781
1804
|
# Dispatch enter and leave events for KeywordHashNode nodes.
|
1782
1805
|
def visit_keyword_hash_node(node)
|
1783
1806
|
listeners[:on_keyword_hash_node_enter]&.each { |listener| listener.on_keyword_hash_node_enter(node) }
|
@@ -2042,6 +2065,12 @@ module Prism
|
|
2042
2065
|
listeners[:on_self_node_leave]&.each { |listener| listener.on_self_node_leave(node) }
|
2043
2066
|
end
|
2044
2067
|
|
2068
|
+
# Dispatch enter and leave events for ShareableConstantNode nodes.
|
2069
|
+
def visit_shareable_constant_node(node)
|
2070
|
+
listeners[:on_shareable_constant_node_enter]&.each { |listener| listener.on_shareable_constant_node_enter(node) }
|
2071
|
+
listeners[:on_shareable_constant_node_leave]&.each { |listener| listener.on_shareable_constant_node_leave(node) }
|
2072
|
+
end
|
2073
|
+
|
2045
2074
|
# Dispatch enter and leave events for SingletonClassNode nodes.
|
2046
2075
|
def visit_singleton_class_node(node)
|
2047
2076
|
listeners[:on_singleton_class_node_enter]&.each { |listener| listener.on_singleton_class_node_enter(node) }
|