prism 1.4.0 → 1.7.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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +73 -1
  3. data/Makefile +7 -5
  4. data/README.md +3 -1
  5. data/config.yml +294 -41
  6. data/docs/build_system.md +2 -2
  7. data/docs/cruby_compilation.md +1 -1
  8. data/docs/design.md +2 -2
  9. data/docs/parser_translation.md +8 -23
  10. data/docs/releasing.md +6 -25
  11. data/docs/ripper_translation.md +1 -1
  12. data/ext/prism/api_node.c +9 -3
  13. data/ext/prism/extconf.rb +1 -1
  14. data/ext/prism/extension.c +24 -3
  15. data/ext/prism/extension.h +1 -1
  16. data/include/prism/ast.h +360 -70
  17. data/include/prism/diagnostic.h +7 -0
  18. data/include/prism/options.h +49 -3
  19. data/include/prism/parser.h +3 -0
  20. data/include/prism/regexp.h +2 -2
  21. data/include/prism/util/pm_buffer.h +8 -0
  22. data/include/prism/util/pm_integer.h +4 -0
  23. data/include/prism/util/pm_list.h +6 -0
  24. data/include/prism/util/pm_string.h +12 -2
  25. data/include/prism/version.h +2 -2
  26. data/include/prism.h +40 -15
  27. data/lib/prism/compiler.rb +456 -151
  28. data/lib/prism/desugar_compiler.rb +1 -0
  29. data/lib/prism/dispatcher.rb +16 -0
  30. data/lib/prism/dot_visitor.rb +10 -1
  31. data/lib/prism/dsl.rb +5 -2
  32. data/lib/prism/ffi.rb +28 -10
  33. data/lib/prism/inspect_visitor.rb +4 -0
  34. data/lib/prism/lex_compat.rb +1 -0
  35. data/lib/prism/mutation_compiler.rb +3 -0
  36. data/lib/prism/node.rb +559 -349
  37. data/lib/prism/node_ext.rb +4 -1
  38. data/lib/prism/pack.rb +2 -0
  39. data/lib/prism/parse_result/comments.rb +1 -0
  40. data/lib/prism/parse_result/errors.rb +1 -0
  41. data/lib/prism/parse_result/newlines.rb +1 -0
  42. data/lib/prism/parse_result.rb +3 -15
  43. data/lib/prism/pattern.rb +1 -0
  44. data/lib/prism/polyfill/scan_byte.rb +14 -0
  45. data/lib/prism/polyfill/warn.rb +36 -0
  46. data/lib/prism/reflection.rb +4 -1
  47. data/lib/prism/relocation.rb +1 -0
  48. data/lib/prism/serialize.rb +30 -22
  49. data/lib/prism/string_query.rb +1 -0
  50. data/lib/prism/translation/parser/builder.rb +1 -0
  51. data/lib/prism/translation/parser/compiler.rb +63 -41
  52. data/lib/prism/translation/parser/lexer.rb +29 -21
  53. data/lib/prism/translation/parser.rb +25 -4
  54. data/lib/prism/translation/parser33.rb +1 -0
  55. data/lib/prism/translation/parser34.rb +1 -0
  56. data/lib/prism/translation/parser35.rb +2 -6
  57. data/lib/prism/translation/parser40.rb +13 -0
  58. data/lib/prism/translation/parser41.rb +13 -0
  59. data/lib/prism/translation/parser_current.rb +26 -0
  60. data/lib/prism/translation/ripper/sexp.rb +1 -0
  61. data/lib/prism/translation/ripper.rb +19 -3
  62. data/lib/prism/translation/ruby_parser.rb +340 -22
  63. data/lib/prism/translation.rb +4 -0
  64. data/lib/prism/visitor.rb +457 -152
  65. data/lib/prism.rb +22 -0
  66. data/prism.gemspec +9 -1
  67. data/rbi/prism/dsl.rbi +6 -6
  68. data/rbi/prism/node.rbi +42 -17
  69. data/rbi/prism/translation/parser35.rbi +0 -2
  70. data/rbi/prism/translation/parser40.rbi +6 -0
  71. data/rbi/prism/translation/parser41.rbi +6 -0
  72. data/sig/prism/dispatcher.rbs +3 -0
  73. data/sig/prism/dsl.rbs +5 -5
  74. data/sig/prism/node.rbs +462 -38
  75. data/sig/prism/node_ext.rbs +84 -17
  76. data/sig/prism/parse_result/comments.rbs +38 -0
  77. data/sig/prism/parse_result.rbs +4 -0
  78. data/sig/prism/reflection.rbs +1 -1
  79. data/sig/prism.rbs +4 -0
  80. data/src/diagnostic.c +13 -1
  81. data/src/encoding.c +172 -67
  82. data/src/node.c +11 -0
  83. data/src/options.c +17 -7
  84. data/src/prettyprint.c +18 -0
  85. data/src/prism.c +1495 -2021
  86. data/src/serialize.c +9 -1
  87. data/src/token_type.c +38 -36
  88. data/src/util/pm_constant_pool.c +1 -1
  89. data/src/util/pm_string.c +6 -8
  90. metadata +11 -3
