prism 0.28.0 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -1
  3. data/CONTRIBUTING.md +0 -4
  4. data/README.md +1 -0
  5. data/config.yml +95 -26
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/ripper_translation.md +22 -0
  8. data/ext/prism/api_node.c +70 -52
  9. data/ext/prism/extconf.rb +27 -23
  10. data/ext/prism/extension.c +107 -372
  11. data/ext/prism/extension.h +1 -1
  12. data/include/prism/ast.h +170 -102
  13. data/include/prism/diagnostic.h +18 -3
  14. data/include/prism/node.h +0 -21
  15. data/include/prism/parser.h +23 -25
  16. data/include/prism/regexp.h +17 -8
  17. data/include/prism/static_literals.h +3 -2
  18. data/include/prism/util/pm_char.h +1 -2
  19. data/include/prism/util/pm_constant_pool.h +0 -8
  20. data/include/prism/util/pm_integer.h +16 -9
  21. data/include/prism/util/pm_string.h +0 -8
  22. data/include/prism/version.h +2 -2
  23. data/include/prism.h +0 -11
  24. data/lib/prism/compiler.rb +3 -0
  25. data/lib/prism/desugar_compiler.rb +4 -4
  26. data/lib/prism/dispatcher.rb +14 -0
  27. data/lib/prism/dot_visitor.rb +54 -35
  28. data/lib/prism/dsl.rb +23 -18
  29. data/lib/prism/ffi.rb +25 -4
  30. data/lib/prism/inspect_visitor.rb +26 -24
  31. data/lib/prism/mutation_compiler.rb +6 -1
  32. data/lib/prism/node.rb +314 -389
  33. data/lib/prism/node_ext.rb +175 -17
  34. data/lib/prism/parse_result/comments.rb +1 -8
  35. data/lib/prism/parse_result/newlines.rb +102 -12
  36. data/lib/prism/parse_result.rb +17 -0
  37. data/lib/prism/reflection.rb +11 -9
  38. data/lib/prism/serialize.rb +91 -68
  39. data/lib/prism/translation/parser/compiler.rb +288 -138
  40. data/lib/prism/translation/parser.rb +7 -2
  41. data/lib/prism/translation/ripper.rb +24 -22
  42. data/lib/prism/translation/ruby_parser.rb +32 -14
  43. data/lib/prism/visitor.rb +3 -0
  44. data/lib/prism.rb +0 -4
  45. data/prism.gemspec +2 -4
  46. data/rbi/prism/node.rbi +114 -57
  47. data/rbi/prism/node_ext.rbi +5 -0
  48. data/rbi/prism/parse_result.rbi +1 -1
  49. data/rbi/prism/visitor.rbi +3 -0
  50. data/rbi/prism.rbi +6 -0
  51. data/sig/prism/dsl.rbs +13 -10
  52. data/sig/prism/lex_compat.rbs +10 -0
  53. data/sig/prism/mutation_compiler.rbs +1 -0
  54. data/sig/prism/node.rbs +72 -48
  55. data/sig/prism/node_ext.rbs +4 -0
  56. data/sig/prism/visitor.rbs +1 -0
  57. data/sig/prism.rbs +21 -0
  58. data/src/diagnostic.c +56 -27
  59. data/src/node.c +432 -1690
  60. data/src/prettyprint.c +97 -54
  61. data/src/prism.c +1286 -1196
  62. data/src/regexp.c +133 -68
  63. data/src/serialize.c +22 -17
  64. data/src/static_literals.c +63 -84
  65. data/src/token_type.c +4 -4
  66. data/src/util/pm_constant_pool.c +0 -8
  67. data/src/util/pm_integer.c +39 -11
  68. data/src/util/pm_string.c +0 -12
  69. data/src/util/pm_strpbrk.c +32 -6
  70. metadata +3 -5
  71. data/include/prism/util/pm_string_list.h +0 -44
  72. data/lib/prism/debug.rb +0 -249
  73. data/src/util/pm_string_list.c +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7715842445523172c9593bae81ff5c1a889c6735b59f1c5a879fe63bbeacd724
