prism 0.19.0 → 0.20.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 +29 -1
  3. data/Makefile +5 -0
  4. data/README.md +8 -6
  5. data/config.yml +236 -38
  6. data/docs/build_system.md +19 -2
  7. data/docs/cruby_compilation.md +27 -0
  8. data/docs/parser_translation.md +34 -0
  9. data/docs/parsing_rules.md +19 -0
  10. data/docs/releasing.md +3 -3
  11. data/docs/ruby_api.md +1 -1
  12. data/docs/serialization.md +17 -5
  13. data/ext/prism/api_node.c +101 -81
  14. data/ext/prism/extension.c +74 -11
  15. data/ext/prism/extension.h +1 -1
  16. data/include/prism/ast.h +1699 -504
  17. data/include/prism/defines.h +8 -0
  18. data/include/prism/diagnostic.h +39 -2
  19. data/include/prism/encoding.h +10 -0
  20. data/include/prism/options.h +40 -14
  21. data/include/prism/parser.h +33 -17
  22. data/include/prism/util/pm_buffer.h +9 -0
  23. data/include/prism/util/pm_constant_pool.h +7 -0
  24. data/include/prism/util/pm_newline_list.h +0 -11
  25. data/include/prism/version.h +2 -2
  26. data/include/prism.h +19 -2
  27. data/lib/prism/debug.rb +11 -5
  28. data/lib/prism/dot_visitor.rb +36 -14
  29. data/lib/prism/dsl.rb +22 -22
  30. data/lib/prism/ffi.rb +2 -2
  31. data/lib/prism/node.rb +1020 -737
  32. data/lib/prism/node_ext.rb +2 -2
  33. data/lib/prism/parse_result.rb +17 -9
  34. data/lib/prism/serialize.rb +53 -29
  35. data/lib/prism/translation/parser/compiler.rb +1831 -0
  36. data/lib/prism/translation/parser/lexer.rb +335 -0
  37. data/lib/prism/translation/parser/rubocop.rb +37 -0
  38. data/lib/prism/translation/parser.rb +163 -0
  39. data/lib/prism/translation.rb +11 -0
  40. data/lib/prism.rb +1 -0
  41. data/prism.gemspec +12 -5
  42. data/rbi/prism.rbi +150 -88
  43. data/rbi/prism_static.rbi +15 -3
  44. data/sig/prism.rbs +996 -961
  45. data/sig/prism_static.rbs +123 -46
  46. data/src/diagnostic.c +259 -219
  47. data/src/encoding.c +4 -8
  48. data/src/node.c +2 -6
  49. data/src/options.c +24 -5
  50. data/src/prettyprint.c +174 -42
  51. data/src/prism.c +1136 -328
  52. data/src/serialize.c +12 -9
  53. data/src/token_type.c +353 -4
  54. data/src/util/pm_buffer.c +11 -0
  55. data/src/util/pm_constant_pool.c +12 -11
  56. data/src/util/pm_newline_list.c +2 -14
  57. metadata +10 -3
  58. data/docs/building.md +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72e48ffbc7a58cb622a709f860470c4cf2178113a2ba6a2c9cd4f838229ccff8
4
- data.tar.gz: 709ecc0c274a141a868661f94d28aad3fda3032e1b253b2f699a15ff71200c37
3
+ metadata.gz: 742f60637c4fd77f62b7713f484e87d70249e6e9dfeefc2c2ba0bfe667eed034
4
+ data.tar.gz: 67bd239271c1d848536389668722a0617419b19b6bb250ed39cf17b7a414da4c
5
5
  SHA512:
