prism 0.24.0 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +50 -1
  4. data/Makefile +5 -2
  5. data/README.md +45 -6
  6. data/config.yml +499 -4
  7. data/docs/build_system.md +31 -0
  8. data/docs/configuration.md +2 -0
  9. data/docs/cruby_compilation.md +1 -1
  10. data/docs/parser_translation.md +14 -9
  11. data/docs/releasing.md +2 -2
  12. data/docs/ripper_translation.md +50 -0
  13. data/docs/ruby_api.md +1 -0
  14. data/docs/serialization.md +26 -5
  15. data/ext/prism/api_node.c +911 -815
  16. data/ext/prism/api_pack.c +9 -0
  17. data/ext/prism/extconf.rb +27 -11
  18. data/ext/prism/extension.c +313 -66
  19. data/ext/prism/extension.h +5 -4
  20. data/include/prism/ast.h +213 -64
  21. data/include/prism/defines.h +106 -2
  22. data/include/prism/diagnostic.h +134 -71
  23. data/include/prism/encoding.h +22 -4
  24. data/include/prism/node.h +93 -0
  25. data/include/prism/options.h +82 -7
  26. data/include/prism/pack.h +11 -0
  27. data/include/prism/parser.h +198 -53
  28. data/include/prism/prettyprint.h +8 -0
  29. data/include/prism/static_literals.h +118 -0
  30. data/include/prism/util/pm_buffer.h +65 -2
  31. data/include/prism/util/pm_constant_pool.h +18 -1
  32. data/include/prism/util/pm_integer.h +119 -0
  33. data/include/prism/util/pm_list.h +1 -1
  34. data/include/prism/util/pm_newline_list.h +8 -0
  35. data/include/prism/util/pm_string.h +26 -2
  36. data/include/prism/version.h +2 -2
  37. data/include/prism.h +59 -1
  38. data/lib/prism/compiler.rb +8 -1
  39. data/lib/prism/debug.rb +46 -3
  40. data/lib/prism/desugar_compiler.rb +1 -1
  41. data/lib/prism/dispatcher.rb +29 -0
  42. data/lib/prism/dot_visitor.rb +87 -16
  43. data/lib/prism/dsl.rb +24 -12
  44. data/lib/prism/ffi.rb +67 -12
  45. data/lib/prism/lex_compat.rb +17 -15
  46. data/lib/prism/mutation_compiler.rb +11 -0
  47. data/lib/prism/node.rb +2096 -2499
  48. data/lib/prism/node_ext.rb +77 -29
  49. data/lib/prism/pack.rb +4 -0
  50. data/lib/prism/parse_result/comments.rb +34 -17
  51. data/lib/prism/parse_result/newlines.rb +3 -1
  52. data/lib/prism/parse_result.rb +78 -32
  53. data/lib/prism/pattern.rb +16 -4
  54. data/lib/prism/polyfill/string.rb +12 -0
  55. data/lib/prism/serialize.rb +439 -102
  56. data/lib/prism/translation/parser/compiler.rb +152 -50
  57. data/lib/prism/translation/parser/lexer.rb +103 -22
  58. data/lib/prism/translation/parser/rubocop.rb +41 -13
  59. data/lib/prism/translation/parser.rb +119 -7
  60. data/lib/prism/translation/parser33.rb +1 -1
  61. data/lib/prism/translation/parser34.rb +1 -1
  62. data/lib/prism/translation/ripper/sexp.rb +125 -0
  63. data/lib/prism/translation/ripper/shim.rb +5 -0
  64. data/lib/prism/translation/ripper.rb +3212 -462
  65. data/lib/prism/translation/ruby_parser.rb +35 -18
  66. data/lib/prism/translation.rb +3 -1
  67. data/lib/prism/visitor.rb +10 -0
  68. data/lib/prism.rb +8 -2
  69. data/prism.gemspec +33 -4
  70. data/rbi/prism/compiler.rbi +14 -0
  71. data/rbi/prism/desugar_compiler.rbi +5 -0
  72. data/rbi/prism/mutation_compiler.rbi +5 -0
  73. data/rbi/prism/node.rbi +8221 -0
  74. data/rbi/prism/node_ext.rbi +102 -0
  75. data/rbi/prism/parse_result.rbi +304 -0
  76. data/rbi/prism/translation/parser/compiler.rbi +13 -0
  77. data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
  78. data/rbi/prism/translation/ripper.rbi +25 -0
  79. data/rbi/prism/translation/ruby_parser.rbi +11 -0
  80. data/rbi/prism/visitor.rbi +470 -0
  81. data/rbi/prism.rbi +39 -7749
  82. data/sig/prism/compiler.rbs +9 -0
  83. data/sig/prism/dispatcher.rbs +16 -0
  84. data/sig/prism/dot_visitor.rbs +6 -0
  85. data/sig/prism/dsl.rbs +462 -0
  86. data/sig/prism/mutation_compiler.rbs +158 -0
  87. data/sig/prism/node.rbs +3529 -0
  88. data/sig/prism/node_ext.rbs +78 -0
  89. data/sig/prism/pack.rbs +43 -0
  90. data/sig/prism/parse_result.rbs +127 -0
  91. data/sig/prism/pattern.rbs +13 -0
  92. data/sig/prism/serialize.rbs +7 -0
  93. data/sig/prism/visitor.rbs +168 -0
  94. data/sig/prism.rbs +188 -4767
  95. data/src/diagnostic.c +575 -230
  96. data/src/encoding.c +211 -108
  97. data/src/node.c +7526 -447
  98. data/src/options.c +36 -12
  99. data/src/pack.c +33 -17
  100. data/src/prettyprint.c +1294 -1385
  101. data/src/prism.c +3628 -1099
  102. data/src/regexp.c +17 -2
  103. data/src/serialize.c +47 -28
  104. data/src/static_literals.c +552 -0
  105. data/src/token_type.c +1 -0
  106. data/src/util/pm_buffer.c +147 -20
  107. data/src/util/pm_char.c +4 -4
  108. data/src/util/pm_constant_pool.c +35 -11
  109. data/src/util/pm_integer.c +629 -0
  110. data/src/util/pm_list.c +1 -1
  111. data/src/util/pm_newline_list.c +14 -5
  112. data/src/util/pm_string.c +134 -5
  113. data/src/util/pm_string_list.c +2 -2
  114. metadata +35 -6
  115. data/docs/ripper.md +0 -36
  116. data/rbi/prism_static.rbi +0 -207
  117. data/sig/prism_static.rbs +0 -201