4
- data.tar.gz: 755dd34f1e20f374aa2910482a8fac4e709e332d5313a1c80bcc2b3fc9ffbad4
3
+ metadata.gz: 46cabe6b76e675b905cb9b2941faf00d35c0c5043e480c094952a89404e87587
4
+ data.tar.gz: 50a764fb701657e5936b764a7438f49ab074f45d5bee3e435bf70c9b891067be
5
5
  SHA512:
6
- metadata.gz: 37206e932b34156ad6b1679ea379e8665d987bf9673d37a1e5f74c1abb1a442adbdc0d2045d75624e60507794bd8dd56c5b7bbc8864d7ab9cec1f9a6c1c44b05
7
- data.tar.gz: 15fc69115a30581010fb65d540f8d2a0c0cd1f76d59754d9b3c1d2f4c2f4354f2f9cbb5087a7989df6b85ff5285248875d6ed40b05d2fca89753f1235948bb0d
6
+ metadata.gz: 58535a5049cf8d6b8ceb97721135f58ca2fa4e7311cce8c336b6d4d5674de38861a07728651859ffe926bf84db8c14454b543d5d26732174de4c67a2be7cb46b
7
+ data.tar.gz: 16ae75556351bd4c96a54dbd930e466c40695419c29ba9cf5b048dc1173fc397094974bea313258e7615a27f67c9b55b00d72dcee33ddacc1613169005b0e184
data/CHANGELOG.md CHANGED
@@ -6,6 +6,44 @@ 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.30.0] - 2024-06-07
10
+
11
+ ### Added
12
+
13
+ - More correctly raise mixed encoding errors.
14
+ - Implement ambiguous binary operator warning.
15
+ - Fix up regexp escapes with control and meta characters.
16
+ - Fix up support for the `it` implicit local variable.
17
+ - Heredoc identifiers now properly disallow CLRF.
18
+ - Errors added for void value expressions in begin clauses.
19
+ - Many updates to more closely match the `parser` gem in parser translation.
20
+ - Many errors added for invalid regular expressions.
21
+
22
+ ### Changed
23
+
24
+ - Handle parser translation missing the `parser` gem.
25
+ - Handle ruby_parser translation missing the `ruby_parser` gem.
26
+ - Various error messages have been updated to more closely match CRuby.
27
+ - `RationalNode` now has a `numerator` and `denominator` field instead of a `numeric` field. For the Ruby API we provide a `RationalNode#numeric` method for backwards-compatibility.
28
+
29
+ ## [0.29.0] - 2024-05-10
30
+
31
+ ### Added
32
+
33
+ - Added `Prism::CallNode#full_message_loc`, which gives the location including the `=` if there is one.
34
+ - A warning for when `# shareable_constant_value` is not used on its own line.
35
+ - An error for invalid implicit local variable writes.
36
+ - Implicit hash patterns in array patterns are disallowed.
37
+ - We now validate that Unicode escape sequences are not surrogates.
38
+
39
+ ### Changed
40
+
41
+ - All fields named `operator` have been renamed to `binary_operator` for `*OperatorWriteNode` nodes. This is to make it easier to provide C++ support. In the Ruby API, the old fields are aliased to the new fields with a deprecation warning.
42
+ - Many updated error messages to more closely match CRuby.
43
+ - We ensure keyword parameters do not end in `!` or `?`.
44
+ - Fixed some escaping in string literals with control sequences and hex escapes.
45
+ - Fix a bug with RBS types when used outside the `ruby/prism` codebase.
46
+
9
47
  ## [0.28.0] - 2024-05-03
10
48
 
11
49
  ### Added
@@ -500,7 +538,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
500
538
 
501
539
  - 🎉 Initial release! 🎉
502
540
 
503
- [unreleased]: https://github.com/ruby/prism/compare/v0.28.0...HEAD
541
+ [unreleased]: https://github.com/ruby/prism/compare/v0.30.0...HEAD
542
+ [0.30.0]: https://github.com/ruby/prism/compare/v0.29.0...v0.30.0
543
+ [0.29.0]: https://github.com/ruby/prism/compare/v0.28.0...v0.29.0
504
544
  [0.28.0]: https://github.com/ruby/prism/compare/v0.27.0...v0.28.0