6
- metadata.gz: 42a21574ff5ca1ce62c836839a8c54ed7d6a3f943cfbbd13d860aa30f3d1cf2b6fd5add3082d7622b30e3403ecbf98a404f3c9ef831744e60d40deabeae44ba2
7
- data.tar.gz: 8ef39e9818ba2f13808a0e1131514709e6c7cbbbf2a0c784d047637d56b0024d35951a852c91d8f29c72477b5e923a6cc2687335cf44ccc761ab2e8e5eb5e521
6
+ metadata.gz: d0a90337f2635d35b08b0932ad6d928610406bb3f908c1b7b601f5fcb08b404604745f93bffd9a4bb84fc13cde0b6b4a71015390546a077daa4e05d7d8cf965e
7
+ data.tar.gz: 231693786022302c486d3c4ea2c8841636e3c94cb37f6b5e410f1ab6ac4ce7fc12e53cd4d67f43d6a38f3292867fda808e655391528619d626823a5163cbf722
data/CHANGELOG.md CHANGED
@@ -6,6 +6,33 @@ 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.20.0] - 2024-01-01
10
+
11
+ ### Added
12
+
13
+ - String literal hash keys are now marked as frozen as static literal.
14
+ - `IndexTargetNode` now always has the `ATTRIBUTE_WRITE` flag.
15
+ - `Call*Node` nodes now have an `IGNORE_VISIBILITY` flag.
16
+ - We now support the `it` default parameter.
17
+ - Errors and warnings now have levels associated with them.
18
+ - Symbols now have correct encoding flags.
19
+ - We have now merged `parser-prism` in, which provides translation to the `whitequark/parser` AST.
20
+ - We now emit errors for invalid method definition receivers.
21
+
22
+ ### Changed
23
+
24
+ - We now emit errors on invalid pinned local variables.
25
+ - When passed scopes, it is now assumed that the innermost scope is the current binding.
26
+ - We now provide better error recovery for non terminated heredocs.
27
+ - Fix for `RationalNode#value` for non-decimal integers.
28
+ - Unary symbols `!@` and `~@` now unescape to `!` and `~`, respectively.
29
+ - `frozen_string_literal: false` now works properly.
30
+
31
+ ### Removed
32
+
33
+ - We've removed the `locals_body_index` field.
34
+ - We've removed the `verbose` option on the various parse APIs. Warnings are now always emitted with their associated level so that consumers can decide how to handle them.
35
+
9
36
  ## [0.19.0] - 2023-12-14
10
37
 
11
38
  ### Added
@@ -296,7 +323,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
296
323
 
297
324
  - 🎉 Initial release! 🎉
298
325
 
299
- [unreleased]: https://github.com/ruby/prism/compare/v0.19.0...HEAD
326
+ [unreleased]: https://github.com/ruby/prism/compare/v0.20.0...HEAD
327
+ [0.20.0]: https://github.com/ruby/prism/compare/v0.19.0...v0.20.0
300
328
  [0.19.0]: https://github.com/ruby/prism/compare/v0.18.0...v0.19.0
301
329
  [0.18.0]: https://github.com/ruby/prism/compare/v0.17.1...v0.18.0
302
330
  [0.17.1]: https://github.com/ruby/prism/compare/v0.17.0...v0.17.1
data/Makefile CHANGED
@@ -25,6 +25,7 @@ all: shared static
25
25
  shared: build/libprism.$(SOEXT)
26
26
  static: build/libprism.a
27
27
  wasm: javascript/src/prism.wasm
28
+ java-wasm: java-wasm/src/test/resources/prism.wasm
28
29
 
29
30
  build/libprism.$(SOEXT): $(SHARED_OBJECTS)
30
31
  $(ECHO) "linking $@"
@@ -38,6 +39,10 @@ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
38
39
  $(ECHO) "building $@"
39
40
  $(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -o $@ $(SOURCES)
40
41
 
42
+ java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)
43
+ $(ECHO) "building $@"
44
+ $(Q) $(WASI_SDK_PATH)/bin/clang $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -lc++ -lc++abi -o $@ $(SOURCES)
45
+
41
46
  build/shared/%.o: src/%.c Makefile $(HEADERS)
42
47
  $(ECHO) "compiling $@"
43
48
  $(Q) mkdir -p $(@D)
data/README.md CHANGED
@@ -32,8 +32,8 @@ The repository contains the infrastructure for both a shared library (libprism)
32
32
  │   └── prism.rb main entrypoint for the Ruby library
33
33
  ├── rakelib various Rake tasks for the project
34
34
  ├── rust
35
- │   ├── prism Rustified crate for the shared library
36
- │   └── prism-sys FFI binding for Rust
35
+ │   ├── ruby-prism Rustified crate for the shared library
36
+ │   └── ruby-prism-sys FFI binding for Rust
37
37
  ├── src
38
38
  │   ├── enc various encoding files
39
39
  │   ├── util various utility files
@@ -50,10 +50,9 @@ The repository contains the infrastructure for both a shared library (libprism)
50
50
 
