prism 0.27.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -1
  3. data/config.yml +39 -27
  4. data/docs/configuration.md +1 -0
  5. data/ext/prism/api_node.c +814 -807
  6. data/ext/prism/extension.c +5 -3
  7. data/ext/prism/extension.h +1 -1
  8. data/include/prism/ast.h +38 -16
  9. data/include/prism/diagnostic.h +12 -5
  10. data/include/prism/options.h +2 -2
  11. data/include/prism/parser.h +10 -0
  12. data/include/prism/static_literals.h +8 -6
  13. data/include/prism/version.h +2 -2
  14. data/lib/prism/dot_visitor.rb +22 -6
  15. data/lib/prism/dsl.rb +8 -8
  16. data/lib/prism/ffi.rb +3 -3
  17. data/lib/prism/inspect_visitor.rb +2156 -0
  18. data/lib/prism/lex_compat.rb +1 -1
  19. data/lib/prism/mutation_compiler.rb +2 -2
  20. data/lib/prism/node.rb +589 -1715
  21. data/lib/prism/node_ext.rb +34 -5
  22. data/lib/prism/parse_result.rb +78 -0
  23. data/lib/prism/pattern.rb +12 -6
  24. data/lib/prism/polyfill/byteindex.rb +13 -0
  25. data/lib/prism/polyfill/unpack1.rb +14 -0
  26. data/lib/prism/reflection.rb +13 -13
  27. data/lib/prism/serialize.rb +21 -14
  28. data/lib/prism/translation/parser/compiler.rb +2 -2
  29. data/lib/prism/translation/parser.rb +6 -6
  30. data/lib/prism/translation/ripper.rb +13 -9
  31. data/lib/prism/translation/ruby_parser.rb +4 -4
  32. data/lib/prism.rb +2 -1
  33. data/prism.gemspec +36 -38
  34. data/rbi/prism/compiler.rbi +3 -5
  35. data/rbi/prism/inspect_visitor.rbi +12 -0
  36. data/rbi/prism/node.rbi +354 -319
  37. data/rbi/prism/parse_result.rbi +23 -0
  38. data/rbi/prism/translation/ripper.rbi +1 -11
  39. data/sig/prism/dsl.rbs +3 -3
  40. data/sig/prism/inspect_visitor.rbs +22 -0
  41. data/sig/prism/node.rbs +64 -47
  42. data/sig/prism/parse_result.rbs +12 -0
  43. data/src/diagnostic.c +38 -24
  44. data/src/node.c +41 -16
  45. data/src/options.c +2 -2
  46. data/src/prettyprint.c +61 -18
  47. data/src/prism.c +607 -185
  48. data/src/serialize.c +5 -2
  49. data/src/static_literals.c +120 -34
  50. data/src/token_type.c +4 -4
  51. metadata +7 -9
  52. data/lib/prism/node_inspector.rb +0 -68
  53. data/lib/prism/polyfill/string.rb +0 -12
  54. data/rbi/prism/desugar_compiler.rbi +0 -5
  55. data/rbi/prism/mutation_compiler.rbi +0 -5
  56. data/rbi/prism/translation/parser/compiler.rbi +0 -13
  57. data/rbi/prism/translation/ripper/ripper_compiler.rbi +0 -5
  58. data/rbi/prism/translation/ruby_parser.rbi +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c27362d3d2d174aeaeab0db8eaf69b47d618f4c2948c9c8a55e96cb927c1ddd6
4
- data.tar.gz: f66f7d1e74c9e35c5ce45e8e34240f90cfc659bc5641048f81f3835ae52fd584
3
+ metadata.gz: 7715842445523172c9593bae81ff5c1a889c6735b59f1c5a879fe63bbeacd724
4
+ data.tar.gz: 755dd34f1e20f374aa2910482a8fac4e709e332d5313a1c80bcc2b3fc9ffbad4
5
5
  SHA512:
6
- metadata.gz: dc64bd0ead37af96b5632498babd6860c9f257c98b0f9dc7aae2c78d6a853b9b95ef6a2f625f61ee1348ef41645e5d4c3f256c30357abca33d7d9387b2a76e2e
7
- data.tar.gz: 34f22069e23dc9adf8c7968e7dcf929b479ef3650c909c4c3ad142e858d89c529bc53b6bd38c40fa7f00340dbafabb86fdf59ab6ba3367b71f64c43201b4e99a
6
+ metadata.gz: 37206e932b34156ad6b1679ea379e8665d987bf9673d37a1e5f74c1abb1a442adbdc0d2045d75624e60507794bd8dd56c5b7bbc8864d7ab9cec1f9a6c1c44b05
7
+ data.tar.gz: 15fc69115a30581010fb65d540f8d2a0c0cd1f76d59754d9b3c1d2f4c2f4354f2f9cbb5087a7989df6b85ff5285248875d6ed40b05d2fca89753f1235948bb0d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,30 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.28.0] - 2024-05-03
10
+
11
+ ### Added
12
+
13
+ - Nested hashes will now warn for duplicated keys, as in: `{ foo: 1, **{ foo: 2 } }`.
14
+ - `Prism::ReturnNode` now has a flag on it to indicate if it is redundant.
15
+ - `Prism::Location#slice_lines` and `Prism::Node#slice_lines` are now provided to slice the source code of a node including the content before the node on the same line that it starts on and the content after the node on the same line that it ends on.
16
+ - Symbols with invalid byte sequences now give errors.
17
+ - You can now pass `"3.3.1"` to the `version:` parameter on all `Prism.*` APIs.
18
+ - `Prism::Source#lines`, `Prism::Location#source_lines`, `Prism::Node#source_lines`, and `Prism::Node#script_lines` are now provided, which will all return the source code of the source as an array of strings.
19
+ - `Prism::ASCIISource` is now provided, which is a subclass of `Prism::Source` but specialized to increase performance when the source is entirely ASCII.
20
+ - Prism now provides errors when parsing Ruby 3.4+ syntax for index expressions with keywords or blocks.
21
+ - Prism now provides an error when `**nil` is used after other keyword parameters.
22
+ - Prism now provides errors when safe navigation is used in call target expressions, e.g., `foo&.bar, = 1`.
23
+ - `Prism::Node#tunnel` is now provided, which returns an array of nodes starting at the current node that contain a given line and column.
24
+
25
+ ### Changed
26
+
27
+ - All translation layers now assume an eval context, which means they will not return errors for invalid jumps like `yield`.
28
+ - `Prism::Node#inspect` now uses a queue instead of recursion to avoid stack overflows.
29
+ - Prism now more closely mirrors CRuby interpolation semantics, which means you could potentially have a static literal string that directly interpolates another static literal string.
30
+ - The shipped RBI sorbet types no longer use generics.
31
+ - `Prism::ConstantPathNode#child` and `Prism::ConstantTargetNode#child` are now deprecated, replaced by two new fields on these nodes: `name` and `name_loc`.
32
+
9
33
  ## [0.27.0] - 2024-04-23
10
34
 
11
35
  ### Added
@@ -476,7 +500,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
476
500
 
477
501
  - 🎉 Initial release! 🎉
478
502
 
479
- [unreleased]: https://github.com/ruby/prism/compare/v0.27.0...HEAD
503
+ [unreleased]: https://github.com/ruby/prism/compare/v0.28.0...HEAD
504
+ [0.28.0]: https://github.com/ruby/prism/compare/v0.27.0...v0.28.0
480
505
  [0.27.0]: https://github.com/ruby/prism/compare/v0.26.0...v0.27.0
481
506
  [0.26.0]: https://github.com/ruby/prism/compare/v0.25.0...v0.26.0
482
507
  [0.25.0]: https://github.com/ruby/prism/compare/v0.24.0...v0.25.0