data/config.yml CHANGED
@@ -60,6 +60,7 @@ errors:
60
60
  - CONDITIONAL_WHILE_PREDICATE
61
61
  - CONSTANT_PATH_COLON_COLON_CONSTANT
62
62
  - DEF_ENDLESS
63
+ - DEF_ENDLESS_PARAMETERS
63
64
  - DEF_ENDLESS_SETTER
64
65
  - DEF_NAME
65
66
  - DEF_PARAMS_TERM
@@ -101,6 +102,8 @@ errors:
101
102
  - EXPECT_FOR_DELIMITER
102
103
  - EXPECT_IDENT_REQ_PARAMETER
103
104
  - EXPECT_IN_DELIMITER
105
+ - EXPECT_LPAREN_AFTER_NOT_LPAREN
106
+ - EXPECT_LPAREN_AFTER_NOT_OTHER
104
107
  - EXPECT_LPAREN_REQ_PARAMETER
105
108
  - EXPECT_MESSAGE
106
109
  - EXPECT_RBRACKET
@@ -216,6 +219,7 @@ errors:
216
219
  - PARAMETER_WILD_LOOSE_COMMA
217
220
  - PATTERN_ARRAY_MULTIPLE_RESTS
218
221
  - PATTERN_CAPTURE_DUPLICATE
222
+ - PATTERN_CAPTURE_IN_ALTERNATIVE
219
223
  - PATTERN_EXPRESSION_AFTER_BRACKET
220
224
  - PATTERN_EXPRESSION_AFTER_COMMA
221
225
  - PATTERN_EXPRESSION_AFTER_HROCKET
@@ -277,6 +281,7 @@ errors:
277
281
  - UNEXPECTED_INDEX_KEYWORDS
278
282
  - UNEXPECTED_LABEL
279
283
  - UNEXPECTED_MULTI_WRITE
284
+ - UNEXPECTED_PARAMETER_DEFAULT_VALUE
280
285
  - UNEXPECTED_RANGE_OPERATOR
281
286
  - UNEXPECTED_SAFE_NAVIGATION
282
287
  - UNEXPECTED_TOKEN_CLOSE_CONTEXT
@@ -320,13 +325,44 @@ warnings:
320
325
  - UNUSED_LOCAL_VARIABLE
321
326
  - VOID_STATEMENT
322
327
  tokens:
328
+ # The order of the tokens at the beginning is important, because we use them
329
+ # for a lookup table.
323
330
  - name: EOF
324
331
  value: 1
325
332
  comment: final token in the file