51
51
  To compile the shared library, you will need:
52
52
 
53
- * A C99 compiler
54
- * autotools (autoconf, automake, libtool)
53
+ * C99 compiler
55
54
  * make
56
- * Ruby 3.3.0-preview1 or later
55
+ * Ruby 3.0.0 or later
57
56
 
58
57
  Once you have these dependencies, run:
59
58
 
@@ -79,8 +78,9 @@ to see the syntax tree for the expression `1 + 2`.
79
78
 
80
79
  See the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information. We additionally have documentation about the overall design of the project as well as various subtopics.
81
80
 
82
- * [Building](docs/building.md)
81
+ * [Build system](docs/build_system.md)
83
82
  * [Configuration](docs/configuration.md)
83
+ * [CRuby compilation](docs/cruby_compilation.md)
84
84
  * [Design](docs/design.md)
85
85
  * [Encoding](docs/encoding.md)
86
86
  * [Fuzzing](docs/fuzzing.md)
@@ -88,6 +88,8 @@ See the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information. We additio
88
88
  * [JavaScript](docs/javascript.md)
89
89
  * [Local variable depth](docs/local_variable_depth.md)
90
90
  * [Mapping](docs/mapping.md)
91
+ * [Parser translation](docs/parser_translation.md)
92
+ * [Parsing rules](docs/parsing_rules.md)
91
93
  * [Releasing](docs/releasing.md)
92
94
  * [Ripper](docs/ripper.md)
93
95
  * [Ruby API](docs/ruby_api.md)
data/config.yml CHANGED
@@ -347,6 +347,8 @@ flags:
347
347
  comment: "a call that could have been a local variable"
348
348
  - name: ATTRIBUTE_WRITE
349
349
  comment: "a call that is an attribute write, so the value being written should be returned"
350
+ - name: IGNORE_VISIBILITY
351
+ comment: "a call that ignores method visibility"
350
352
  comment: Flags for call nodes.
351
353
  - name: EncodingFlags
352
354
  values:
@@ -368,14 +370,19 @@ flags:
368
370
  comment: Flags for integer nodes that correspond to the base of the integer.
369
371
  - name: KeywordHashNodeFlags
370
372
  values:
371
- - name: STATIC_KEYS
372
- comment: "a keyword hash which only has `AssocNode` elements all with static literal keys, which means the elements can be treated as keyword arguments"
373
+ - name: SYMBOL_KEYS
374
+ comment: "a keyword hash which only has `AssocNode` elements all with symbol keys, which means the elements can be treated as keyword arguments"
373
375
  comment: Flags for keyword hash nodes.
374
376
  - name: LoopFlags
375
377
  values:
376
378
  - name: BEGIN_MODIFIER
377
379
  comment: "a loop after a begin statement, so the body is executed first before the condition"
378
380
  comment: Flags for while and until loop nodes.
381
+ - name: ParameterFlags
382
+ values:
383
+ - name: REPEATED_PARAMETER
384
+ comment: "a parameter name that has been repeated in the method signature"
385
+ comment: Flags for parameter nodes.
379
386
  - name: RangeFlags
380
387
  values:
381
388
  - name: EXCLUDE_END
@@ -468,10 +475,31 @@ nodes:
468
475
  fields:
469
476
  - name: left
470
477
  type: node
478
+ comment: |
479
+ Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
480
+
481
+ left and right
482
+ ^^^^
483
+
484
+ 1 && 2
485
+ ^
471
486
  - name: right
472
487
  type: node
488
+ comment: |
489
+ Represents the right side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
490
+
491
+ left && right
492
+ ^^^^^
493
+
494
+ 1 and 2
495
+ ^
473
496
  - name: operator_loc
474
497
  type: location
498
+ comment: |
499
+ The location of the `and` keyword or the `&&` operator.
500
+
501
+ left and right
502
+ ^^^
475
503
  comment: |
476
504
  Represents the use of the `&&` operator or the `and` keyword.
477
505
 
@@ -501,8 +529,7 @@ nodes:
501
529
  - name: closing_loc
502
530
  type: location?
503
531
  comment: |
504
- Represents an array literal. This can be a regular array using brackets or
505
- a special array using % like %w or %i.
532
+ Represents an array literal. This can be a regular array using brackets or a special array using % like %w or %i.
506
533
 
