prism 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abad576ba53ce985475eb5d69638557386eef255c8fe625728780ce8ff66844e
4
- data.tar.gz: a3c5e24f5d1ee0fe04d282a3f40d643cd914a518985a9cadebbb53200e4d3003
3
+ metadata.gz: c27362d3d2d174aeaeab0db8eaf69b47d618f4c2948c9c8a55e96cb927c1ddd6
4
+ data.tar.gz: f66f7d1e74c9e35c5ce45e8e34240f90cfc659bc5641048f81f3835ae52fd584
5
5
  SHA512:
6
- metadata.gz: d3255b2de64f3154500885ae2bd091389d6ac87c9b88cb8ff83b7d58026066c4e007cb7c486dcc8e8146132aad63a1c58ddd8ad598441d26bec7ad062409f6a9
7
- data.tar.gz: 3d7563663f013a4dcc633b5e19d0a4605cae18bd0a0f99cc02c142198b25126f915185eef4080625c9a5867093a5bc5717db96ef8a8da6cdc69e849f65fbb7fd
6
+ metadata.gz: dc64bd0ead37af96b5632498babd6860c9f257c98b0f9dc7aae2c78d6a853b9b95ef6a2f625f61ee1348ef41645e5d4c3f256c30357abca33d7d9387b2a76e2e
7
+ data.tar.gz: 34f22069e23dc9adf8c7968e7dcf929b479ef3650c909c4c3ad142e858d89c529bc53b6bd38c40fa7f00340dbafabb86fdf59ab6ba3367b71f64c43201b4e99a
data/CHANGELOG.md CHANGED
@@ -6,6 +6,24 @@ 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.27.0] - 2024-04-23
10
+
11
+ ### Added
12
+
13
+ - Implemented `===` for each of the nodes, which will check if equality but ignore the specific ranges of locations.
14
+
15
+ ### Changed
16
+
17
+ - Fix translation of `ItParametersNode` for parser translation.
18
+ - Fix translation of `dstr` for ruby_parser translation.
19
+ - Do not allow omitted hash values whose keys end with `!` or `?`.
20
+ - Split up `Prism::ParseResult` into `Prism::Result` with subclasses `Prism::ParseResult`, `Prism::LexResult`, `Prism::ParseLexResult`, and `Prism::LexCompat::Result`.
21
+ - Change reflection classes to have only a single `IntegerField` class and rename `DoubleField` to `FloatField`.
22
+ - Fall back to default `AR` and `CC` in `Makefile`.
23
+ - Use GC-able symbols for the syntax tree to avoid adding to the global symbol table.
24
+ - Fix a bug with karatsuba_multiply that would result in a stack overflow.
25
+ - Fix parser translation when looking for tokens with `srange_find`.
26
+
9
27
  ## [0.26.0] - 2024-04-18
10
28
 
11
29
  ### Added
@@ -458,7 +476,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
458
476
 
459
477
  - 🎉 Initial release! 🎉
460
478
 
461
- [unreleased]: https://github.com/ruby/prism/compare/v0.26.0...HEAD
479
+ [unreleased]: https://github.com/ruby/prism/compare/v0.27.0...HEAD
480
+ [0.27.0]: https://github.com/ruby/prism/compare/v0.26.0...v0.27.0
462
481
  [0.26.0]: https://github.com/ruby/prism/compare/v0.25.0...v0.26.0
463
482
  [0.25.0]: https://github.com/ruby/prism/compare/v0.24.0...v0.25.0
464
483
  [0.24.0]: https://github.com/ruby/prism/compare/v0.23.0...v0.24.0
data/Makefile CHANGED
@@ -13,6 +13,7 @@ SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
13
13
  CPPFLAGS := -Iinclude $(CPPFLAGS)
14
14
  CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden $(CFLAGS)
15
15
  CC ?= cc
16
+ AR ?= ar
16
17
  WASI_SDK_PATH := /opt/wasi-sdk
17
18
 
18
19
  MAKEDIRS ?= mkdir -p