505
545
  [0.27.0]: https://github.com/ruby/prism/compare/v0.26.0...v0.27.0
506
546
  [0.26.0]: https://github.com/ruby/prism/compare/v0.25.0...v0.26.0
data/CONTRIBUTING.md CHANGED
@@ -10,10 +10,6 @@ The discussions page on the GitHub repository are open. If you have a question o
10
10
 
11
11
  If you want to contribute code, please first open or contribute to a discussion. A lot of the project is in flux, and we want to make sure that you are contributing to the right place. Once you have a discussion going, you can open a pull request with your changes. We will review your code and get it merged in.
12
12
 
13
- ### Ruby Features
14
-
15
- Pattern matching and endless method definitions should be avoided as long as the latest TruffleRuby release does not support it.
16
-
17
13
  ## Tests
18
14
 
19
15
  We could always use more tests! One of the biggest challenges of this project is building up a big test suite. If you want to contribute tests, feel free to open a pull request. These will get merged in as soon as possible.
data/README.md CHANGED
@@ -40,6 +40,7 @@ The repository contains the infrastructure for both a shared library (libprism)
40
40
  ├── rust
41
41
  │   ├── ruby-prism Rustified crate for the shared library
42
42
  │   └── ruby-prism-sys FFI binding for Rust
43
+ ├── sample Sample code that uses the Ruby API for documentation
43
44
  ├── sig RBS type signatures for the Ruby library
44
45
  ├── src
45
46
  │   ├── util various utility files
data/config.yml CHANGED
@@ -7,13 +7,16 @@ errors:
7
7
  - ARGUMENT_BARE_HASH
8
8
  - ARGUMENT_BLOCK_FORWARDING
9
9
  - ARGUMENT_BLOCK_MULTI
10
+ - ARGUMENT_CONFLICT_AMPERSAND
11
+ - ARGUMENT_CONFLICT_STAR
12
+ - ARGUMENT_CONFLICT_STAR_STAR
10
13
  - ARGUMENT_FORMAL_CLASS
11
14
  - ARGUMENT_FORMAL_CONSTANT
12
15
  - ARGUMENT_FORMAL_GLOBAL
13
16
  - ARGUMENT_FORMAL_IVAR
14
17
  - ARGUMENT_FORWARDING_UNBOUND
15
18
  - ARGUMENT_IN
16
- - ARGUMENT_NO_FORWARDING_AMP
19
+ - ARGUMENT_NO_FORWARDING_AMPERSAND
17
20
  - ARGUMENT_NO_FORWARDING_ELLIPSES
18
21
  - ARGUMENT_NO_FORWARDING_STAR
19
22
  - ARGUMENT_NO_FORWARDING_STAR_STAR
@@ -95,6 +98,7 @@ errors:
95
98
  - EXPECT_EXPRESSION_AFTER_SPLAT_HASH
96
99
  - EXPECT_EXPRESSION_AFTER_STAR
97
100
  - EXPECT_IDENT_REQ_PARAMETER
101
+ - EXPECT_IN_DELIMITER
98
102
  - EXPECT_LPAREN_REQ_PARAMETER
99
103
  - EXPECT_MESSAGE
100
104
  - EXPECT_RBRACKET
@@ -110,6 +114,7 @@ errors:
110
114
  - EXPRESSION_NOT_WRITABLE_FILE
111
115
  - EXPRESSION_NOT_WRITABLE_LINE
112
116
  - EXPRESSION_NOT_WRITABLE_NIL
117
+ - EXPRESSION_NOT_WRITABLE_NUMBERED
113
118
  - EXPRESSION_NOT_WRITABLE_SELF
114
119
  - EXPRESSION_NOT_WRITABLE_TRUE
115
120
  - FLOAT_PARSE
@@ -134,6 +139,7 @@ errors:
134
139
  - INVALID_BLOCK_EXIT
135
140
  - INVALID_CHARACTER
136
141
  - INVALID_ENCODING_MAGIC_COMMENT