326
- - name: MISSING
327
- comment: "a token that was expected but not found"
328
- - name: NOT_PROVIDED
329
- comment: "a token that was not present but it is okay"
333
+ - name: BRACE_RIGHT
334
+ comment: "}"
335
+ - name: COMMA
336
+ comment: ","
337
+ - name: EMBEXPR_END
338
+ comment: "}"
339
+ - name: KEYWORD_DO
340
+ comment: "do"
341
+ - name: KEYWORD_ELSE
342
+ comment: "else"
343
+ - name: KEYWORD_ELSIF
344
+ comment: "elsif"
345
+ - name: KEYWORD_END
346
+ comment: "end"
347
+ - name: KEYWORD_ENSURE
348
+ comment: "ensure"
349
+ - name: KEYWORD_IN
350
+ comment: "in"
351
+ - name: KEYWORD_RESCUE
352
+ comment: "rescue"
353
+ - name: KEYWORD_THEN
354
+ comment: "then"
355
+ - name: KEYWORD_WHEN
356
+ comment: "when"
357
+ - name: NEWLINE
358
+ comment: "a newline character outside of other tokens"
359
+ - name: PARENTHESIS_RIGHT
360
+ comment: ")"
361
+ - name: PIPE
362
+ comment: "|"
363
+ - name: SEMICOLON
364
+ comment: ";"
365
+ # Tokens from here on are not used for lookup, and can be in any order.
330
366
  - name: AMPERSAND
331
367
  comment: "&"
332
368
  - name: AMPERSAND_AMPERSAND
@@ -349,8 +385,6 @@ tokens:
349
385
  comment: "!~"
350
386
  - name: BRACE_LEFT
351
387
  comment: "{"
352
- - name: BRACE_RIGHT
353
- comment: "}"
354
388
  - name: BRACKET_LEFT
355
389
  comment: "["
356
390
  - name: BRACKET_LEFT_ARRAY
@@ -373,8 +407,6 @@ tokens:
373
407
  comment: ":"
374
408
  - name: COLON_COLON
375
409
  comment: "::"
376
- - name: COMMA
377
- comment: ","
378
410
  - name: COMMENT
379
411
  comment: "a comment"
380
412
  - name: CONSTANT
@@ -393,8 +425,6 @@ tokens:
393
425
  comment: "a line inside of embedded documentation"
394
426
  - name: EMBEXPR_BEGIN
395
427
  comment: "#{"
396
- - name: EMBEXPR_END
397
- comment: "}"
398
428
  - name: EMBVAR
399
429
  comment: "#"
400
430
  - name: EQUAL
@@ -461,20 +491,10 @@ tokens:
461
491
  comment: "def"
462
492
  - name: KEYWORD_DEFINED
463
493
  comment: "defined?"
464
- - name: KEYWORD_DO
465
- comment: "do"
466
494
  - name: KEYWORD_DO_LOOP
467
495
  comment: "do keyword for a predicate in a while, until, or for loop"
468
- - name: KEYWORD_ELSE
469
- comment: "else"
470
- - name: KEYWORD_ELSIF
471
- comment: "elsif"
472
- - name: KEYWORD_END
473
- comment: "end"
474
496
  - name: KEYWORD_END_UPCASE
475
497
  comment: "END"
476
- - name: KEYWORD_ENSURE
477
- comment: "ensure"
478
498
  - name: KEYWORD_FALSE
479
499
  comment: "false"
480
500
  - name: KEYWORD_FOR
@@ -483,8 +503,6 @@ tokens:
483
503
  comment: "if"
484
504
  - name: KEYWORD_IF_MODIFIER
485
505
  comment: "if in the modifier form"
486
- - name: KEYWORD_IN
487
- comment: "in"
488
506
  - name: KEYWORD_MODULE
489
507
  comment: "module"
490
508
  - name: KEYWORD_NEXT
@@ -497,8 +515,6 @@ tokens:
497
515
  comment: "or"
498
516
  - name: KEYWORD_REDO
499
517
  comment: "redo"
500
- - name: KEYWORD_RESCUE
501
- comment: "rescue"
502
518
  - name: KEYWORD_RESCUE_MODIFIER
503
519
  comment: "rescue in the modifier form"
504
520
  - name: KEYWORD_RETRY
@@ -509,8 +525,6 @@ tokens:
509
525
  comment: "self"
510
526
  - name: KEYWORD_SUPER
511
527
  comment: "super"
512
- - name: KEYWORD_THEN
513
- comment: "then"
514
528
  - name: KEYWORD_TRUE
515
529
  comment: "true"
516
530
  - name: KEYWORD_UNDEF
@@ -523,8 +537,6 @@ tokens:
523
537
  comment: "until"
524
538
  - name: KEYWORD_UNTIL_MODIFIER
525
539
  comment: "until in the modifier form"
526
- - name: KEYWORD_WHEN
527
- comment: "when"
528
540
  - name: KEYWORD_WHILE
