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
@@ -6,7 +6,7 @@ module Prism
|
|
6
6
|
module Translation
|
7
7
|
# This module is the entry-point for converting a prism syntax tree into the
|
8
8
|
# seattlerb/ruby_parser gem's syntax tree.
|
9
|
-
|
9
|
+
class RubyParser
|
10
10
|
# A prism visitor that builds Sexp objects.
|
11
11
|
class Compiler < ::Prism::Compiler
|
12
12
|
# This is the name of the file that we are compiling. We set it on every
|
@@ -192,19 +192,19 @@ module Prism
|
|
192
192
|
|
193
193
|
if node.opening == "("
|
194
194
|
result.line = node.opening_loc.start_line
|
195
|
-
result.
|
195
|
+
result.line_max = node.closing_loc.end_line
|
196
196
|
shadow_loc = false
|
197
197
|
end
|
198
198
|
|
199
199
|
if node.locals.any?
|
200
200
|
shadow = s(node, :shadow).concat(visit_all(node.locals))
|
201
201
|
shadow.line = node.locals.first.location.start_line
|
202
|
-
shadow.
|
202
|
+
shadow.line_max = node.locals.last.location.end_line
|
203
203
|
result << shadow
|
204
204
|
|
205
205
|
if shadow_loc
|
206
206
|
result.line = shadow.line
|
207
|
-
result.
|
207
|
+
result.line_max = shadow.line_max
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
@@ -1274,6 +1274,11 @@ module Prism
|
|
1274
1274
|
s(node, :self)
|
1275
1275
|
end
|
1276
1276
|
|
1277
|
+
# A shareable constant.
|
1278
|
+
def visit_shareable_constant_node(node)
|
1279
|
+
visit(node.write)
|
1280
|
+
end
|
1281
|
+
|
1277
1282
|
# class << self; end
|
1278
1283
|
# ^^^^^^^^^^^^^^^^^^
|
1279
1284
|
def visit_singleton_class_node(node)
|
@@ -1407,7 +1412,7 @@ module Prism
|
|
1407
1412
|
|
1408
1413
|
if node.heredoc?
|
1409
1414
|
result.line = node.content_loc.start_line
|
1410
|
-
result.
|
1415
|
+
result.line_max = node.content_loc.end_line
|
1411
1416
|
end
|
1412
1417
|
|
1413
1418
|
result
|
@@ -1434,7 +1439,7 @@ module Prism
|
|
1434
1439
|
result = Sexp.new(*arguments)
|
1435
1440
|
result.file = file
|
1436
1441
|
result.line = node.location.start_line
|
1437
|
-
result.
|
1442
|
+
result.line_max = node.location.end_line
|
1438
1443
|
result
|
1439
1444
|
end
|
1440
1445
|
|
@@ -1490,31 +1495,43 @@ module Prism
|
|
1490
1495
|
|
1491
1496
|
private_constant :Compiler
|
1492
1497
|
|
1498
|
+
# Parse the given source and translate it into the seattlerb/ruby_parser
|
1499
|
+
# gem's Sexp format.
|
1500
|
+
def parse(source, filepath = "(string)")
|
1501
|
+
translate(Prism.parse(source), filepath)
|
1502
|
+
end
|
1503
|
+
|
1504
|
+
# Parse the given file and translate it into the seattlerb/ruby_parser
|
1505
|
+
# gem's Sexp format.
|
1506
|
+
def parse_file(filepath)
|
1507
|
+
translate(Prism.parse_file(filepath), filepath)
|
1508
|
+
end
|
1509
|
+
|
1493
1510
|
class << self
|
1494
1511
|
# Parse the given source and translate it into the seattlerb/ruby_parser
|
1495
1512
|
# gem's Sexp format.
|
1496
1513
|
def parse(source, filepath = "(string)")
|
1497
|
-
|
1514
|
+
new.parse(source, filepath)
|
1498
1515
|
end
|
1499
1516
|
|
1500
1517
|
# Parse the given file and translate it into the seattlerb/ruby_parser
|
1501
1518
|
# gem's Sexp format.
|
1502
1519
|
def parse_file(filepath)
|
1503
|
-
|
1520
|
+
new.parse_file(filepath)
|
1504
1521
|
end
|
1522
|
+
end
|
1505
1523
|
|
1506
|
-
|
1524
|
+
private
|
1507
1525
|
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
end
|
1515
|
-
|
1516
|
-
result.value.accept(Compiler.new(filepath))
|
1526
|
+
# Translate the given parse result and filepath into the
|
1527
|
+
# seattlerb/ruby_parser gem's Sexp format.
|
1528
|
+
def translate(result, filepath)
|
1529
|
+
if result.failure?
|
1530
|
+
error = result.errors.first
|
1531
|
+
raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}"
|
1517
1532
|
end
|
1533
|
+
|
1534
|
+
result.value.accept(Compiler.new(filepath))
|
1518
1535
|
end
|
1519
1536
|
end
|
1520
1537
|
end
|
data/lib/prism/translation.rb
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
module Prism
|
4
4
|
# This module is responsible for converting the prism syntax tree into other
|
5
5
|
# syntax trees.
|
6
|
-
module Translation
|
6
|
+
module Translation # steep:ignore
|
7
7
|
autoload :Parser, "prism/translation/parser"
|
8
|
+
autoload :Parser33, "prism/translation/parser33"
|
9
|
+
autoload :Parser34, "prism/translation/parser34"
|
8
10
|
autoload :Ripper, "prism/translation/ripper"
|
9
11
|
autoload :RubyParser, "prism/translation/ruby_parser"
|
10
12
|
end
|
data/lib/prism/visitor.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/visitor.rb.erb
|
@@ -14,16 +15,19 @@ module Prism
|
|
14
15
|
# Calls `accept` on the given node if it is not `nil`, which in turn should
|
15
16
|
# call back into this visitor by calling the appropriate `visit_*` method.
|
16
17
|
def visit(node)
|
18
|
+
# @type self: _Visitor
|
17
19
|
node&.accept(self)
|
18
20
|
end
|
19
21
|
|
20
22
|
# Visits each node in `nodes` by calling `accept` on each one.
|
21
23
|
def visit_all(nodes)
|
24
|
+
# @type self: _Visitor
|
22
25
|
nodes.each { |node| node&.accept(self) }
|
23
26
|
end
|
24
27
|
|
25
28
|
# Visits the child nodes of `node` by calling `accept` on each one.
|
26
29
|
def visit_child_nodes(node)
|
30
|
+
# @type self: _Visitor
|
27
31
|
node.compact_child_nodes.each { |node| node.accept(self) }
|
28
32
|
end
|
29
33
|
end
|
@@ -309,6 +313,9 @@ module Prism
|
|
309
313
|
# Visit a InterpolatedXStringNode node
|
310
314
|
alias visit_interpolated_x_string_node visit_child_nodes
|
311
315
|
|
316
|
+
# Visit a ItParametersNode node
|
317
|
+
alias visit_it_parameters_node visit_child_nodes
|
318
|
+
|
312
319
|
# Visit a KeywordHashNode node
|
313
320
|
alias visit_keyword_hash_node visit_child_nodes
|
314
321
|
|
@@ -441,6 +448,9 @@ module Prism
|
|
441
448
|
# Visit a SelfNode node
|
442
449
|
alias visit_self_node visit_child_nodes
|
443
450
|
|
451
|
+
# Visit a ShareableConstantNode node
|
452
|
+
alias visit_shareable_constant_node visit_child_nodes
|
453
|
+
|
444
454
|
# Visit a SingletonClassNode node
|
445
455
|
alias visit_singleton_class_node visit_child_nodes
|
446
456
|
|
data/lib/prism.rb
CHANGED
@@ -44,7 +44,7 @@ module Prism
|
|
44
44
|
#
|
45
45
|
# For supported options, see Prism::parse.
|
46
46
|
def self.lex_compat(source, **options)
|
47
|
-
LexCompat.new(source, **options).result
|
47
|
+
LexCompat.new(source, **options).result # steep:ignore
|
48
48
|
end
|
49
49
|
|
50
50
|
# :call-seq:
|
@@ -54,7 +54,7 @@ module Prism
|
|
54
54
|
# returns the same tokens. Raises SyntaxError if the syntax in source is
|
55
55
|
# invalid.
|
56
56
|
def self.lex_ripper(source)
|
57
|
-
LexRipper.new(source).result
|
57
|
+
LexRipper.new(source).result # steep:ignore
|
58
58
|
end
|
59
59
|
|
60
60
|
# :call-seq:
|
@@ -94,6 +94,12 @@ require_relative "prism/parse_result/newlines"
|
|
94
94
|
# module that uses FFI to call into the library.
|
95
95
|
if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
|
96
96
|
require "prism/prism"
|
97
|
+
|
98
|
+
# The C extension is the default backend on CRuby.
|
99
|
+
Prism::BACKEND = :CEXT
|
97
100
|
else
|
98
101
|
require_relative "prism/ffi"
|
102
|
+
|
103
|
+
# The FFI backend is used on other Ruby implementations.
|
104
|
+
Prism::BACKEND = :FFI
|
99
105
|
end
|
data/prism.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "prism"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.25.0"
|
6
6
|
spec.authors = ["Shopify"]
|
7
7
|
spec.email = ["ruby@shopify.com"]
|
8
8
|
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
spec.files = [
|
17
|
+
"BSDmakefile",
|
17
18
|
"CHANGELOG.md",
|
18
19
|
"CODE_OF_CONDUCT.md",
|
19
20
|
"CONTRIBUTING.md",
|
@@ -34,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
34
35
|
"docs/parser_translation.md",
|
35
36
|
"docs/parsing_rules.md",
|
36
37
|
"docs/releasing.md",
|
37
|
-
"docs/
|
38
|
+
"docs/ripper_translation.md",
|
38
39
|
"docs/ruby_api.md",
|
39
40
|
"docs/ruby_parser_translation.md",
|
40
41
|
"docs/serialization.md",
|
@@ -54,9 +55,11 @@ Gem::Specification.new do |spec|
|
|
54
55
|
"include/prism/parser.h",
|
55
56
|
"include/prism/prettyprint.h",
|
56
57
|
"include/prism/regexp.h",
|
58
|
+
"include/prism/static_literals.h",
|
57
59
|
"include/prism/util/pm_buffer.h",
|
58
60
|
"include/prism/util/pm_char.h",
|
59
61
|
"include/prism/util/pm_constant_pool.h",
|
62
|
+
"include/prism/util/pm_integer.h",
|
60
63
|
"include/prism/util/pm_list.h",
|
61
64
|
"include/prism/util/pm_memchr.h",
|
62
65
|
"include/prism/util/pm_newline_list.h",
|
@@ -84,6 +87,7 @@ Gem::Specification.new do |spec|
|
|
84
87
|
"lib/prism/parse_result/comments.rb",
|
85
88
|
"lib/prism/parse_result/newlines.rb",
|
86
89
|
"lib/prism/pattern.rb",
|
90
|
+
"lib/prism/polyfill/string.rb",
|
87
91
|
"lib/prism/serialize.rb",
|
88
92
|
"lib/prism/translation.rb",
|
89
93
|
"lib/prism/translation/parser.rb",
|
@@ -93,6 +97,8 @@ Gem::Specification.new do |spec|
|
|
93
97
|
"lib/prism/translation/parser/lexer.rb",
|
94
98
|
"lib/prism/translation/parser/rubocop.rb",
|
95
99
|
"lib/prism/translation/ripper.rb",
|
100
|
+
"lib/prism/translation/ripper/sexp.rb",
|
101
|
+
"lib/prism/translation/ripper/shim.rb",
|
96
102
|
"lib/prism/translation/ruby_parser.rb",
|
97
103
|
"lib/prism/visitor.rb",
|
98
104
|
"src/diagnostic.c",
|
@@ -102,10 +108,12 @@ Gem::Specification.new do |spec|
|
|
102
108
|
"src/prettyprint.c",
|
103
109
|
"src/regexp.c",
|
104
110
|
"src/serialize.c",
|
111
|
+
"src/static_literals.c",
|
105
112
|
"src/token_type.c",
|
106
113
|
"src/util/pm_buffer.c",
|
107
114
|
"src/util/pm_char.c",
|
108
115
|
"src/util/pm_constant_pool.c",
|
116
|
+
"src/util/pm_integer.c",
|
109
117
|
"src/util/pm_list.c",
|
110
118
|
"src/util/pm_memchr.c",
|
111
119
|
"src/util/pm_newline_list.c",
|
@@ -118,9 +126,30 @@ Gem::Specification.new do |spec|
|
|
118
126
|
"src/prism.c",
|
119
127
|
"prism.gemspec",
|
120
128
|
"sig/prism.rbs",
|
121
|
-
"sig/
|
129
|
+
"sig/prism/compiler.rbs",
|
130
|
+
"sig/prism/dispatcher.rbs",
|
131
|
+
"sig/prism/dot_visitor.rbs",
|
132
|
+
"sig/prism/dsl.rbs",
|
133
|
+
"sig/prism/mutation_compiler.rbs",
|
134
|
+
"sig/prism/node.rbs",
|
135
|
+
"sig/prism/node_ext.rbs",
|
136
|
+
"sig/prism/pack.rbs",
|
137
|
+
"sig/prism/parse_result.rbs",
|
138
|
+
"sig/prism/pattern.rbs",
|
139
|
+
"sig/prism/serialize.rbs",
|
140
|
+
"sig/prism/visitor.rbs",
|
122
141
|
"rbi/prism.rbi",
|
123
|
-
"rbi/
|
142
|
+
"rbi/prism/compiler.rbi",
|
143
|
+
"rbi/prism/desugar_compiler.rbi",
|
144
|
+
"rbi/prism/mutation_compiler.rbi",
|
145
|
+
"rbi/prism/node_ext.rbi",
|
146
|
+
"rbi/prism/node.rbi",
|
147
|
+
"rbi/prism/parse_result.rbi",
|
148
|
+
"rbi/prism/translation/parser/compiler.rbi",
|
149
|
+
"rbi/prism/translation/ripper.rbi",
|
150
|
+
"rbi/prism/translation/ripper/ripper_compiler.rbi",
|
151
|
+
"rbi/prism/translation/ruby_parser.rbi",
|
152
|
+
"rbi/prism/visitor.rbi"
|
124
153
|
]
|
125
154
|
|
126
155
|
spec.extensions = ["ext/prism/extconf.rb"]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# typed: strict
|
2
|
+
|
3
|
+
class Prism::Compiler
|
4
|
+
Result = type_member
|
5
|
+
|
6
|
+
sig { params(node: T.nilable(Prism::Node)).returns(T.nilable(Result)) }
|
7
|
+
def visit(node); end
|
8
|
+
|
9
|
+
sig { params(nodes: T::Array[T.nilable(Prism::Node)]).returns(T::Array[T.nilable(Result)]) }
|
10
|
+
def visit_all(nodes); end
|
11
|
+
|
12
|
+
sig { params(node: Prism::Node).returns(T::Array[T.nilable(Result)]) }
|
13
|
+
def visit_child_nodes(node); end
|
14
|
+
end
|