507
534
  [1, 2, 3]
508
535
  ^^^^^^^^^
@@ -541,10 +568,34 @@ nodes:
541
568
  fields:
542
569
  - name: key
543
570
  type: node
571
+ comment: |
572
+ The key of the association. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
573
+
574
+ { a: b }
575
+ ^
576
+
577
+ { foo => bar }
578
+ ^^^
579
+
580
+ { def a; end => 1 }
581
+ ^^^^^^^^^^
544
582
  - name: value
545
- type: node?
583
+ type: node
584
+ comment: |
585
+ The value of the association, if present. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
586
+
587
+ { foo => bar }
588
+ ^^^
589
+
590
+ { x: 1 }
591
+ ^
546
592
  - name: operator_loc
547
593
  type: location?
594
+ comment: |
595
+ The location of the `=>` operator, if present.
596
+
597
+ { foo => bar }
598
+ ^^
548
599
  comment: |
549
600
  Represents a hash key/value pair.
550
601
 
@@ -554,8 +605,18 @@ nodes:
554
605
  fields:
555
606
  - name: value
556
607
  type: node?
608
+ comment: |
609
+ The value to be splatted, if present. Will be missing when keyword rest argument forwarding is used.
610
+
611
+ { **foo }
612
+ ^^^
557
613
  - name: operator_loc
558
614
  type: location
615
+ comment: |
616
+ The location of the `**` operator.
617
+
618
+ { **x }
619
+ ^^
559
620
  comment: |
560
621
  Represents a splat in a hash literal.
561
622
 
@@ -565,6 +626,12 @@ nodes:
565
626
  fields:
566
627
  - name: name
567
628
  type: constant
629
+ comment: |
630
+ The name of the back-reference variable, including the leading `$`.
631
+
632
+ $& # name `:$&`
633
+
634
+ $+ # name `:$+`
568
635
  comment: |
569
636
  Represents reading a reference to a field in the previous match.
570
637
 
@@ -609,6 +676,9 @@ nodes:
609
676
  ^^^^^^^^^^
610
677
  - name: BlockLocalVariableNode
611
678
  fields:
679
+ - name: flags
680
+ type: flags
681
+ kind: ParameterFlags
612
682
  - name: name
613
683
  type: constant
614
684
  comment: |
@@ -620,8 +690,6 @@ nodes:
620
690
  fields:
621
691
  - name: locals
622
692
  type: constant[]
623
- - name: locals_body_index
624
- type: uint32
625
693
  - name: parameters
626
694
  type: node?
627
695
  - name: body
@@ -633,10 +701,13 @@ nodes:
633
701
  comment: |
634
702
  Represents a block of ruby code.
635
703
 
636
- [1, 2, 3].each { |i| puts x }
637
- ^^^^^^^^^^^^^^
704
+ [1, 2, 3].each { |i| puts x }
705
+ ^^^^^^^^^^^^^^
638
706
  - name: BlockParameterNode
639
707
  fields:
708
+ - name: flags
709
+ type: flags
710
+ kind: ParameterFlags
640
711
  - name: name
641
712
  type: constant?
642
713
  - name: name_loc
@@ -712,6 +783,17 @@ nodes:
712
783
  kind: CallNodeFlags
713
784
  - name: receiver
714
785
  type: node?
786
+ comment: |
787
+ The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
788
+
789
+ foo.bar
790
+ ^^^
791
+
792
+ +foo
793
+ ^^^
794
+
795
+ foo + bar
796
+ ^^^
715
797
  - name: call_operator_loc
716
798
  type: location?
717
799
  - name: name
@@ -950,6 +1032,12 @@ nodes:
950
1032
  fields:
951
1033
  - name: name
952
1034
  type: constant
1035
+ comment: |
1036
+ The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
1037
+
1038
+ @@abc # name `:@@abc`
1039
+
1040
+ @@_test # name `:@@_test`
953
1041
  comment: |
954
1042
  Represents referencing a class variable.
955
1043
 
@@ -1120,6 +1208,12 @@ nodes:
1120
1208
  fields:
1121
1209
  - name: name
1122
1210
  type: constant
1211
+ comment: |
1212
+ The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
1213
+
1214
+ X # name `:X`
1215
+
1216
+ SOME_CONSTANT # name `:SOME_CONSTANT`
1123
1217
  comment: |