@@ -31,11 +32,11 @@ wasm: javascript/src/prism.wasm
31
32
  java-wasm: java-wasm/src/test/resources/prism.wasm
32
33
 
33
34
  build/libprism.$(SOEXT): $(SHARED_OBJECTS)
34
- $(ECHO) "linking $@"
35
+ $(ECHO) "linking $@ with $(CC)"
35
36
  $(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared -o $@ $(SHARED_OBJECTS)
36
37
 
37
38
  build/libprism.a: $(STATIC_OBJECTS)
38
- $(ECHO) "building $@"
39
+ $(ECHO) "building $@ with $(AR)"
39
40
  $(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)
40
41
 
41
42
  javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
data/config.yml CHANGED
@@ -134,6 +134,8 @@ errors:
134
134
  - INVALID_CHARACTER
135
135
  - INVALID_ENCODING_MAGIC_COMMENT
136
136
  - INVALID_FLOAT_EXPONENT
137
+ - INVALID_LOCAL_VARIABLE_READ
138
+ - INVALID_LOCAL_VARIABLE_WRITE
137
139
  - INVALID_MULTIBYTE_CHAR
138
140
  - INVALID_MULTIBYTE_CHARACTER
139
141
  - INVALID_MULTIBYTE_ESCAPE
@@ -206,6 +208,7 @@ errors:
206
208
  - PATTERN_HASH_KEY
207
209
  - PATTERN_HASH_KEY_DUPLICATE
208
210
  - PATTERN_HASH_KEY_LABEL
211
+ - PATTERN_HASH_KEY_LOCALS
209
212
  - PATTERN_IDENT_AFTER_HROCKET
210
213
  - PATTERN_LABEL_AFTER_COMMA
211
214
  - PATTERN_REST
@@ -737,10 +740,25 @@ nodes:
737
740
  fields:
738
741
  - name: new_name
739
742
  type: node
743
+ comment: |
744
+ Represents the new name of the global variable that can be used after aliasing. This can be either a global variable, a back reference, or a numbered reference.
745
+
746
+ alias $foo $bar
747
+ ^^^^
740
748
  - name: old_name
741
749
  type: node
750
+ comment: |
751
+ Represents the old name of the global variable that could be used before aliasing. This can be either a global variable, a back reference, or a numbered reference.
752
+
753
+ alias $foo $bar
754
+ ^^^^
742
755
  - name: keyword_loc
743
756
  type: location
757
+ comment: |
758
+ The location of the `alias` keyword.
759
+
760
+ alias $foo $bar
761
+ ^^^^^
744
762
  comment: |
745
763
  Represents the use of the `alias` keyword to alias a global variable.
746
764
 
@@ -825,10 +843,25 @@ nodes:
825
843
  kind: ArrayNodeFlags
826
844
  - name: elements
827
845
  type: node[]
846
+ comment: Represent the list of zero or more [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression) within the array.
828
847
  - name: opening_loc
829
848
  type: location?
849
+ comment: |
850
+ Represents the optional source location for the opening token.
851
+
852
+ [1,2,3] # "["
853
+ %w[foo bar baz] # "%w["
854
+ %I(apple orange banana) # "%I("
855
+ foo = 1, 2, 3 # nil
830
856
  - name: closing_loc
831
857
  type: location?
858
+ comment: |
859
+ Represents the optional source location for the closing token.
860
+
861
+ [1,2,3] # "]"
862
+ %w[foo bar baz] # "]"
863
+ %I(apple orange banana) # ")"
864
+ foo = 1, 2, 3 # nil
832
865
  comment: |
833
866
  Represents an array literal. This can be a regular array using brackets or a special array using % like %w or %i.
834
867
 
@@ -1047,8 +1080,18 @@ nodes:
1047
1080
  - name: arguments
1048
1081
  type: node?
1049
1082
  kind: ArgumentsNode
1083
+ comment: |
1084
+ The arguments to the break statement, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1085
+
1086
+ break foo
1087
+ ^^^
1050
1088
  - name: keyword_loc
1051
1089
  type: location
1090
+ comment: |
1091
+ The location of the `break` keyword.
1092
+
1093
+ break foo
1094
+ ^^^^^
1052
1095
  comment: |
1053
1096
  Represents the use of the `break` keyword.
1054
1097
 
@@ -1374,8 +1417,7 @@ nodes:
1374
1417
  - name: value
1375
1418
  type: node
1376
1419
  comment: |
1377
- The value to assign to the class variable. Can be any node that
1378
- represents a non-void expression.
1420
+ The value to write to the class variable. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1379
1421
 
1380
1422
  @@foo = :bar
1381
1423
  ^^^^
@@ -1459,13 +1501,44 @@ nodes:
1459
1501
  fields:
1460
1502
  - name: parent
1461
1503
  type: node?
1504
+ comment: |
1505
+ The left-hand node of the path, if present. It can be `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression). It will be `nil` when the constant lookup is at the root of the module tree.
1506
+
1507
+ Foo::Bar
1508
+ ^^^
1509
+
1510
+ self::Test
1511
+ ^^^^
1512
+
1513
+ a.b::C
1514
+ ^^^
1462
1515
  - name: child
1463
1516
  type: node
1464
1517
  kind:
1465
1518
  - ConstantReadNode
1466
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
+ ^
1467
1532
  - name: delimiter_loc
1468
1533
  type: location
1534
+ comment: |
1535
+ The location of the `::` delimiter.
1536
+
1537
+ ::Foo
1538
+ ^^
1539
+
1540
+ One::Two
1541
+ ^^
1469
1542
  comment: |
1470
1543
  Represents accessing a constant through a path of `::` operators.
1471
1544
 
@@ -1522,10 +1595,28 @@ nodes:
1522
1595
  - name: target
1523
1596
  type: node
1524
1597
  kind: ConstantPathNode
1598
+ comment: |
1599
+ A node representing the constant path being written to.
1600
+
1601
+ Foo::Bar = 1
1602
+ ^^^^^^^^
1603
+
1604
+ ::Foo = :abc
1605
+ ^^^^^
1525
1606
  - name: operator_loc
1526
1607
  type: location
1608
+ comment: |
1609
+ The location of the `=` operator.
1610
+
1611
+ ::ABC = 123
1612
+ ^
1527
1613
  - name: value
1528
1614
  type: node
1615
+ comment: |
1616
+ The value to write to the constant path. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1617
+
1618
+ FOO::BAR = :abc
1619
+ ^^^^
1529
1620
  comment: |
1530
1621
  Represents writing to a constant path.
1531
1622
 
@@ -1565,12 +1656,36 @@ nodes:
1565
1656
  fields:
1566
1657
  - name: name
1567
1658
  type: constant
1659
+ comment: |
1660
+ The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
1661
+
1662
+ Foo = :bar # name `:Foo`
1663
+
1664
+ XYZ = 1 # name `:XYZ`
1568
1665
  - name: name_loc
1569
1666
  type: location
1667
+ comment: |
1668
+ The location of the constant name.
1669
+
1670
+ FOO = 1
1671
+ ^^^
1570
1672
  - name: value
1571
1673
  type: node
1674
+ comment: |
1675
+ The value to write to the constant. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1676
+
1677
+ FOO = :bar
1678
+ ^^^^
1679
+
1680
+ MyClass = Class.new
1681
+ ^^^^^^^^^
1572
1682
  - name: operator_loc
1573
1683
  type: location
1684
+ comment: |
1685
+ The location of the `=` operator.
1686
+
1687
+ FOO = :bar
1688
+ ^
1574
1689
  comment: |
1575
1690
  Represents writing to a constant.
1576
1691
 
@@ -1860,12 +1975,36 @@ nodes:
1860
1975
  fields:
1861
1976
  - name: name
1862
1977
  type: constant
1978
+ comment: |
1979
+ 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.
1980
+
1981
+ $foo = :bar # name `:$foo`
1982
+
1983
+ $_Test = 123 # name `:$_Test`
1863
1984
  - name: name_loc
1864
1985
  type: location
1986
+ comment: |
1987
+ The location of the global variable's name.
1988
+
1989
+ $foo = :bar
1990
+ ^^^^
1865
1991
  - name: value
1866
1992
  type: node
1993
+ comment: |
1994
+ The value to write to the global variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
1995
+
1996
+ $foo = :bar
1997
+ ^^^^
1998
+
1999
+ $-xyz = 123
2000
+ ^^^
1867
2001
  - name: operator_loc
1868
2002
  type: location
2003
+ comment: |
2004
+ The location of the `=` operator.
2005
+
2006
+ $foo = :bar
2007
+ ^
1869
2008
  comment: |
1870
2009
  Represents writing to a global variable.
1871
2010
 
@@ -1933,26 +2072,87 @@ nodes:
1933
2072
  fields:
1934
2073
  - name: if_keyword_loc
1935
2074
  type: location?
2075
+ comment: |
2076
+ The location of the `if` keyword if present.
2077
+
2078
+ bar if foo
2079
+ ^^
2080
+
2081
+ The `if_keyword_loc` field will be `nil` when the `IfNode` represents a ternary expression.
1936
2082
  - name: predicate
1937
2083
  type: node
2084
+ comment: |
2085
+ The node for the condition the `IfNode` is testing.
2086
+
2087
+ if foo
2088
+ ^^^
2089
+ bar
2090
+ end
2091
+
2092
+ bar if foo
2093
+ ^^^
2094
+
2095
+ foo ? bar : baz
2096
+ ^^^
1938
2097
  - name: then_keyword_loc
1939
2098
  type: location?
2099
+ comment: |
2100
+ The location of the `then` keyword (if present) or the `?` in a ternary expression, `nil` otherwise.
2101
+
2102
+ if foo then bar end
2103
+ ^^^^
2104
+
2105
+ a ? b : c
2106
+ ^
1940
2107
  - name: statements
1941
2108
  type: node?
1942
2109
  kind: StatementsNode
2110
+ comment: |
2111
+ Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be `nil` when no body is provided.
2112
+
2113
+ if foo
2114
+ bar
2115
+ ^^^
2116
+ baz
2117
+ ^^^
2118
+ end
1943
2119
  - name: consequent
1944
2120
  type: node?
2121
+ comment: |
2122
+ Represents an `ElseNode` or an `IfNode` when there is an `else` or an `elsif` in the `if` statement.
2123
+
2124
+ if foo
2125
+ bar
2126
+ elsif baz
2127
+ ^^^^^^^^^
2128
+ qux
2129
+ ^^^
2130
+ end
2131
+ ^^^
2132
+
2133
+ if foo then bar else baz end
2134
+ ^^^^^^^^^^^^
1945
2135
  - name: end_keyword_loc
1946
2136
  type: location?
2137
+ comment: |
2138
+ The location of the `end` keyword if present, `nil` otherwise.
2139
+
2140
+ if foo
2141
+ bar
2142
+ end
2143
+ ^^^
1947
2144
  newline: predicate
1948
2145
  comment: |
1949
- Represents the use of the `if` keyword, either in the block form or the modifier form.
2146
+ Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
1950
2147
 
1951
2148
  bar if foo
1952
2149
  ^^^^^^^^^^
1953
2150
 
1954
2151
  if foo then bar end
1955
2152
  ^^^^^^^^^^^^^^^^^^^
2153
+
2154
+ foo ? bar : baz
2155
+ ^^^^^^^^^^^^^^^
1956
2156
  - name: ImaginaryNode
1957
2157
  fields:
1958
2158
  - name: numeric
@@ -2215,8 +2415,7 @@ nodes:
2215
2415
  - name: value
2216
2416
  type: node
2217
2417
  comment: |
2218
- The value to assign to the instance variable. Can be any node that
2219
- represents a non-void expression.
2418
+ The value to write to the instance variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2220
2419
 
2221
2420
  @foo = :bar
2222
2421
  ^^^^
@@ -2507,14 +2706,50 @@ nodes:
2507
2706
  fields:
2508
2707
  - name: name
2509
2708
  type: constant
2709
+ comment: |
2710
+ The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
2711
+
2712
+ foo = :bar # name `:foo`
2713
+
2714
+ abc = 123 # name `:abc`
2510
2715
  - name: depth
2511
2716
  type: uint32
2717
+ comment: |
2718
+ The number of semantic scopes we have to traverse to find the declaration of this variable.
2719
+
2720
+ foo = 1 # depth 0
2721
+
2722
+ tap { foo = 1 } # depth 1
2723
+
2724
+ 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).
2512
2725
  - name: name_loc
2513
2726
  type: location
2727
+ comment: |
2728
+ The location of the variable name.
2729
+
2730
+ foo = :bar
2731
+ ^^^
2514
2732
  - name: value
2515
2733
  type: node
2734
+ comment: |
2735
+ The value to write to the local variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2736
+
2737
+ foo = :bar
2738
+ ^^^^
2739
+
2740
+ abc = 1234
2741
+ ^^^^
2742
+
2743
+ Note that since the name of a local variable is known before the value is parsed, it is valid for a local variable to appear within the value of its own write.
2744
+
2745
+ foo = foo
2516
2746
  - name: operator_loc
2517
2747
  type: location
2748
+ comment: |
2749
+ The location of the `=` operator.
2750
+
2751
+ x = :y
2752
+ ^
2518
2753
  comment: |
2519
2754
  Represents writing to a local variable.
2520
2755
 
@@ -3166,6 +3401,7 @@ nodes:
3166
3401
  kind: StringFlags
3167
3402
  - name: filepath
3168
3403
  type: string
3404
+ comment: Represents the file path being parsed. This corresponds directly to the `filepath` option given to the various `Prism::parse*` APIs.
3169
3405
  comment: |
3170
3406
  Represents the use of the `__FILE__` keyword.
3171
3407
 
@@ -3287,18 +3523,55 @@ nodes:
3287
3523
  fields:
3288
3524
  - name: keyword_loc
3289
3525
  type: location
3526
+ comment: |
3527
+ The location of the `unless` keyword.
3528
+
3529
+ unless cond then bar end
3530
+ ^^^^^^
3531
+
3532
+ bar unless cond
3533
+ ^^^^^^
3290
3534
  - name: predicate
3291
3535
  type: node
3536
+ comment: |
3537
+ The condition to be evaluated for the unless expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
3538
+
3539
+ unless cond then bar end
3540
+ ^^^^
3541
+
3542
+ bar unless cond
3543
+ ^^^^
3292
3544
  - name: then_keyword_loc
3293
3545
  type: location?
3546
+ comment:
3547
+ The location of the `then` keyword, if present.
3548
+
3549
+ unless cond then bar end
3550
+ ^^^^
3294
3551
  - name: statements
3295
3552
  type: node?
3296
3553
  kind: StatementsNode
3554
+ comment: |
3555
+ The body of statements that will executed if the unless condition is
3556
+ falsey. Will be `nil` if no body is provided.
3557
+
3558
+ unless cond then bar end
3559
+ ^^^
3297
3560
  - name: consequent
3298
3561
  type: node?
3299
3562
  kind: ElseNode
3563
+ comment: |
3564
+ The else clause of the unless expression, if present.
3565
+
3566
+ unless cond then bar else baz end
3567
+ ^^^^^^^^
3300
3568
  - name: end_keyword_loc
3301
3569
  type: location?
3570
+ comment: |
3571
+ The location of the `end` keyword, if present.
3572
+
3573
+ unless cond then bar end
3574
+ ^^^
3302
3575
  newline: predicate
3303
3576
  comment: |
3304
3577
  Represents the use of the `unless` keyword, either in the block form or the modifier form.