data/config.yml CHANGED
@@ -123,12 +123,13 @@ errors:
123
123
  - HASH_ROCKET
124
124
  - HASH_TERM
125
125
  - HASH_VALUE
126
+ - HEREDOC_IDENTIFIER
126
127
  - HEREDOC_TERM
127
128
  - INCOMPLETE_QUESTION_MARK
128
129
  - INCOMPLETE_VARIABLE_CLASS
129
- - INCOMPLETE_VARIABLE_CLASS_3_3_0
130
+ - INCOMPLETE_VARIABLE_CLASS_3_3
130
131
  - INCOMPLETE_VARIABLE_INSTANCE
131
- - INCOMPLETE_VARIABLE_INSTANCE_3_3_0
132
+ - INCOMPLETE_VARIABLE_INSTANCE_3_3
132
133
  - INSTANCE_VARIABLE_BARE
133
134
  - INVALID_BLOCK_EXIT
134
135
  - INVALID_CHARACTER
@@ -143,14 +144,16 @@ errors:
143
144
  - INVALID_NUMBER_DECIMAL
144
145
  - INVALID_NUMBER_HEXADECIMAL
145
146
  - INVALID_NUMBER_OCTAL
146
- - INVALID_NUMBER_UNDERSCORE
147
+ - INVALID_NUMBER_UNDERSCORE_INNER
148
+ - INVALID_NUMBER_UNDERSCORE_TRAILING
147
149
  - INVALID_PERCENT
148
150
  - INVALID_PRINTABLE_CHARACTER
149
151
  - INVALID_RETRY_AFTER_ELSE
150
152
  - INVALID_RETRY_AFTER_ENSURE
151
153
  - INVALID_RETRY_WITHOUT_RESCUE
154
+ - INVALID_SYMBOL
152
155
  - INVALID_VARIABLE_GLOBAL
153
- - INVALID_VARIABLE_GLOBAL_3_3_0
156
+ - INVALID_VARIABLE_GLOBAL_3_3
154
157
  - INVALID_YIELD
155
158
  - IT_NOT_ALLOWED_NUMBERED
156
159
  - IT_NOT_ALLOWED_ORDINARY
@@ -194,6 +197,7 @@ errors:
194
197
  - PARAMETER_STAR
195
198
  - PARAMETER_UNEXPECTED_FWD
196
199
  - PARAMETER_WILD_LOOSE_COMMA
200
+ - PARAMETER_UNEXPECTED_NO_KW
197
201
  - PATTERN_CAPTURE_DUPLICATE
198
202
  - PATTERN_EXPRESSION_AFTER_BRACKET
199
203
  - PATTERN_EXPRESSION_AFTER_COMMA
@@ -247,6 +251,9 @@ errors:
247
251
  - UNARY_RECEIVER
248
252
  - UNDEF_ARGUMENT
249
253
  - UNEXPECTED_BLOCK_ARGUMENT
254
+ - UNEXPECTED_INDEX_BLOCK
255
+ - UNEXPECTED_INDEX_KEYWORDS
256
+ - UNEXPECTED_SAFE_NAVIGATION
250
257
  - UNEXPECTED_TOKEN_CLOSE_CONTEXT
251
258
  - UNEXPECTED_TOKEN_IGNORE
252
259
  - UNTIL_TERM
@@ -266,7 +273,7 @@ warnings:
266
273
  - COMPARISON_AFTER_COMPARISON
267
274
  - DOT_DOT_DOT_EOL
268
275
  - EQUAL_IN_CONDITIONAL
269
- - EQUAL_IN_CONDITIONAL_3_3_0
276
+ - EQUAL_IN_CONDITIONAL_3_3
270
277
  - END_IN_METHOD
271
278
  - DUPLICATED_HASH_KEY
272
279
  - DUPLICATED_WHEN_CLAUSE
@@ -617,6 +624,8 @@ tokens:
617
624
  flags:
618
625
  - name: ArgumentsNodeFlags
619
626
  values:
627
+ - name: CONTAINS_KEYWORDS
628
+ comment: "if arguments contain keywords"
620
629
  - name: CONTAINS_KEYWORD_SPLAT
621
630
  comment: "if arguments contain keyword splat"
622
631
  comment: Flags for arguments nodes.
@@ -706,6 +715,11 @@ flags:
706
715
  - name: FORCED_US_ASCII_ENCODING
707
716
  comment: "internal bytes forced the encoding to US-ASCII"
708
717
  comment: Flags for regular expression and match last line nodes.
718
+ - name: ReturnNodeFlags
719
+ values:
720
+ - name: REDUNDANT
721
+ comment: "a return statement that is redundant because it is the last statement in a method"
722
+ comment: Flags for return nodes.
709
723
  - name: ShareableConstantNodeFlags
710
724
  values:
711
725
  - name: LITERAL
@@ -1512,23 +1526,9 @@ nodes:
1512
1526
 
1513
1527
  a.b::C
1514
1528
  ^^^
1515
- - name: child
1516
- type: node
1517
- kind:
1518
- - ConstantReadNode
1519
- - MissingNode
1520
- comment: |
1521
- The right-hand node of the path. Always a `ConstantReadNode` in a
1522
- valid Ruby syntax tree.
1523
-
1524
- ::Foo
1525
- ^^^
1526
-
1527
- self::Test
1528
- ^^^^
1529
-
1530
- a.b::C
1531
- ^
1529
+ - name: name
1530
+ type: constant?
1531
+ comment: The name of the constant being accessed. This could be `nil` in the event of a syntax error.
1532
1532
  - name: delimiter_loc
1533
1533
  type: location
1534
1534
  comment: |
@@ -1539,6 +1539,16 @@ nodes:
1539
1539
 
1540
1540
  One::Two
1541
1541
  ^^
1542
+ - name: name_loc
1543
+ type: location
1544
+ comment: |
1545
+ The location of the name of the constant.
1546
+
1547
+ ::Foo
1548
+ ^^^
1549
+
1550
+ One::Two
1551
+ ^^^
1542
1552
  comment: |
1543
1553
  Represents accessing a constant through a path of `::` operators.
1544
1554
 
@@ -1578,13 +1588,12 @@ nodes:
1578
1588
  fields:
1579
1589
  - name: parent
1580
1590
  type: node?
1581
- - name: child
1582
- type: node
1583
- kind:
1584
- - ConstantReadNode
1585
- - MissingNode
1591
+ - name: name
1592
+ type: constant?
1586
1593
  - name: delimiter_loc
1587
1594
  type: location
1595
+ - name: name_loc
1596
+ type: location
1588
1597
  comment: |
1589
1598
  Represents writing to a constant path in a context that doesn't have an explicit value.
1590
1599
 
@@ -3330,6 +3339,9 @@ nodes:
3330
3339
  ^^^^^
3331
3340
  - name: ReturnNode
3332
3341
  fields:
3342
+ - name: flags
3343
+ type: flags
3344
+ kind: ReturnNodeFlags
3333
3345
  - name: keyword_loc
3334
3346
  type: location
3335
3347
  - name: arguments
@@ -14,6 +14,7 @@ A lot of code in prism's repository is templated from a single configuration fil
14
14
  * `lib/prism/dispatcher.rb` - for defining the dispatch visitors for the nodes in Ruby
15
15
  * `lib/prism/dot_visitor.rb` - for defining the dot visitor for the nodes in Ruby
16
16
  * `lib/prism/dsl.rb` - for defining the DSL for the nodes in Ruby
17
+ * `lib/prism/inspect_visitor.rb` - for defining the `#inspect` methods on nodes in Ruby
17
18
  * `lib/prism/mutation_compiler.rb` - for defining the mutation compiler for the nodes in Ruby
18
19
  * `lib/prism/node.rb` - for defining the nodes in Ruby
19
20
  * `lib/prism/reflection.rb` - for defining the reflection API in Ruby