1124
1218
  Represents referencing a constant.
1125
1219
 
@@ -1164,8 +1258,6 @@ nodes:
1164
1258
  type: node?
1165
1259
  - name: locals
1166
1260
  type: constant[]
1167
- - name: locals_body_index
1168
- type: uint32
1169
1261
  - name: def_keyword_loc
1170
1262
  type: location
1171
1263
  - name: operator_loc
@@ -1407,6 +1499,12 @@ nodes:
1407
1499
  fields:
1408
1500
  - name: name
1409
1501
  type: constant
1502
+ comment: |
1503
+ The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
1504
+
1505
+ $foo # name `:$foo`
1506
+
1507
+ $_Test # name `:$_Test`
1410
1508
  comment: |
1411
1509
  Represents referencing a global variable.
1412
1510
 
@@ -1440,10 +1538,28 @@ nodes:
1440
1538
  fields:
1441
1539
  - name: opening_loc
1442
1540
  type: location
1541
+ comment: |
1542
+ The location of the opening brace.
1543
+
1544
+ { a => b }
1545
+ ^
1443
1546
  - name: elements
1444
1547
  type: node[]
1548
+ comment: |
1549
+ The elements of the hash. These can be either `AssocNode`s or `AssocSplatNode`s.
1550
+
1551
+ { a: b }
1552
+ ^^^^
1553
+
1554
+ { **foo }
1555
+ ^^^^^
1445
1556
  - name: closing_loc
1446
1557
  type: location
1558
+ comment: |
1559
+ The location of the closing brace.
1560
+
1561
+ { a => b }
1562
+ ^
1447
1563
  comment: |
1448
1564
  Represents a hash literal.
1449
1565
 
@@ -1507,14 +1623,16 @@ nodes:
1507
1623
  - name: value
1508
1624
  type: node
1509
1625
  comment: |
1510
- Represents a node that is implicitly being added to the tree but doesn't
1511
- correspond directly to a node in the source.
1626
+ Represents a node that is implicitly being added to the tree but doesn't correspond directly to a node in the source.
1512
1627
 
1513
1628
  { foo: }
1514
1629
  ^^^^
1515
1630
 
1516
1631
  { Foo: }
1517
1632
  ^^^^
1633
+
1634
+ foo in { bar: }
1635
+ ^^^^
1518
1636
  - name: ImplicitRestNode
1519
1637
  comment: |
1520
1638
  Represents using a trailing comma to indicate an implicit rest parameter.
@@ -1709,6 +1827,12 @@ nodes:
1709
1827
  fields:
1710
1828
  - name: name
1711
1829
  type: constant
1830
+ comment: |
1831
+ The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
1832
+
1833
+ @x # name `:@x`
1834
+
1835
+ @_test # name `:@_test`
1712
1836
  comment: |
1713
1837
  Represents referencing an instance variable.
1714
1838
 
@@ -1761,9 +1885,7 @@ nodes:
1761
1885
  type: location
1762
1886
  newline: parts
1763
1887
  comment: |
1764
- Represents a regular expression literal that contains interpolation that
1765
- is being used in the predicate of a conditional to implicitly match
1766
- against the last line read by an IO object.
1888
+ Represents a regular expression literal that contains interpolation that is being used in the predicate of a conditional to implicitly match against the last line read by an IO object.
1767
1889
 
1768
1890
  if /foo #{bar} baz/ then end
1769
1891
  ^^^^^^^^^^^^^^^^
@@ -1840,6 +1962,9 @@ nodes:
1840
1962
  ^^^^
1841
1963
  - name: KeywordRestParameterNode
1842
1964
  fields:
1965
+ - name: flags
1966
+ type: flags
1967
+ kind: ParameterFlags
1843
1968
  - name: name
1844
1969
  type: constant?
1845
1970
  - name: name_loc
@@ -1856,8 +1981,6 @@ nodes:
1856
1981
  fields:
1857
1982
  - name: locals
1858
1983
  type: constant[]
1859
- - name: locals_body_index
1860
- type: uint32
1861
1984
  - name: operator_loc
1862
1985
  type: location
1863
1986
  - name: opening_loc
@@ -1930,12 +2053,33 @@ nodes:
1930
2053
  fields:
1931
2054
  - name: name
1932
2055
  type: constant