142
+ - INVALID_ESCAPE_CHARACTER
137
143
  - INVALID_FLOAT_EXPONENT
138
144
  - INVALID_LOCAL_VARIABLE_READ
139
145
  - INVALID_LOCAL_VARIABLE_WRITE
@@ -142,11 +148,13 @@ errors:
142
148
  - INVALID_MULTIBYTE_ESCAPE
143
149
  - INVALID_NUMBER_BINARY
144
150
  - INVALID_NUMBER_DECIMAL
151
+ - INVALID_NUMBER_FRACTION
145
152
  - INVALID_NUMBER_HEXADECIMAL
146
153
  - INVALID_NUMBER_OCTAL
147
154
  - INVALID_NUMBER_UNDERSCORE_INNER
148
155
  - INVALID_NUMBER_UNDERSCORE_TRAILING
149
156
  - INVALID_PERCENT
157
+ - INVALID_PERCENT_EOF
150
158
  - INVALID_PRINTABLE_CHARACTER
151
159
  - INVALID_RETRY_AFTER_ELSE
152
160
  - INVALID_RETRY_AFTER_ENSURE
@@ -178,15 +186,17 @@ errors:
178
186
  - NO_LOCAL_VARIABLE
179
187
  - NOT_EXPRESSION
180
188
  - NUMBER_LITERAL_UNDERSCORE
189
+ - NUMBERED_PARAMETER_INNER_BLOCK
181
190
  - NUMBERED_PARAMETER_IT
182
191
  - NUMBERED_PARAMETER_ORDINARY
183
- - NUMBERED_PARAMETER_OUTER_SCOPE
192
+ - NUMBERED_PARAMETER_OUTER_BLOCK
184
193
  - OPERATOR_MULTI_ASSIGN
185
194
  - OPERATOR_WRITE_ARGUMENTS
186
195
  - OPERATOR_WRITE_BLOCK
187
196
  - PARAMETER_ASSOC_SPLAT_MULTI
188
197
  - PARAMETER_BLOCK_MULTI
189
198
  - PARAMETER_CIRCULAR
199
+ - PARAMETER_FORWARDING_AFTER_REST
190
200
  - PARAMETER_METHOD_NAME
191
201
  - PARAMETER_NAME_DUPLICATED
192
202
  - PARAMETER_NO_DEFAULT
@@ -196,8 +206,8 @@ errors:
196
206
  - PARAMETER_SPLAT_MULTI
197
207
  - PARAMETER_STAR
198
208
  - PARAMETER_UNEXPECTED_FWD
199
- - PARAMETER_WILD_LOOSE_COMMA
200
209
  - PARAMETER_UNEXPECTED_NO_KW
210
+ - PARAMETER_WILD_LOOSE_COMMA
201
211
  - PATTERN_CAPTURE_DUPLICATE
202
212
  - PATTERN_EXPRESSION_AFTER_BRACKET
203
213
  - PATTERN_EXPRESSION_AFTER_COMMA
@@ -209,8 +219,10 @@ errors:
209
219
  - PATTERN_EXPRESSION_AFTER_PIPE
210
220
  - PATTERN_EXPRESSION_AFTER_RANGE
211
221
  - PATTERN_EXPRESSION_AFTER_REST
222
+ - PATTERN_HASH_IMPLICIT
212
223
  - PATTERN_HASH_KEY
213
224
  - PATTERN_HASH_KEY_DUPLICATE
225
+ - PATTERN_HASH_KEY_INTERPOLATED
214
226
  - PATTERN_HASH_KEY_LABEL
215
227
  - PATTERN_HASH_KEY_LOCALS
216
228
  - PATTERN_IDENT_AFTER_HROCKET
@@ -224,6 +236,7 @@ errors:
224
236
  - REGEXP_INCOMPAT_CHAR_ENCODING
225
237
  - REGEXP_INVALID_UNICODE_RANGE
226
238
  - REGEXP_NON_ESCAPED_MBC
239
+ - REGEXP_PARSE_ERROR
227
240
  - REGEXP_TERM
228
241
  - REGEXP_UNKNOWN_OPTIONS