529
541
  comment: "while"
530
542
  - name: KEYWORD_WHILE_MODIFIER
@@ -561,16 +573,12 @@ tokens:
561
573
  comment: "-="
562
574
  - name: MINUS_GREATER
563
575
  comment: "->"
564
- - name: NEWLINE
565
- comment: "a newline character outside of other tokens"
566
576
  - name: NUMBERED_REFERENCE
567
577
  comment: "a numbered reference to a capture group in the previous regular expression match"
568
578
  - name: PARENTHESIS_LEFT
569
579
  comment: "("
570
580
  - name: PARENTHESIS_LEFT_PARENTHESES
571
581
  comment: "( for a parentheses node"
572
- - name: PARENTHESIS_RIGHT
573
- comment: ")"
574
582
  - name: PERCENT
575
583
  comment: "%"
576
584
  - name: PERCENT_EQUAL
@@ -585,8 +593,6 @@ tokens:
585
593
  comment: "%I"
586
594
  - name: PERCENT_UPPER_W
587
595
  comment: "%W"
588
- - name: PIPE
589
- comment: "|"
590
596
  - name: PIPE_EQUAL
591
597
  comment: "|="
592
598
  - name: PIPE_PIPE
@@ -603,8 +609,6 @@ tokens:
603
609
  comment: "the beginning of a regular expression"
604
610
  - name: REGEXP_END
605
611
  comment: "the end of a regular expression"
606
- - name: SEMICOLON
607
- comment: ";"
608
612
  - name: SLASH
609
613
  comment: "/"
610
614
  - name: SLASH_EQUAL
@@ -649,6 +653,10 @@ tokens:
649
653
  comment: "a separator between words in a list"
650
654
  - name: __END__
651
655
  comment: "marker for the point in the file at which the parser should stop"
656
+ - name: MISSING
657
+ comment: "a token that was expected but not found"
658
+ - name: NOT_PROVIDED
659
+ comment: "a token that was not present but it is okay"
652
660
  flags:
653
661
  - name: ArgumentsNodeFlags
654
662
  values:
@@ -987,8 +995,19 @@ nodes:
987
995
  - name: constant
988
996
  type: node?
989
997
  kind:
990
- - ConstantReadNode
991
998
  - ConstantPathNode
999
+ - ConstantReadNode
1000
+ comment: |
1001
+ Represents the optional constant preceding the Array
1002
+
1003
+ foo in Bar[]
1004
+ ^^^
1005
+
1006
+ foo in Bar[1, 2, 3]
1007
+ ^^^
1008
+
1009
+ foo in Bar::Baz[1, 2, 3]
1010
+ ^^^^^^^^
992
1011
  - name: requireds
993
1012
  type: node[]
994
1013
  kind: pattern expression
@@ -1498,6 +1517,16 @@ nodes:
1498
1517
 
1499
1518
  foo(bar)
1500
1519
  ^
1520
+ - name: equal_loc
1521
+ type: location?
1522
+ comment: |
1523
+ Represents the location of the equal sign, in the case that this is an attribute write.
1524
+
1525
+ foo.bar = value
1526
+ ^
1527
+
1528
+ foo[bar] = value
1529
+ ^
1501
1530
  - name: block
1502
1531
  type: node?
1503
1532
  kind:
@@ -1784,7 +1813,7 @@ nodes:
1784
1813
  Represents the predicate of the case statement. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1785
1814
 
1786
1815
  case true; when false; end
1787
- ^^^^
1816
+ ^^^^
1788
1817
  - name: conditions
1789
1818
  type: node[]
1790
1819
  kind: WhenNode
@@ -1828,6 +1857,11 @@ nodes:
1828
1857
  type: constant[]
1829
1858
  - name: class_keyword_loc
1830
1859
  type: location
1860
+ comment: |
1861
+ Represents the location of the `class` keyword.
1862
+
1863
+ class Foo end
1864
+ ^^^^^
1831
1865
  - name: constant_path
1832
1866
  type: node
1833
1867
  kind:
@@ -1836,18 +1870,43 @@ nodes:
1836
1870
  - on error: CallNode # class 0.X end
1837
1871
  - name: inheritance_operator_loc