@@ -0,0 +1,102 @@
1
+ # typed: strict
2
+
3
+ class Prism::InterpolatedMatchLastLineNode < Prism::Node
4
+ sig { returns(Integer) }
5
+ def options; end
6
+ end
7
+
8
+ class Prism::InterpolatedRegularExpressionNode < Prism::Node
9
+ sig { returns(Integer) }
10
+ def options; end
11
+ end
12
+
13
+ class Prism::MatchLastLineNode < Prism::Node
14
+ sig { returns(Integer) }
15
+ def options; end
16
+ end
17
+
18
+ class Prism::RegularExpressionNode < Prism::Node
19
+ sig { returns(Integer) }
20
+ def options; end
21
+ end
22
+
23
+ class Prism::InterpolatedStringNode < Prism::Node
24
+ sig { returns(T::Boolean) }
25
+ def heredoc?; end
26
+ end
27
+
28
+ class Prism::InterpolatedXStringNode < Prism::Node
29
+ sig { returns(T::Boolean) }
30
+ def heredoc?; end
31
+ end
32
+
33
+ class Prism::StringNode < Prism::Node
34
+ sig { returns(T::Boolean) }
35
+ def heredoc?; end
36
+
37
+ sig { returns(Prism::InterpolatedStringNode) }
38
+ def to_interpolated; end
39
+ end
40
+
41
+ class Prism::XStringNode < Prism::Node
42
+ sig { returns(T::Boolean) }
43
+ def heredoc?; end
44
+
45
+ sig { returns(Prism::InterpolatedXStringNode) }
46
+ def to_interpolated; end
47
+ end
48
+
49
+ class Prism::ImaginaryNode < Prism::Node
50
+ sig { returns(Complex) }
51
+ def value; end
52
+ end
53
+
54
+ class Prism::RationalNode < Prism::Node
55
+ sig { returns(Rational) }
56
+ def value; end
57
+ end
58
+
59
+ class Prism::ConstantReadNode < Prism::Node
60
+ sig { returns(T::Array[Symbol]) }
61
+ def full_name_parts; end
62
+
63
+ sig { returns(String) }
64
+ def full_name; end
65
+ end
66
+
67
+ class Prism::ConstantWriteNode < Prism::Node
68
+ sig { returns(T::Array[Symbol]) }
69
+ def full_name_parts; end
70
+
71
+ sig { returns(String) }
72
+ def full_name; end
73
+ end
74
+
75
+ class Prism::ConstantPathNode < Prism::Node
76
+ sig { returns(T::Array[Symbol]) }
77
+ def full_name_parts; end
78
+
79
+ sig { returns(String) }
80
+ def full_name; end
81
+ end
82
+
83
+ class Prism::ConstantPathTargetNode < Prism::Node
84
+ sig { returns(T::Array[Symbol]) }
85
+ def full_name_parts; end
86
+
87
+ sig { returns(String) }
88
+ def full_name; end
89
+ end
90
+
91
+ class Prism::ConstantTargetNode < Prism::Node
92
+ sig { returns(T::Array[Symbol]) }
93
+ def full_name_parts; end
94
+
95
+ sig { returns(String) }
96
+ def full_name; end
97
+ end
98
+
99
+ class Prism::ParametersNode < Prism::Node
100
+ sig { returns(T::Array[T.any([Symbol, Symbol], [Symbol])]) }
101
+ def signature; end
102
+ end
@@ -0,0 +1,304 @@
1
+ # typed: strict
2
+
3
+ class Prism::Source
4
+ sig { returns(String) }
5
+ attr_reader :source
6
+
7
+ sig { returns(Integer) }
8
+ attr_reader :start_line
9
+
10
+ sig { returns(T::Array[Integer]) }
11
+ attr_reader :offsets
12
+
13
+ sig { params(source: String, start_line: Integer, offsets: T::Array[Integer]).void }
14
+ def initialize(source, start_line = 1, offsets = []); end
15
+
16
+ sig { returns(Encoding) }
17
+ def encoding; end
18
+
19
+ sig { params(byte_offset: Integer, length: Integer).returns(String) }
20
+ def slice(byte_offset, length); end
21
+
22
+ sig { params(byte_offset: Integer).returns(Integer) }
23
+ def line(byte_offset); end
24
+
25
+ sig { params(byte_offset: Integer).returns(Integer) }
26
+ def line_start(byte_offset); end
27
+
28
+ sig { params(byte_offset: Integer).returns(Integer) }
29
+ def column(byte_offset); end
30
+
31
+ sig { params(byte_offset: Integer).returns(Integer) }
32
+ def character_offset(byte_offset); end
33
+
34
+ sig { params(byte_offset: Integer).returns(Integer) }
35
+ def character_column(byte_offset); end
36
+
37
+ sig { params(byte_offset: Integer, encoding: Encoding).returns(Integer) }
38
+ def code_units_offset(byte_offset, encoding); end
39
+
40
+ sig { params(byte_offset: Integer, encoding: Encoding).returns(Integer) }
41
+ def code_units_column(byte_offset, encoding); end
42
+ end
43
+
44
+ class Prism::Location
45
+ sig { returns(Prism::Source) }
46
+ attr_reader :source
47
+
48
+ sig { returns(Integer) }
49
+ attr_reader :start_offset
50
+
51
+ sig { returns(Integer) }
52
+ attr_reader :length
53
+
54
+ sig { params(source: Prism::Source, start_offset: Integer, length: Integer).void }
55
+ def initialize(source, start_offset, length); end
56
+
57
+ sig { returns(T::Array[Prism::Comment]) }
58
+ def leading_comments; end
59
+
60
+ sig { params(comment: Prism::Comment).void }
61
+ def leading_comment(comment); end
62
+
63
+ sig { returns(T::Array[Prism::Comment]) }
64
+ def trailing_comments; end
65
+
66
+ sig { params(comment: Prism::Comment).void }
67
+ def trailing_comment(comment); end
68
+
69
+ sig { returns(T::Array[Prism::Comment]) }
70
+ def comments; end
71
+
72
+ sig { params(source: Prism::Source, start_offset: Integer, length: Integer).returns(Prism::Location) }
73
+ def copy(source: self.source, start_offset: self.start_offset, length: self.length); end
74
+
75
+ sig { returns(String) }
76
+ def inspect; end
77
+
78
+ sig { returns(String) }
79
+ def slice; end
80
+
81
+ sig { returns(Integer) }
82
+ def start_character_offset; end
83
+
84
+ sig { params(encoding: Encoding).returns(Integer) }
85
+ def start_code_units_offset(encoding = Encoding::UTF_16LE); end
86
+
87
+ sig { returns(Integer) }
88
+ def end_offset; end
89
+
90
+ sig { returns(Integer) }
91
+ def end_character_offset; end
92
+
93
+ sig { params(encoding: Encoding).returns(Integer) }
94
+ def end_code_units_offset(encoding = Encoding::UTF_16LE); end
95
+
96
+ sig { returns(Integer) }
97
+ def start_line; end
98
+
99
+ sig { returns(String) }
100
+ def start_line_slice; end
101
+
102
+ sig { returns(Integer) }
103
+ def end_line; end
104
+
105
+ sig { returns(Integer) }
106
+ def start_column; end
107
+
108
+ sig { returns(Integer) }
109
+ def start_character_column; end
110
+
111
+ sig { params(encoding: Encoding).returns(Integer) }
112
+ def start_code_units_column(encoding = Encoding::UTF_16LE); end
113
+
114
+ sig { returns(Integer) }
115
+ def end_column; end
116
+
117
+ sig { returns(Integer) }
118
+ def end_character_column; end
119
+
120
+ sig { params(encoding: Encoding).returns(Integer) }
121
+ def end_code_units_column(encoding = Encoding::UTF_16LE); end
122
+
123
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
124
+ def deconstruct_keys(keys); end
125
+
126
+ sig { params(q: T.untyped).void }
127
+ def pretty_print(q); end
128
+
129
+ sig { params(other: T.untyped).returns(T::Boolean) }
130
+ def ==(other); end
131
+
132
+ sig { params(other: Prism::Location).returns(Prism::Location) }
133
+ def join(other); end
134
+ end
135
+
136
+ class Prism::Comment
137
+ abstract!
138
+
139
+ sig { returns(Prism::Location) }
140
+ attr_reader :location
141
+
142
+ sig { params(location: Prism::Location).void }
143
+ def initialize(location); end
144
+
145
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
146
+ def deconstruct_keys(keys); end
147
+
148
+ sig { returns(String) }
149
+ def slice; end
150
+
151
+ sig { abstract.returns(T::Boolean) }
152
+ def trailing?; end
153
+ end
154
+
155
+ class Prism::InlineComment < Prism::Comment
156
+ sig { override.returns(T::Boolean) }
157
+ def trailing?; end
158
+
159
+ sig { returns(String) }
160
+ def inspect; end
161
+ end
162
+
163
+ class Prism::EmbDocComment < Prism::Comment
164
+ sig { override.returns(T::Boolean) }
165
+ def trailing?; end
166
+
167
+ sig { returns(String) }
168
+ def inspect; end
169
+ end
170
+
171
+ class Prism::MagicComment
172
+ sig { returns(Prism::Location) }
173
+ attr_reader :key_loc
174
+
175
+ sig { returns(Prism::Location) }
176
+ attr_reader :value_loc
177
+
178
+ sig { params(key_loc: Prism::Location, value_loc: Prism::Location).void }
179
+ def initialize(key_loc, value_loc); end
180
+
181
+ sig { returns(String) }
182
+ def key; end
183
+
184
+ sig { returns(String) }
185
+ def value; end
186
+
187
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
188
+ def deconstruct_keys(keys); end
189
+
190
+ sig { returns(String) }
191
+ def inspect; end
192
+ end
193
+
194
+ class Prism::ParseError
195
+ sig { returns(Symbol) }
196
+ attr_reader :type
197
+
198
+ sig { returns(String) }
199
+ attr_reader :message
200
+
201
+ sig { returns(Prism::Location) }
202
+ attr_reader :location
203
+
204
+ sig { returns(Symbol) }
205
+ attr_reader :level
206
+
207
+ sig { params(type: Symbol, message: String, location: Prism::Location, level: Symbol).void }
208
+ def initialize(type, message, location, level); end
209
+
210
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
211
+ def deconstruct_keys(keys); end
212
+
213
+ sig { returns(String) }
214
+ def inspect; end
215
+ end
216
+
217
+ class Prism::ParseWarning
218
+ sig { returns(Symbol) }
219
+ attr_reader :type
220
+
221
+ sig { returns(String) }
222
+ attr_reader :message
223
+
224
+ sig { returns(Prism::Location) }
225
+ attr_reader :location
226
+
227
+ sig { returns(Symbol) }
228
+ attr_reader :level
229
+
230
+ sig { params(type: Symbol, message: String, location: Prism::Location, level: Symbol).void }
231
+ def initialize(type, message, location, level); end
232
+
233
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
234
+ def deconstruct_keys(keys); end
235
+
236
+ sig { returns(String) }
237
+ def inspect; end
238
+ end
239
+
240
+ class Prism::ParseResult
241
+ Value = type_member
242
+
243
+ sig { returns(Value) }
244
+ attr_reader :value
245
+
246
+ sig { returns(T::Array[Prism::Comment]) }
247
+ attr_reader :comments
248
+
249
+ sig { returns(T::Array[Prism::MagicComment]) }
250
+ attr_reader :magic_comments
251
+
252
+ sig { returns(T.nilable(Prism::Location)) }
253
+ attr_reader :data_loc
254
+
255
+ sig { returns(T::Array[Prism::ParseError]) }
256
+ attr_reader :errors
257
+
258
+ sig { returns(T::Array[Prism::ParseWarning]) }
259
+ attr_reader :warnings
260
+
261
+ sig { returns(Prism::Source) }
262
+ attr_reader :source
263
+
264
+ sig { params(value: Value, comments: T::Array[Prism::Comment], magic_comments: T::Array[Prism::MagicComment], data_loc: T.nilable(Prism::Location), errors: T::Array[Prism::ParseError], warnings: T::Array[Prism::ParseWarning], source: Prism::Source).void }
265
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source); end
266
+
267
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
268
+ def deconstruct_keys(keys); end
269
+
270
+ sig { returns(Encoding) }
271
+ def encoding; end
272
+
273
+ sig { returns(T::Boolean) }
274
+ def success?; end
275
+
276
+ sig { returns(T::Boolean) }
277
+ def failure?; end
278
+ end
279
+
280
+ class Prism::Token
281
+ sig { returns(Prism::Source) }
282
+ attr_reader :source
283
+
284
+ sig { returns(Symbol) }
285
+ attr_reader :type
286
+
287
+ sig { returns(String) }
288
+ attr_reader :value
289
+
290
+ sig { params(source: Prism::Source, type: Symbol, value: String, location: T.any(Integer, Prism::Location)).void }
291
+ def initialize(source, type, value, location); end
292
+
293
+ sig { params(keys: T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, T.untyped]) }
294
+ def deconstruct_keys(keys); end
295
+
296
+ sig { returns(Prism::Location) }
297
+ def location; end
298
+
299
+ sig { params(q: T.untyped).void }
300
+ def pretty_print(q); end
301
+
302
+ sig { params(other: T.untyped).returns(T::Boolean) }
303
+ def ==(other); end
304
+ end
@@ -0,0 +1,13 @@
1
+ # typed: strict
2
+
3
+ # We keep these shims in here because our client libraries might not have
4
+ # ast/parser in their bundle.
5
+ module AST; end
6
+ class AST::Node; end
7
+ module Parser; end
8
+ module Parser::AST; end
9
+ class Parser::AST::Node < AST::Node; end
10
+
11
+ class Prism::Translation::Parser::Compiler < Prism::Compiler
12
+ Result = type_member { { fixed: Parser::AST::Node } }
13
+ end
@@ -0,0 +1,5 @@
1
+ # typed: strict
2
+
3
+ class Prism::Translation::RipperCompiler < Prism::Compiler
4
+ Result = type_member
5
+ end
@@ -0,0 +1,25 @@
1
+ # typed: strict
2
+
3
+ class Prism::Translation::Ripper < Prism::Compiler
4
+ Result = type_member
5
+
6
+ sig { returns(T::Boolean) }
7
+ def error?; end
8
+
9
+ sig { returns(T.nilable(Result)) }
10
+ def parse; end
11
+
12
+ sig { params(source: String, filename: String, lineno: Integer, raise_errors: T.untyped).returns(T.untyped) }
13
+ def self.sexp_raw(source, filename = "-", lineno = 1, raise_errors: false); end
14
+
15
+ sig { params(source: String, filename: String, lineno: Integer, raise_errors: T.untyped).returns(T.untyped) }
16
+ def self.sexp(source, filename = "-", lineno = 1, raise_errors: false); end
17
+ end
18
+
19
+ class Prism::Translation::Ripper::SexpBuilder < Prism::Translation::Ripper
20
+ Result = type_member { { fixed: T::Array[T.untyped] } }
21
+ end
22
+
23
+ class Prism::Translation::Ripper::SexpBuilderPP < Prism::Translation::Ripper::SexpBuilder
24
+ Result = type_member { { fixed: T::Array[T.untyped] } }
25
+ end
@@ -0,0 +1,11 @@
1
+ # typed: strict
2
+
3
+ # We keep this shim in here because our client libraries might not have
4
+ # ruby_parser in their bundle.
5
+ class Sexp < ::Array
6
+ Elem = type_member { { fixed: T.untyped }}
7
+ end
8
+
9
+ class Prism::Translation::RubyParser::Compiler < Prism::Compiler
10
+ Result = type_member { { fixed: Sexp } }
11
+ end