229
242
  - REGEXP_UTF8_CHAR_NON_UTF8_REGEXP
@@ -264,6 +277,7 @@ errors:
264
277
  - WRITE_TARGET_UNEXPECTED
265
278
  - XSTRING_TERM
266
279
  warnings:
280
+ - AMBIGUOUS_BINARY_OPERATOR
267
281
  - AMBIGUOUS_FIRST_ARGUMENT_MINUS
268
282
  - AMBIGUOUS_FIRST_ARGUMENT_PLUS
269
283
  - AMBIGUOUS_PREFIX_AMPERSAND
@@ -286,6 +300,7 @@ warnings:
286
300
  - KEYWORD_EOL
287
301
  - LITERAL_IN_CONDITION_DEFAULT
288
302
  - LITERAL_IN_CONDITION_VERBOSE
303
+ - SHAREABLE_CONSTANT_VALUE_LINE
289
304
  - SHEBANG_CARRIAGE_RETURN
290
305
  - UNEXPECTED_CARRIAGE_RETURN
291
306
  - UNREACHABLE_STATEMENT
@@ -1203,9 +1218,9 @@ nodes:
1203
1218
  type: constant
1204
1219
  - name: write_name
1205
1220
  type: constant
1206
- - name: operator
1221
+ - name: binary_operator
1207
1222
  type: constant
1208
- - name: operator_loc
1223
+ - name: binary_operator_loc
1209
1224
  type: location
1210
1225
  - name: value
1211
1226
  type: node
@@ -1361,11 +1376,11 @@ nodes:
1361
1376
  type: constant
1362
1377
  - name: name_loc
1363
1378
  type: location
1364
- - name: operator_loc
1379
+ - name: binary_operator_loc
1365
1380
  type: location
1366
1381
  - name: value
1367
1382
  type: node
1368
- - name: operator
1383
+ - name: binary_operator
1369
1384
  type: constant
1370
1385
  comment: |
1371
1386
  Represents assigning to a class variable using an operator that isn't `=`.
@@ -1471,11 +1486,11 @@ nodes:
1471
1486
  type: constant
1472
1487
  - name: name_loc
1473
1488
  type: location
1474
- - name: operator_loc
1489
+ - name: binary_operator_loc
1475
1490
  type: location
1476
1491
  - name: value
1477
1492
  type: node
1478
- - name: operator
1493
+ - name: binary_operator
1479
1494
  type: constant
1480
1495
  comment: |
1481
1496
  Represents assigning to a constant using an operator that isn't `=`.
@@ -1559,11 +1574,11 @@ nodes:
1559
1574
  - name: target
1560
1575
  type: node
1561
1576
  kind: ConstantPathNode
1562
- - name: operator_loc
1577
+ - name: binary_operator_loc
1563
1578
  type: location
1564
1579
  - name: value
1565
1580
  type: node
1566
- - name: operator
1581
+ - name: binary_operator
1567
1582
  type: constant
1568
1583
  comment: |
1569
1584
  Represents assigning to a constant path using an operator that isn't `=`.
@@ -1866,19 +1881,56 @@ nodes:
1866
1881
  fields:
1867
1882
  - name: index
1868
1883
  type: node
1884
+ comment: |
1885
+ The index expression for `for` loops.
1886
+
1887
+ for i in a end
1888
+ ^
1869
1889
  - name: collection
1870
1890
  type: node
1891
+ comment: |
1892
+ The collection to iterate over.
1893
+
1894
+ for i in a end
1895
+ ^
1871
1896
  - name: statements
1872
1897
  type: node?
1873
1898
  kind: StatementsNode
1899
+ comment: |
1900
+ Represents the body of statements to execute for each iteration of the loop.
1901
+
1902
+ for i in a
1903
+ foo(i)
1904
+ ^^^^^^
1905
+ end
1874
1906
  - name: for_keyword_loc
1875
1907
  type: location
1908
+ comment: |
1909
+ The location of the `for` keyword.
1910
+
1911
+ for i in a end
1912
+ ^^^
1876
1913
  - name: in_keyword_loc
1877
1914
  type: location