1838
1872
  type: location?
1873
+ comment: |
1874
+ Represents the location of the `<` operator.
1875
+
1876
+ class Foo < Bar
1877
+ ^
1839
1878
  - name: superclass
1840
1879
  type: node?
1841
1880
  kind: non-void expression
1881
+ comment: |
1882
+ Represents the superclass of the class.
1883
+
1884
+ class Foo < Bar
1885
+ ^^^
1842
1886
  - name: body
1843
1887
  type: node?
1844
1888
  kind:
1845
1889
  - StatementsNode
1846
1890
  - BeginNode
1891
+ comment: |
1892
+ Represents the body of the class.
1893
+
1894
+ class Foo
1895
+ foo
1896
+ ^^^
1847
1897
  - name: end_keyword_loc
1848
1898
  type: location
1899
+ comment: |
1900
+ Represents the location of the `end` keyword.
1901
+
1902
+ class Foo end
1903
+ ^^^
1849
1904
  - name: name
1850
1905
  type: constant
1906
+ comment: |
1907
+ The name of the class.
1908
+
1909
+ class Foo end # name `:Foo`
1851
1910
  comment: |
1852
1911
  Represents a class declaration involving the `class` keyword.
1853
1912
 
@@ -2374,23 +2433,68 @@ nodes:
2374
2433
  - name: constant
2375
2434
  type: node?
2376
2435
  kind:
2377
- - ConstantReadNode
2378
2436
  - ConstantPathNode
2437
+ - ConstantReadNode
2438
+ comment: |
2439
+ Represents the optional constant preceding the pattern
2440
+
2441
+ foo in Foo(*bar, baz, *qux)
2442
+ ^^^
2379
2443
  - name: left
2380
2444
  type: node
2381
2445
  kind: SplatNode
2446
+ comment: |
2447
+ Represents the first wildcard node in the pattern.
2448
+
2449
+ foo in *bar, baz, *qux
2450
+ ^^^^
2451
+
2452
+ foo in Foo(*bar, baz, *qux)
2453
+ ^^^^
2382
2454
  - name: requireds
2383
2455
  type: node[]
2384
2456
  kind: pattern expression
2457
+ comment: |
2458
+ Represents the nodes in between the wildcards.
2459
+
2460
+ foo in *bar, baz, *qux
2461
+ ^^^
2462
+
2463
+ foo in Foo(*bar, baz, 1, *qux)
2464
+ ^^^^^^
2385
2465
  - name: right
2386
2466
  type: node
2387
2467
  kind:
2388
2468
  - SplatNode
2389
2469
  - on error: MissingNode
2470
+ comment: |
2471
+ Represents the second wildcard node in the pattern.
2472
+
2473
+ foo in *bar, baz, *qux
2474
+ ^^^^
2475
+
2476
+ foo in Foo(*bar, baz, *qux)
2477
+ ^^^^
2390
2478
  - name: opening_loc
2391
2479
  type: location?
2480
+ comment: |
2481
+ The location of the opening brace.
2482
+
2483
+ foo in [*bar, baz, *qux]
2484
+ ^
2485
+
2486
+ foo in Foo(*bar, baz, *qux)
2487
+ ^
2392
2488
  - name: closing_loc
2393
2489
  type: location?
2490
+ comment: |
2491
+ The location of the closing brace.
2492
+
2493
+ foo in [*bar, baz, *qux]
2494
+ ^
2495
+
2496
+ foo in Foo(*bar, baz, *qux)
2497
+ ^
2394
2498
  comment: |
2395
2499
  Represents a find pattern in pattern matching.
2396
2500
 
@@ -2402,6 +2506,9 @@ nodes:
2402
2506
 
2403
2507
  foo in Foo(*bar, baz, *qux)
2404
2508
  ^^^^^^^^^^^^^^^^^^^^
2509
+
2510
+ foo => *bar, baz, *qux
2511
+ ^^^^^^^^^^^^^^^
2405
2512
  - name: FlipFlopNode
2406
2513
  flags: RangeFlags
2407
2514
  fields:
@@ -2521,11 +2628,18 @@ nodes:
2521
2628
  - name: block
2522
2629
  type: node?
