prism 0.22.0 → 0.24.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -1
- data/README.md +2 -1
- data/docs/releasing.md +67 -17
- data/docs/ruby_parser_translation.md +19 -0
- data/docs/serialization.md +2 -0
- data/ext/prism/api_node.c +1982 -1538
- data/ext/prism/extension.c +12 -7
- data/ext/prism/extension.h +2 -2
- data/include/prism/diagnostic.h +3 -4
- data/include/prism/encoding.h +7 -0
- data/include/prism/util/pm_constant_pool.h +1 -1
- data/include/prism/util/pm_newline_list.h +4 -3
- data/include/prism/util/pm_strpbrk.h +4 -1
- data/include/prism/version.h +2 -2
- data/lib/prism/desugar_compiler.rb +225 -80
- data/lib/prism/dsl.rb +302 -299
- data/lib/prism/ffi.rb +103 -77
- data/lib/prism/lex_compat.rb +1 -0
- data/lib/prism/node.rb +3624 -2114
- data/lib/prism/node_ext.rb +25 -2
- data/lib/prism/parse_result.rb +56 -19
- data/lib/prism/serialize.rb +605 -303
- data/lib/prism/translation/parser/compiler.rb +1 -1
- data/lib/prism/translation/parser/rubocop.rb +11 -3
- data/lib/prism/translation/parser.rb +25 -12
- data/lib/prism/translation/parser33.rb +12 -0
- data/lib/prism/translation/parser34.rb +12 -0
- data/lib/prism/translation/ripper.rb +696 -0
- data/lib/prism/translation/ruby_parser.rb +1521 -0
- data/lib/prism/translation.rb +3 -3
- data/lib/prism.rb +0 -1
- data/prism.gemspec +6 -2
- data/src/diagnostic.c +10 -11
- data/src/encoding.c +16 -17
- data/src/options.c +7 -2
- data/src/prettyprint.c +3 -3
- data/src/prism.c +172 -97
- data/src/serialize.c +24 -13
- data/src/token_type.c +3 -3
- data/src/util/pm_constant_pool.c +1 -1
- data/src/util/pm_newline_list.c +6 -3
- data/src/util/pm_strpbrk.c +122 -14
- metadata +8 -4
- data/lib/prism/ripper_compat.rb +0 -285
@@ -1477,7 +1477,7 @@ module Prism
|
|
1477
1477
|
# ^^^^^
|
1478
1478
|
def visit_string_node(node)
|
1479
1479
|
if node.opening&.start_with?("<<")
|
1480
|
-
children, closing = visit_heredoc(InterpolatedStringNode.new(node.opening_loc, [node.copy(opening_loc: nil, closing_loc: nil, location: node.content_loc)], node.closing_loc, node.location))
|
1480
|
+
children, closing = visit_heredoc(InterpolatedStringNode.new(node.send(:source), node.opening_loc, [node.copy(opening_loc: nil, closing_loc: nil, location: node.content_loc)], node.closing_loc, node.location))
|
1481
1481
|
builder.string_compose(token(node.opening_loc), children, closing)
|
1482
1482
|
elsif node.opening == "?"
|
1483
1483
|
builder.character([node.unescaped, srange(node.location)])
|
@@ -9,18 +9,26 @@ require "prism/translation/parser"
|
|
9
9
|
module Prism
|
10
10
|
module Translation
|
11
11
|
class Parser
|
12
|
-
# This is the special version
|
12
|
+
# This is the special version numbers that should be used in RuboCop
|
13
13
|
# configuration files to trigger using prism.
|
14
|
+
|
15
|
+
# For Ruby 3.3
|
14
16
|
VERSION_3_3 = 80_82_73_83_77.33
|
15
17
|
|
18
|
+
# For Ruby 3.4
|
19
|
+
VERSION_3_4 = 80_82_73_83_77.34
|
20
|
+
|
16
21
|
# This module gets prepended into RuboCop::AST::ProcessedSource.
|
17
22
|
module ProcessedSource
|
18
23
|
# Redefine parser_class so that we can inject the prism parser into the
|
19
24
|
# list of known parsers.
|
20
25
|
def parser_class(ruby_version)
|
21
26
|
if ruby_version == Prism::Translation::Parser::VERSION_3_3
|
22
|
-
require "prism/translation/
|
23
|
-
Prism::Translation::
|
27
|
+
require "prism/translation/parser33"
|
28
|
+
Prism::Translation::Parser33
|
29
|
+
elsif ruby_version == Prism::Translation::Parser::VERSION_3_4
|
30
|
+
require "prism/translation/parser34"
|
31
|
+
Prism::Translation::Parser34
|
24
32
|
else
|
25
33
|
super
|
26
34
|
end
|
@@ -43,7 +43,7 @@ module Prism
|
|
43
43
|
source = source_buffer.source
|
44
44
|
|
45
45
|
offset_cache = build_offset_cache(source)
|
46
|
-
result = unwrap(Prism.parse(source, filepath: source_buffer.name), offset_cache)
|
46
|
+
result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version)), offset_cache)
|
47
47
|
|
48
48
|
build_ast(result.value, offset_cache)
|
49
49
|
ensure
|
@@ -56,7 +56,7 @@ module Prism
|
|
56
56
|
source = source_buffer.source
|
57
57
|
|
58
58
|
offset_cache = build_offset_cache(source)
|
59
|
-
result = unwrap(Prism.parse(source, filepath: source_buffer.name), offset_cache)
|
59
|
+
result = unwrap(Prism.parse(source, filepath: source_buffer.name, version: convert_for_prism(version)), offset_cache)
|
60
60
|
|
61
61
|
[
|
62
62
|
build_ast(result.value, offset_cache),
|
@@ -75,7 +75,7 @@ module Prism
|
|
75
75
|
offset_cache = build_offset_cache(source)
|
76
76
|
result =
|
77
77
|
begin
|
78
|
-
unwrap(Prism.parse_lex(source, filepath: source_buffer.name), offset_cache)
|
78
|
+
unwrap(Prism.parse_lex(source, filepath: source_buffer.name, version: convert_for_prism(version)), offset_cache)
|
79
79
|
rescue ::Parser::SyntaxError
|
80
80
|
raise if !recover
|
81
81
|
end
|
@@ -124,20 +124,21 @@ module Prism
|
|
124
124
|
# build the parser gem AST.
|
125
125
|
#
|
126
126
|
# If the bytesize of the source is the same as the length, then we can
|
127
|
-
# just use the offset directly. Otherwise, we build
|
128
|
-
#
|
129
|
-
#
|
130
|
-
# This is a good opportunity for some optimizations. If the source file
|
131
|
-
# has any multi-byte characters, this can tank the performance of the
|
132
|
-
# translator. We could make this significantly faster by using a
|
133
|
-
# different data structure for the cache.
|
127
|
+
# just use the offset directly. Otherwise, we build an array where the
|
128
|
+
# index is the byte offset and the value is the character offset.
|
134
129
|
def build_offset_cache(source)
|
135
130
|
if source.bytesize == source.length
|
136
131
|
-> (offset) { offset }
|
137
132
|
else
|
138
|
-
|
139
|
-
|
133
|
+
offset_cache = []
|
134
|
+
offset = 0
|
135
|
+
|
136
|
+
source.each_char do |char|
|
137
|
+
char.bytesize.times { offset_cache << offset }
|
138
|
+
offset += 1
|
140
139
|
end
|
140
|
+
|
141
|
+
offset_cache << offset
|
141
142
|
end
|
142
143
|
end
|
143
144
|
|
@@ -167,6 +168,18 @@ module Prism
|
|
167
168
|
)
|
168
169
|
end
|
169
170
|
|
171
|
+
# Converts the version format handled by Parser to the format handled by Prism.
|
172
|
+
def convert_for_prism(version)
|
173
|
+
case version
|
174
|
+
when 33
|
175
|
+
"3.3.0"
|
176
|
+
when 34
|
177
|
+
"3.4.0"
|
178
|
+
else
|
179
|
+
"latest"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
170
183
|
require_relative "parser/compiler"
|
171
184
|
require_relative "parser/lexer"
|
172
185
|
|