1915
+ comment: |
1916
+ The location of the `in` keyword.
1917
+
1918
+ for i in a end
1919
+ ^^
1878
1920
  - name: do_keyword_loc
1879
1921
  type: location?
1922
+ comment: |
1923
+ The location of the `do` keyword, if present.
1924
+
1925
+ for i in a do end
1926
+ ^^
1880
1927
  - name: end_keyword_loc
1881
1928
  type: location
1929
+ comment: |
1930
+ The location of the `end` keyword.
1931
+
1932
+ for i in a end
1933
+ ^^^
1882
1934
  comment: |
1883
1935
  Represents the use of the `for` keyword.
1884
1936
 
@@ -1930,11 +1982,11 @@ nodes:
1930
1982
  type: constant
1931
1983
  - name: name_loc
1932
1984
  type: location
1933
- - name: operator_loc
1985
+ - name: binary_operator_loc
1934
1986
  type: location
1935
1987
  - name: value
1936
1988
  type: node
1937
- - name: operator
1989
+ - name: binary_operator
1938
1990
  type: constant
1939
1991
  comment: |
1940
1992
  Represents assigning to a global variable using an operator that isn't `=`.
@@ -2266,9 +2318,9 @@ nodes:
2266
2318
  type: location
2267
2319
  - name: block
2268
2320
  type: node?
2269
- - name: operator
2321
+ - name: binary_operator
2270
2322
  type: constant
2271
- - name: operator_loc
2323
+ - name: binary_operator_loc
2272
2324
  type: location
2273
2325
  - name: value
2274
2326
  type: node
@@ -2354,11 +2406,11 @@ nodes:
2354
2406
  type: constant
2355
2407
  - name: name_loc
2356
2408
  type: location
2357
- - name: operator_loc
2409
+ - name: binary_operator_loc
2358
2410
  type: location
2359
2411
  - name: value
2360
2412
  type: node
2361
- - name: operator
2413
+ - name: binary_operator
2362
2414
  type: constant
2363
2415
  comment: |
2364
2416
  Represents assigning to an instance variable using an operator that isn't `=`.
@@ -2556,6 +2608,12 @@ nodes:
2556
2608
 
2557
2609
  `foo #{bar} baz`
2558
2610
  ^^^^^^^^^^^^^^^^
2611
+ - name: ItLocalVariableReadNode
2612
+ comment: |
2613
+ Represents reading from the implicit `it` local variable.
2614
+
2615
+ -> { it }
2616
+ ^^
2559
2617
  - name: ItParametersNode
2560
2618
  comment: |
2561
2619
  Represents an implicit set of parameters through the use of the `it` keyword within a block or lambda.
@@ -2634,13 +2692,13 @@ nodes:
2634
2692
  fields:
2635
2693
  - name: name_loc
2636
2694
  type: location
2637
- - name: operator_loc
2695
+ - name: binary_operator_loc
2638
2696
  type: location
2639
2697
  - name: value
2640
2698
  type: node
2641
2699
  - name: name
2642
2700
  type: constant
2643
- - name: operator
2701
+ - name: binary_operator
2644
2702
  type: constant
2645
2703
  - name: depth
2646
2704
  type: uint32
@@ -2681,10 +2739,6 @@ nodes:
2681
2739
 
2682
2740
  _1 # name `:_1`
2683
2741
 
2684
- Finally, for the default `it` block parameter, the name is `0it`. This is to distinguish it from an `it` local variable that is explicitly declared.
2685
-
2686
- it # name `:0it`
2687
-
2688
2742
  - name: depth
2689
2743
  type: uint32
2690
2744
  comment: |
@@ -3075,6 +3129,8 @@ nodes:
3075
3129
  # On parsing error of `f(**kwargs, ...)` or `f(**nil, ...)`, the keyword_rest value is moved here:
3076
3130
  - KeywordRestParameterNode
3077
3131
  - NoKeywordsParameterNode
3132
+ # On parsing error of `f(..., ...)`, the first forwarding parameter is moved here:
3133
+ - ForwardingParameterNode
3078
3134
  - name: keywords
3079
3135
  type: node[]