2523
2630
  kind: BlockNode
2631
+ comment: |
2632
+ All other arguments are forwarded as normal, except the original block is replaced with the new block.
2524
2633
  comment: |
2525
- Represents the use of the `super` keyword without parentheses or arguments.
2634
+ Represents the use of the `super` keyword without parentheses or arguments, but which might have a block.
2526
2635
 
2527
2636
  super
2528
2637
  ^^^^^
2638
+
2639
+ super { 123 }
2640
+ ^^^^^^^^^^^^^
2641
+
2642
+ If it has any other arguments, it would be a `SuperNode` instead.
2529
2643
  - name: GlobalVariableAndWriteNode
2530
2644
  fields:
2531
2645
  - name: name
@@ -2679,20 +2793,60 @@ nodes:
2679
2793
  - name: constant
2680
2794
  type: node?
2681
2795
  kind:
2682
- - ConstantReadNode
2683
2796
  - ConstantPathNode
2797
+ - ConstantReadNode
2798
+ comment: |
2799
+ Represents the optional constant preceding the Hash.
2800
+
2801
+ foo => Bar[a: 1, b: 2]
2802
+ ^^^
2803
+
2804
+ foo => Bar::Baz[a: 1, b: 2]
2805
+ ^^^^^^^^
2684
2806
  - name: elements
2685
2807
  type: node[]
2686
2808
  kind: AssocNode
2809
+ comment: |
2810
+ Represents the explicit named hash keys and values.
2811
+
2812
+ foo => { a: 1, b:, ** }
2813
+ ^^^^^^^^
2687
2814
  - name: rest
2688
2815
  type: node?
2689
2816
  kind:
2690
2817
  - AssocSplatNode
2691
2818
  - NoKeywordsParameterNode
2819
+ comment: |
2820
+ Represents the rest of the Hash keys and values. This can be named, unnamed, or explicitly forbidden via `**nil`, this last one results in a `NoKeywordsParameterNode`.
2821
+
2822
+ foo => { a: 1, b:, **c }
2823
+ ^^^
2824
+
2825
+ foo => { a: 1, b:, ** }
2826
+ ^^
2827
+
2828
+ foo => { a: 1, b:, **nil }
2829
+ ^^^^^
2692
2830
  - name: opening_loc
2693
2831
  type: location?
2832
+ comment: |
2833
+ The location of the opening brace.
2834
+
2835
+ foo => { a: 1 }
2836
+ ^
2837
+
2838
+ foo => Bar[a: 1]
2839
+ ^
2694
2840
  - name: closing_loc
2695
2841
  type: location?
2842
+ comment: |
2843
+ The location of the closing brace.
2844
+
2845
+ foo => { a: 1 }
2846
+ ^
2847
+
2848
+ foo => Bar[a: 1]
2849
+ ^
2696
2850
  comment: |
2697
2851
  Represents a hash pattern in pattern matching.
2698
2852
 
@@ -2701,6 +2855,12 @@ nodes:
2701
2855
 
2702
2856
  foo => { a: 1, b: 2, **c }
2703
2857
  ^^^^^^^^^^^^^^^^^^^
2858
+
2859
+ foo => Bar[a: 1, b: 2]
2860
+ ^^^^^^^^^^^^^^^
2861
+
2862
+ foo in { a: 1, b: 2 }
2863
+ ^^^^^^^^^^^^^^
2704
2864
  - name: IfNode
2705
2865
  fields:
2706
2866
  - name: if_keyword_loc
@@ -3146,6 +3306,9 @@ nodes:
3146
3306
  - EmbeddedVariableNode
3147
3307
  - InterpolatedStringNode # `"a" "#{b}"`
3148
3308
  - on error: XStringNode # `<<`FOO` "bar"
3309
+ - on error: InterpolatedXStringNode
3310
+ - on error: SymbolNode
3311
+ - on error: InterpolatedSymbolNode
3149
3312
  - name: closing_loc
3150
3313
  type: location?
3151
3314
  newline: parts
@@ -3353,6 +3516,9 @@ nodes:
3353
3516
 
3354
3517
  foo, bar = baz
3355
3518
  ^^^ ^^^
3519
+
3520
+ foo => baz
3521
+ ^^^
3356
3522
  - name: LocalVariableWriteNode