2056
+ comment: |
2057
+ The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
2058
+
2059
+ x # name `:x`
2060
+
2061
+ _Test # name `:_Test`
2062
+
2063
+ Note that this can also be an underscore followed by a number for the default block parameters.
2064
+
2065
+ _1 # name `:_1`
2066
+
2067
+ 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.
2068
+
2069
+ it # name `:0it`
2070
+
1933
2071
  - name: depth
1934
2072
  type: uint32
2073
+ comment: |
2074
+ The number of visible scopes that should be searched to find the origin of this local variable.
2075
+
2076
+ foo = 1; foo # depth 0
2077
+
2078
+ bar = 2; tap { bar } # depth 1
2079
+
2080
+ The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
1935
2081
  comment: |
1936
- Represents reading a local variable. Note that this requires that a local
1937
- variable of the same name has already been written to in the same scope,
1938
- otherwise it is parsed as a method call.
2082
+ Represents reading a local variable. Note that this requires that a local variable of the same name has already been written to in the same scope, otherwise it is parsed as a method call.
1939
2083
 
1940
2084
  foo
1941
2085
  ^^^
@@ -1981,9 +2125,7 @@ nodes:
1981
2125
  - name: unescaped
1982
2126
  type: string
1983
2127
  comment: |
1984
- Represents a regular expression literal used in the predicate of a
1985
- conditional to implicitly match against the last line read by an IO
1986
- object.
2128
+ Represents a regular expression literal used in the predicate of a conditional to implicitly match against the last line read by an IO object.
1987
2129
 
1988
2130
  if /foo/i then end
1989
2131
  ^^^^^^
@@ -2021,15 +2163,13 @@ nodes:
2021
2163
  - name: targets
2022
2164
  type: node[]
2023
2165
  comment: |
2024
- Represents writing local variables using a regular expression match with
2025
- named capture groups.
2166
+ Represents writing local variables using a regular expression match with named capture groups.
2026
2167
 
2027
2168
  /(?<foo>bar)/ =~ baz
2028
2169
  ^^^^^^^^^^^^^^^^^^^^
2029
2170
  - name: MissingNode
2030
2171
  comment: |
2031
- Represents a node that is missing from the source and results in a syntax
2032
- error.
2172
+ Represents a node that is missing from the source and results in a syntax error.
2033
2173
  - name: ModuleNode
2034
2174
  fields:
2035
2175
  - name: locals
@@ -2122,8 +2262,7 @@ nodes:
2122
2262
  - name: maximum
2123
2263
  type: uint8
2124
2264
  comment: |
2125
- Represents an implicit set of parameters through the use of numbered
2126
- parameters within a block or lambda.
2265
+ Represents an implicit set of parameters through the use of numbered parameters within a block or lambda.
2127
2266
 
2128
2267
  -> { _1 + _2 }
2129
2268
  ^^^^^^^^^^^^^^
@@ -2131,6 +2270,14 @@ nodes:
2131
2270
  fields:
2132
2271
  - name: number
2133
2272
  type: uint32
2273
+ comment: |
2274
+ The (1-indexed, from the left) number of the capture group. Numbered references that would overflow a `uint32` result in a `number` of exactly `2**32 - 1`.
2275
+
2276
+ $1 # number `1`
2277
+
2278
+ $5432 # number `5432`
2279
+
2280
+ $4294967296 # number `4294967295`
2134
2281
  comment: |
2135
2282
  Represents reading a numbered reference to a capture in the previous match.
2136
2283
 
@@ -2138,6 +2285,9 @@ nodes:
2138
2285
  ^^
2139
2286
  - name: OptionalKeywordParameterNode
2140
2287
  fields:
2288
+ - name: flags
2289
+ type: flags
2290
+ kind: ParameterFlags
2141
2291
  - name: name
2142
2292
  type: constant
2143
2293
  - name: name_loc
@@ -2152,6 +2302,9 @@ nodes:
2152
2302
  end
2153
2303
  - name: OptionalParameterNode
2154
2304
  fields:
2305
+ - name: flags
2306
+ type: flags
2307
+ kind: ParameterFlags
2155
2308
  - name: name
2156
2309
  type: constant
2157
2310
  - name: name_loc
@@ -2170,10 +2323,31 @@ nodes:
2170
2323
  fields:
2171
2324
  - name: left
2172
2325
  type: node