3080
3136
  kind:
@@ -3215,8 +3271,21 @@ nodes:
3215
3271
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3216
3272
  - name: RationalNode
3217
3273
  fields:
3218
- - name: numeric
3219
- type: node
3274
+ - name: flags
3275
+ type: flags
3276
+ kind: IntegerBaseFlags
3277
+ - name: numerator
3278
+ type: integer
3279
+ comment: |
3280
+ The numerator of the rational number.
3281
+
3282
+ 1.5r # numerator 3
3283
+ - name: denominator
3284
+ type: integer
3285
+ comment: |
3286
+ The denominator of the rational number.
3287
+
3288
+ 1.5r # denominator 2
3220
3289
  comment: |
3221
3290
  Represents a rational number literal.
3222
3291
 
@@ -3555,7 +3624,7 @@ nodes:
3555
3624
  ^^^^
3556
3625
  - name: then_keyword_loc
3557
3626
  type: location?
3558
- comment:
3627
+ comment: |
3559
3628
  The location of the `then` keyword, if present.
3560
3629
 
3561
3630
  unless cond then bar end
data/docs/fuzzing.md CHANGED
@@ -26,7 +26,7 @@ fuzz
26
26
  There are currently three fuzzing targets
27
27
 
28
28
  - `pm_serialize_parse` (parse)
29
- - `pm_regexp_named_capture_group_names` (regexp)
29
+ - `pm_regexp_parse` (regexp)
30
30
 
31
31
  Respectively, fuzzing can be performed with
32
32
 
@@ -48,3 +48,25 @@ ArithmeticRipper.new("1 + 2 - 3").parse # => [0]
48
48
  ```
49
49
 
50
50
  The exact names of the `on_*` methods are listed in the `Ripper` source.
51
+
52
+ ## Background
53
+
54
+ It is helpful to understand the differences between the `Ripper` library and the `Prism` library. Both libraries perform parsing and provide you with APIs to manipulate and understand the resulting syntax tree. However, there are a few key differences.
55
+
56
+ ### Design
57
+
58
+ `Ripper` is a streaming parser. This means as it is parsing Ruby code, it dispatches events back to the consumer. This allows quite a bit of flexibility. You can use it to build your own syntax tree or to find specific patterns in the code. `Prism` on the other hand returns to your the completed syntax tree _before_ it allows you to manipulate it. This means the tree that you get back is the only representation that can be generated by the parser _at parse time_ (but of course can be manipulated later).
59
+
60
+ ### Fields
61
+
62
+ We use the term "field" to mean a piece of information on a syntax tree node. `Ripper` provides the minimal number of fields to accurately represent the syntax tree for the purposes of compilation/interpretation. For example, in the callbacks for nodes that are based on keywords (`class`, `module`, `for`, `while`, etc.) you are not given the keyword itself, you need to attach it on your own. In other cases, tokens are not necessarily dispatched at all, meaning you need to find them yourself. `Prism` provides the opposite: the maximum number of fields on nodes is provided. As a tradeoff, this requires more memory, but this is chosen to make it easier on consumers.
63
+
64
+ ### Maintainability
65
+
66
+ The `Ripper` interface is not guaranteed in any way, and tends to change between patch versions of CRuby. This is largely due to the fact that `Ripper` is a by-product of the generated parser, as opposed to its own parser. As an example, in the expression `foo::bar = baz`, there are three different represents possible for the call operator, including:
67
+
68
+ * `:"::"` - Ruby 1.9 to Ruby 3.1.4
69
+ * `73` - Ruby 3.1.5 to Ruby 3.1.6
70
+ * `[:@op, "::", [lineno, column]]` - Ruby 3.2.0 and later
71
+
72
+ The `Prism` interface is guaranteed going forward to be the consistent, and the official Ruby syntax tree interface. This means you can rely on this interface without having to worry about individual changes between Ruby versions. It also is a gem, which means it is versioned based on the gem version, as opposed to being versioned based on the Ruby version. Finally, you can use `Prism` to parse multiple versions of Ruby, whereas `Ripper` is tied to the Ruby version it is running on.