3357
3523
  fields:
3358
3524
  - name: name
@@ -3443,11 +3609,65 @@ nodes:
3443
3609
  - name: value
3444
3610
  type: node
3445
3611
  kind: non-void expression
3612
+ comment: |
3613
+ Represents the left-hand side of the operator.
3614
+
3615
+ foo => bar
3616
+ ^^^
3446
3617
  - name: pattern
3447
3618
  type: node
3448
3619
  kind: pattern expression
3620
+ comment: |
3621
+ Represents the right-hand side of the operator. The type of the node depends on the expression.
3622
+
3623
+ Anything that looks like a local variable name (including `_`) will result in a `LocalVariableTargetNode`.
3624
+
3625
+ foo => a # This is equivalent to writing `a = foo`
3626
+ ^
3627
+
3628
+ Using an explicit `Array` or combining expressions with `,` will result in a `ArrayPatternNode`. This can be preceded by a constant.
3629
+
3630
+ foo => [a]
3631
+ ^^^
3632
+
3633
+ foo => a, b
3634
+ ^^^^
3635
+
3636
+ foo => Bar[a, b]
3637
+ ^^^^^^^^^
3638
+
3639
+ If the array pattern contains at least two wildcard matches, a `FindPatternNode` is created instead.
3640
+
3641
+ foo => *, 1, *a
3642
+ ^^^^^
3643
+
3644
+ Using an explicit `Hash` or a constant with square brackets and hash keys in the square brackets will result in a `HashPatternNode`.
3645
+
3646
+ foo => { a: 1, b: }
3647
+
3648
+ foo => Bar[a: 1, b:]
3649
+
3650
+ foo => Bar[**]
3651
+
3652
+ To use any variable that needs run time evaluation, pinning is required. This results in a `PinnedVariableNode`
3653
+
3654
+ foo => ^a
3655
+ ^^
3656
+
3657
+ Similar, any expression can be used with pinning. This results in a `PinnedExpressionNode`.
3658
+
3659
+ foo => ^(a + 1)
3660
+
3661
+ Anything else will result in the regular node for that expression, for example a `ConstantReadNode`.
3662
+
3663
+ foo => CONST
3449
3664
  - name: operator_loc
3450
3665
  type: location
3666
+ comment: |
3667
+ The location of the operator.
3668
+
3669
+ foo => bar
3670
+ ^^
3451
3671
  comment: |
3452
3672
  Represents the use of the `=>` operator.
3453
3673
 
@@ -3877,12 +4097,32 @@ nodes:
3877
4097
  - name: expression
3878
4098
  type: node
3879
4099
  kind: non-void expression
4100
+ comment: |
4101
+ The expression used in the pinned expression
4102
+
4103
+ foo in ^(bar)
4104
+ ^^^
3880
4105
  - name: operator_loc
3881
4106
  type: location
4107
+ comment: |
4108
+ The location of the `^` operator
4109
+
4110
+ foo in ^(bar)
4111
+ ^
3882
4112
  - name: lparen_loc
3883
4113
  type: location
4114
+ comment: |
4115
+ The location of the opening parenthesis.
4116
+
4117
+ foo in ^(bar)
4118
+ ^
3884
4119
  - name: rparen_loc
3885
4120
  type: location
4121
+ comment: |
4122
+ The location of the closing parenthesis.
4123
+
4124
+ foo in ^(bar)
4125
+ ^
3886
4126
  comment: |
3887
4127
  Represents the use of the `^` operator for pinning an expression in a pattern matching expression.
3888
4128
 
@@ -3901,8 +4141,18 @@ nodes:
3901
4141
  - NumberedReferenceReadNode # foo in ^$1
3902
4142
  - ItLocalVariableReadNode # proc { 1 in ^it }
3903
4143
  - on error: MissingNode # foo in ^Bar
4144
+ comment: |
4145
+ The variable used in the pinned expression
4146
+
4147
+ foo in ^bar
4148
+ ^^^
3904
4149
  - name: operator_loc
3905
4150
  type: location
4151
+ comment: |
4152
+ The location of the `^` operator
4153
+
4154
+ foo in ^bar
4155
+ ^
3906
4156
  comment: |