2326
+ comment: |
2327
+ Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2328
+
2329
+ left or right
2330
+ ^^^^
2331
+
2332
+ 1 || 2
2333
+ ^
2173
2334
  - name: right
2174
2335
  type: node
2336
+ comment: |
2337
+ Represents the right side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2338
+
2339
+ left || right
2340
+ ^^^^^
2341
+
2342
+ 1 or 2
2343
+ ^
2175
2344
  - name: operator_loc
2176
2345
  type: location
2346
+ comment: |
2347
+ The location of the `or` keyword or the `||` operator.
2348
+
2349
+ left or right
2350
+ ^^
2177
2351
  comment: |
2178
2352
  Represents the use of the `||` operator or the `or` keyword.
2179
2353
 
@@ -2227,8 +2401,7 @@ nodes:
2227
2401
  - name: rparen_loc
2228
2402
  type: location
2229
2403
  comment: |
2230
- Represents the use of the `^` operator for pinning an expression in a
2231
- pattern matching expression.
2404
+ Represents the use of the `^` operator for pinning an expression in a pattern matching expression.
2232
2405
 
2233
2406
  foo in ^(bar)
2234
2407
  ^^^^^^
@@ -2239,8 +2412,7 @@ nodes:
2239
2412
  - name: operator_loc
2240
2413
  type: location
2241
2414
  comment: |
2242
- Represents the use of the `^` operator for pinning a variable in a pattern
2243
- matching expression.
2415
+ Represents the use of the `^` operator for pinning a variable in a pattern matching expression.
2244
2416
 
2245
2417
  foo in ^bar
2246
2418
  ^^^^
@@ -2291,10 +2463,29 @@ nodes:
2291
2463
  kind: RangeFlags
2292
2464
  - name: left
2293
2465
  type: node?
2466
+ comment: |
2467
+ The left-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2468
+
2469
+ 1...
2470
+ ^
2471
+
2472
+ hello...goodbye
2473
+ ^^^^^
2294
2474
  - name: right
2295
2475
  type: node?
2476
+ comment: |
2477
+ The right-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2478
+
2479
+ ..5
2480
+ ^
2481
+
2482
+ 1...foo
2483
+ ^^^
2484
+ If neither right-hand or left-hand side was included, this will be a MissingNode.
2296
2485
  - name: operator_loc
2297
2486
  type: location
2487
+ comment: |
2488
+ The location of the `..` or `...` operator.
2298
2489
  comment: |
2299
2490
  Represents the use of the `..` or `...` operators.
2300
2491
 
@@ -2338,6 +2529,9 @@ nodes:
2338
2529
  ^^^^^^
2339
2530
  - name: RequiredKeywordParameterNode
2340
2531
  fields:
2532
+ - name: flags
2533
+ type: flags
2534
+ kind: ParameterFlags
2341
2535
  - name: name
2342
2536
  type: constant
2343
2537
  - name: name_loc
@@ -2350,6 +2544,9 @@ nodes:
2350
2544
  end
2351
2545
  - name: RequiredParameterNode
2352
2546
  fields:
2547
+ - name: flags
2548
+ type: flags
2549
+ kind: ParameterFlags
2353
2550
  - name: name
2354
2551
  type: constant
2355
2552
  comment: |
@@ -2397,10 +2594,12 @@ nodes:
2397
2594
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2398
2595
  end
2399
2596
 
2400
- `Foo, *splat, Bar` are in the `exceptions` field.
2401
- `ex` is in the `exception` field.
2597
+ `Foo, *splat, Bar` are in the `exceptions` field. `ex` is in the `exception` field.
2402
2598
  - name: RestParameterNode
2403
2599
  fields:
2600
+ - name: flags
2601
+ type: flags
2602
+ kind: ParameterFlags
2404
2603
  - name: name
2405
2604
  type: constant?
2406
2605
  - name: name_loc
@@ -2511,8 +2710,7 @@ nodes:
2511
2710
  - name: unescaped
2512
2711
  type: string
2513
2712
  comment: |
2514
- Represents a string literal, a string contained within a `%w` list, or
2515
- plain string content within an interpolated string.
2713
+ Represents a string literal, a string contained within a `%w` list, or plain string content within an interpolated string.
2516
2714
 
2517
2715
  "foo"
2518
2716
  ^^^^^