3907
4157
  Represents the use of the `^` operator for pinning a variable in a pattern matching expression.
3908
4158
 
@@ -4268,6 +4518,7 @@ nodes:
4268
4518
  - name: arguments
4269
4519
  type: node?
4270
4520
  kind: ArgumentsNode
4521
+ comment: "Can be only `nil` when there are empty parentheses, like `super()`."
4271
4522
  - name: rparen_loc
4272
4523
  type: location?
4273
4524
  - name: block
@@ -4283,6 +4534,8 @@ nodes:
4283
4534
 
4284
4535
  super foo, bar
4285
4536
  ^^^^^^^^^^^^^^
4537
+
4538
+ If no arguments are provided (except for a block), it would be a `ForwardingSuperNode` instead.
4286
4539
  - name: SymbolNode
4287
4540
  flags: SymbolFlags
4288
4541
  fields:
data/docs/build_system.md CHANGED
@@ -58,12 +58,12 @@ prism's `Makefile` is not used at all in CRuby. Instead, CRuby's `Makefile` is u
58
58
 
59
59
  ### Building prism as part of TruffleRuby
60
60
 
61
- [This script](https://github.com/oracle/truffleruby/blob/master/tool/import-prism.sh) imports prism sources in TruffleRuby.
61
+ [This script](https://github.com/truffleruby/truffleruby/blob/master/tool/import-prism.sh) imports prism sources in TruffleRuby.
62
62
  The script generates the templates when importing.
63
63
 
64
64
  Then when `mx build` builds TruffleRuby and the `prism` mx project inside, it runs `make`.
65
65
 
66
- Then the `prism bindings` mx project is built, which contains the [bindings](https://github.com/oracle/truffleruby/blob/vm-24.1.1/src/main/c/yarp_bindings/src/yarp_bindings.c)
66
+ Then the `prism bindings` mx project is built, which contains the [bindings](https://github.com/truffleruby/truffleruby/blob/vm-24.1.1/src/main/c/yarp_bindings/src/yarp_bindings.c)
67
67
  and links to `libprism.a` (to avoid exporting symbols, so no conflict when installing the prism gem).
68
68
 
69
69
  ### Building prism as part of JRuby
@@ -1,6 +1,6 @@
1
1
  # Compiling Prism's AST
2
2
 
3
- One important class of consumers of Prism's AST is compilers. Currently [CRuby](https://github.com/ruby/ruby), [JRuby](https://github.com/jruby/jruby), [TruffleRuby](https://github.com/oracle/truffleruby), and [Natalie](https://github.com/natalie-lang/natalie) have all built compilation code on top of Prism's AST.
3
+ One important class of consumers of Prism's AST is compilers. Currently [CRuby](https://github.com/ruby/ruby), [JRuby](https://github.com/jruby/jruby), [TruffleRuby](https://github.com/truffleruby/truffleruby), and [Natalie](https://github.com/natalie-lang/natalie) have all built compilation code on top of Prism's AST.
4
4
 
5
5
  This document will describe, at a high level, how CRuby's compilation of Prism's AST works.
6
6
 
data/docs/design.md CHANGED
@@ -18,11 +18,11 @@ The templated files contain all of the code required to allocate and initialize
18
18
 
19
19
  In order to provide the best possible error tolerance, the parser is hand-written. It is structured using Pratt parsing, a technique developed by Vaughan Pratt back in the 1970s. Below are a bunch of links to articles and papers that explain Pratt parsing in more detail.
20
20
 
21
- * https://web.archive.org/web/20151223215421/http://hall.org.ua/halls/wizzard/pdf/Vaughan.Pratt.TDOP.pdf
21
+ * https://github.com/tdop/tdop.github.io/raw/master/original.pdf
22
22
  * https://tdop.github.io/
23
23
  * https://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
24
24
  * https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html
25
- * https://chidiwilliams.com/post/on-recursive-descent-and-pratt-parsing/
25
+ * https://chidiwilliams.com/posts/on-recursive-descent-and-pratt-parsing
26
26
 
27
27
  You can find most of the functions that correspond to constructs in the Pratt parsing algorithm in `prism.c`. As a couple of examples:
28
28